作者热门文章
- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
我正在 OS X 10.13.4 上使用 Rails 3.2.22.4、Ruby 2.2.7 开发一个应用程序。有多个翻译文件,例如。 en.yml, sq.yml 基于国家。从下面的 rubymine 执行命令时,加载网页时出现错误。
rake --trace i18n:js:export
i18n (0.9.5)
。如果尝试加载页面,浏览器会显示错误:
can not load translations from /Users/biju/projecty/config/locales/en.yml:
#<Psych::SyntaxError: (/Users/biju/projecty/config/locales/en.yml): found unknown escape character while parsing a quoted scalar at line 26 column 27>
尝试执行 rake 任务时出现错误堆栈
2018-07-18 16:40:51 +0530 Projecty::Application.initialize! took 1.733 sec
---------------------------------------------------------------------------------------------------------------
** Execute i18n:js:export
rake aborted!
I18n::InvalidLocaleData: can not load translations from /Users/biju/projecty/config/locales/en.yml: #<Psych::SyntaxError: (/Users/biju/projecty/config/locales/en.yml): found unknown escape character while parsing a quoted scalar at line 26 column 27>
/Users/biju/.rvm/gems/ruby-2.2.7@yb/gems/i18n-0.9.5/lib/i18n/backend/base.rb:232:in `rescue in load_yml'
/Users/biju/.rvm/gems/ruby-2.2.7@yb/gems/i18n-0.9.5/lib/i18n/backend/base.rb:229:in `load_yml'
/Users/biju/.rvm/gems/ruby-2.2.7@yb/gems/i18n-0.9.5/lib/i18n/backend/base.rb:213:in `load_file'
/Users/biju/.rvm/gems/ruby-2.2.7@yb/gems/i18n-0.9.5/lib/i18n/backend/base.rb:15:in `block in load_translations'
/Users/biju/.rvm/gems/ruby-2.2.7@yb/gems/i18n-0.9.5/lib/i18n/backend/base.rb:15:in `each'
/Users/biju/.rvm/gems/ruby-2.2.7@yb/gems/i18n-0.9.5/lib/i18n/backend/base.rb:15:in `load_translations'
/Users/biju/.rvm/gems/ruby-2.2.7@yb/gems/i18n-0.9.5/lib/i18n/backend/simple.rb:63:in `init_translations'
/Users/biju/.rvm/gems/ruby-2.2.7@yb/gems/i18n-js-3.0.5/lib/i18n/js.rb:164:in `block in translations'
/Users/biju/.rvm/gems/ruby-2.2.7@yb/gems/i18n-js-3.0.5/lib/i18n/js.rb:163:in `instance_eval'
/Users/biju/.rvm/gems/ruby-2.2.7@yb/gems/i18n-js-3.0.5/lib/i18n/js.rb:163:in `translations'
/Users/biju/.rvm/gems/ruby-2.2.7@yb/gems/i18n-js-3.0.5/lib/i18n/js.rb:121:in `block in scoped_translations'
/Users/biju/.rvm/gems/ruby-2.2.7@yb/gems/i18n-js-3.0.5/lib/i18n/js.rb:120:in `each'
/Users/biju/.rvm/gems/ruby-2.2.7@yb/gems/i18n-js-3.0.5/lib/i18n/js.rb:120:in `scoped_translations'
/Users/biju/.rvm/gems/ruby-2.2.7@yb/gems/i18n-js-3.0.5/lib/i18n/js.rb:43:in `segment_for_scope'
/Users/biju/.rvm/gems/ruby-2.2.7@yb/gems/i18n-js-3.0.5/lib/i18n/js.rb:54:in `block in configured_segments'
/Users/biju/.rvm/gems/ruby-2.2.7@yb/gems/i18n-js-3.0.5/lib/i18n/js.rb:48:in `each'
/Users/biju/.rvm/gems/ruby-2.2.7@yb/gems/i18n-js-3.0.5/lib/i18n/js.rb:48:in `inject'
/Users/biju/.rvm/gems/ruby-2.2.7@yb/gems/i18n-js-3.0.5/lib/i18n/js.rb:48:in `configured_segments'
/Users/biju/.rvm/gems/ruby-2.2.7@yb/gems/i18n-js-3.0.5/lib/i18n/js.rb:93:in `translation_segments'
/Users/biju/.rvm/gems/ruby-2.2.7@yb/gems/i18n-js-3.0.5/lib/i18n/js.rb:36:in `export'
/Users/biju/.rvm/gems/ruby-2.2.7@yb/gems/i18n-js-3.0.5/lib/tasks/export.rake:5:in `block (3 levels) in <top (required)>'
/Users/biju/.rvm/gems/ruby-2.2.7@yb/gems/rake-10.5.0/lib/rake/task.rb:240:in `call'
/Users/biju/.rvm/gems/ruby-2.2.7@yb/gems/rake-10.5.0/lib/rake/task.rb:240:in `block in execute'
/Users/biju/.rvm/gems/ruby-2.2.7@yb/gems/rake-10.5.0/lib/rake/task.rb:235:in `each'
/Users/biju/.rvm/gems/ruby-2.2.7@yb/gems/rake-10.5.0/lib/rake/task.rb:235:in `execute'
/Users/biju/.rvm/gems/ruby-2.2.7@yb/gems/rake-10.5.0/lib/rake/task.rb:179:in `block in invoke_with_call_chain'
/Users/biju/.rvm/rubies/ruby-2.2.7/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
/Users/biju/.rvm/gems/ruby-2.2.7@yb/gems/rake-10.5.0/lib/rake/task.rb:172:in `invoke_with_call_chain'
/Users/biju/.rvm/gems/ruby-2.2.7@yb/gems/rake-10.5.0/lib/rake/task.rb:165:in `invoke'
/Users/biju/.rvm/gems/ruby-2.2.7@yb/gems/rake-10.5.0/lib/rake/application.rb:150:in `invoke_task'
/Users/biju/.rvm/gems/ruby-2.2.7@yb/gems/rake-10.5.0/lib/rake/application.rb:106:in `block (2 levels) in top_level'
/Users/biju/.rvm/gems/ruby-2.2.7@yb/gems/rake-10.5.0/lib/rake/application.rb:106:in `each'
/Users/biju/.rvm/gems/ruby-2.2.7@yb/gems/rake-10.5.0/lib/rake/application.rb:106:in `block in top_level'
/Users/biju/.rvm/gems/ruby-2.2.7@yb/gems/rake-10.5.0/lib/rake/application.rb:115:in `run_with_threads'
/Users/biju/.rvm/gems/ruby-2.2.7@yb/gems/rake-10.5.0/lib/rake/application.rb:100:in `top_level'
/Users/biju/.rvm/gems/ruby-2.2.7@yb/gems/rake-10.5.0/lib/rake/application.rb:78:in `block in run'
/Users/biju/.rvm/gems/ruby-2.2.7@yb/gems/rake-10.5.0/lib/rake/application.rb:176:in `standard_exception_handling'
/Users/biju/.rvm/gems/ruby-2.2.7@yb/gems/rake-10.5.0/lib/rake/application.rb:75:in `run'
/Users/biju/.rvm/gems/ruby-2.2.7@yb/gems/rake-10.5.0/bin/rake:33:in `<top (required)>'
/Users/biju/.rvm/gems/ruby-2.2.7@yb/bin/rake:23:in `load'
/Users/biju/.rvm/gems/ruby-2.2.7@yb/bin/rake:23:in `<top (required)>'
-e:1:in `load'
-e:1:in `<main>'
来自 .yml 文件的片段,第 26 行给出错误。
en:
formtastic:
labels:
event_filter:
source_server: "Server:"
source_source: "Sevent_filter:"
source_server: "Server:"
source_source: "Source:"
serverOption: "Server:"
Category: "Category:"
EventID: "Event ID:"
Type: "Type:"
TEA: "Target E-mail Address:"
All: "All"
ShWare: "ShWare:"
Services: "Services:"
Other: "Other"
Any: "Any"
Error: "Error"
Warning: "Warning"
Information: "Information"
None: ""
can_not_be_blank: "can't be blank or click on \'Any\'"
list:
buttons:
previous: "Previous"
next: "Next"
编辑在 Rails 控制台中重建错误:
trans2 = YAML.load(File.read("#{D2_DIR}/config/locales/en.yml")).with_indifferent_access
Psych::SyntaxError: (<unknown>): found unknown escape character while parsing a quoted scalar at line 26 column 27
from /Users/biju/.rvm/rubies/ruby-2.2.7/lib/ruby/2.2.0/psych.rb:370:in `parse'
from /Users/biju/.rvm/rubies/ruby-2.2.7/lib/ruby/2.2.0/psych.rb:370:in `parse_stream'
from /Users/biju/.rvm/rubies/ruby-2.2.7/lib/ruby/2.2.0/psych.rb:318:in `parse'
from /Users/biju/.rvm/rubies/ruby-2.2.7/lib/ruby/2.2.0/psych.rb:245:in `load'
from (irb):18
from /Users/biju/.rvm/gems/ruby-2.2.7@yb/gems/railties-3.2.22.4/lib/rails/commands/console.rb:47:in `start'
from /Users/biju/.rvm/gems/ruby-2.2.7@yb/gems/railties-3.2.22.4/lib/rails/commands/console.rb:8:in `start'
from /Users/biju/.rvm/gems/ruby-2.2.7@yb/gems/railties-3.2.22.4/lib/rails/commands.rb:41:in `<top (required)>'
from /Users/biju/projecty/script/rails:11:in `require'
from /Users/biju/projecty/script/rails:11:in `<top (required)>'
from -e:1:in `load'
from -e:1:in `<main>'
经过足够的搜索后我无法获得指针,但不确定可能是 gem 问题。任何帮助表示赞赏。
最佳答案
这是一个特定于操作系统的问题,与 YAML 库相关。 .yml 文件的解析在 can_not_be_blank: "can't be blank or click on\'Any\'" 处中断。以下错误仅在 OS X 的多个版本的 OS X 测试中出现。
require 'yaml
2.4.1 :002 > trans1 = YAML.load(File.read("/Users/app.yml"))
Psych::SyntaxError: (<unknown>): found unknown escape character while parsing a quoted scalar at line 23 column 27
from /Users/biju/.rvm/rubies/ruby-2.4.1/lib/ruby/2.4.0/psych.rb:377:in `parse'
from /Users/biju/.rvm/rubies/ruby-2.4.1/lib/ruby/2.4.0/psych.rb:377:in `parse_stream'
from /Users/biju/.rvm/rubies/ruby-2.4.1/lib/ruby/2.4.0/psych.rb:325:in `parse'
from /Users/biju/.rvm/rubies/ruby-2.4.1/lib/ruby/2.4.0/psych.rb:252:in `load'
from (irb):2
from /Users/biju/.rvm/rubies/ruby-2.4.1/bin/irb:11:in `<main>'
2.4.1 :003 >
相同的代码适用于 Windows irb。但是在 OSX 中,将 \'Any\' 更改为 'Any' 有助于执行操作。除了库安装在 unix vs windows 中之外,不确定可能是什么原因。
关于ruby - I18n::InvalidLocaleData:I18n gem 在 js 导出中有问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51400887/
我是一名优秀的程序员,十分优秀!