【问题标题】:Rails I18n errors parsing simple YAML fileRails I18n 解析简单 YAML 文件时出错
【发布时间】:2013-08-18 06:41:09
【问题描述】:

我刚开始使用 Rails I18n a 完成非常基本的任务,但收到一条令人困惑的错误消息:

can not load translations from c:/Sites/usrochr/config/locales/en.yml: #<Psych::SyntaxError: (c:/Sites/usrochr/config/locales/en.yml): couldn't parse YAML at line 5 column 2>

我的 YAML 文件是 [非常基本的] config/locales/en.yml [我没有看到语法错误]:

en:
  users:
    title: "this is english"

在views/users/index.html.erb文件中调用它的代码也很简单:

    <hr><%= t "users.title" %><hr>

仅供参考-我正在运行 ruby​​ 1.9.3 和 rails 3.2.7。不知道我在哪里误入歧途.....

【问题讨论】:

  • 您确定 en.yml 中没有标签吗?
  • 错误信息表明错误出现在第5行。文件中除了显示的三行之外还有其他内容吗?
  • 感谢 BroiSatse!!!!- 删除 .yml 中的标签成功了- 谢谢!!!
  • @BroiSatse 您应该将此作为答案发布,以便 OP 将其标记为已接受。

标签: ruby-on-rails ruby internationalization yaml


【解决方案1】:

我将其作为评论说,但将重新发布,以便问题可能被标记为已解决:

YAML 使用空格进行解析,因此其中不应该有标签(AFAIK 它也应该只适用于标签 - 但不能混合)

【讨论】:

  • 我通过在 Sublime Text 编辑器中选择文本发现了我的 yml 文件中的不一致,它显示 .... 或 ..-- 何时混合。
猜你喜欢
  • 2011-08-28
  • 1970-01-01
  • 1970-01-01
  • 2012-07-29
  • 1970-01-01
  • 2018-10-13
  • 2011-06-26
  • 2019-01-23
相关资源
最近更新 更多