Ruby on rails Rails 6国际化-发生了什么变化?

Ruby on rails Rails 6国际化-发生了什么变化?,ruby-on-rails,rails-i18n,ruby-on-rails-6,Ruby On Rails,Rails I18n,Ruby On Rails 6,我开始了一个全新的Rails 6项目,一直在想为什么刚刚成功的应用程序不是我启动的第一个应用程序,失败了。。。 因此,我创建了一个虚拟的simply rails应用程序,没有额外的gem和homeindex页面: 和1个制表符缩进。 导航到localhost:3000/home/index时,我遇到了一个奇怪的错误: /Users/serguei/.rvm/gems/ruby-2.7.0/gems/i18n-1.8.2/lib/i18n.rb:195: warning: The called m

我开始了一个全新的Rails 6项目,一直在想为什么刚刚成功的应用程序不是我启动的第一个应用程序,失败了。。。 因此,我创建了一个虚拟的simply rails应用程序,没有额外的gem和homeindex页面:

和1个制表符缩进。 导航到localhost:3000/home/index时,我遇到了一个奇怪的错误:

/Users/serguei/.rvm/gems/ruby-2.7.0/gems/i18n-1.8.2/lib/i18n.rb:195: warning: The called method `translate' is defined here
  Rendered home/index.html.erb within layouts/application (Duration: 6.2ms | Allocations: 3150)
Completed 500 Internal Server Error in 16ms (ActiveRecord: 0.0ms | Allocations: 5045)



ActionView::Template::Error (can not load translations from /Users/serguei/projects/rails/draft-app/config/locales/en.yml: #<Psych::SyntaxError: (<unknown>): did not find expected key while parsing a block mapping at line 2 column 3>):
    1: <h1>Home#index</h1>
    2: <p>
    3:  <%= t('hello.world') %>
    4: </p>

app/views/home/index.html.erb:3
并从en.yml文件中删除最后一行:

它起作用了。 为什么会这样?自从Rails 5出现以来,发生了什么变化?我们不能在区域设置文件中再使用嵌套翻译吗?没有什么特别的。还是我遗漏了什么

将gem添加到gem文件并不能解决问题

Rails版本:6.0.2.1 Ruby版本:Ruby 2.7.0P02019-12-25修订版647ee6f091[x86_64-darwin19]
如果要嵌套它,则不能将字符串值指定给父级,请改为这样做

en:
  hello:
    world: "Hello World!"
然后,在雇员再培训局,这将起作用

<%= t('hello.world') %>

试试看。

如果要嵌套它,则不能将字符串值分配给父级,请改为这样做

en:
  hello:
    world: "Hello World!"
然后,在雇员再培训局,这将起作用

<%= t('hello.world') %>

试试看。

嵌套翻译应该可以。请检查en.yml中的引号,有时它会被复制粘贴上不正确的符号替换。我检查了它,根本没有复制/粘贴,而且一切似乎都是正确的,您可以检查我创建的。我还更改为在模板中使用双引号:``,但没有成功:。是否尝试重新启动服务器?我总是在出现如此奇怪的错误时运行spring stop&&rails,直到重新启动后仍然如此。嵌套转换应该可以工作。请检查en.yml中的引号,有时它会被复制粘贴上不正确的符号替换。我检查了它,根本没有复制/粘贴,而且一切似乎都是正确的,您可以检查我创建的。我还更改为在模板中使用双引号:``,但没有成功:。是否尝试重新启动服务器?我总是在出现如此奇怪的错误时运行spring stop&&rails,直到重新启动后仍然如此。我的错,就是这样!非常感谢。不知道我到底为什么留下这个值:。我的错,就是这样!非常感谢。不知道我到底为什么留下这个值:。
en:
  hello:
    world: "Hello World!"
<%= t('hello.world') %>