Rails 语言环境文件无法加载

4e4*_*c52 4 yaml locale ruby-on-rails

我正在用英语和法语翻译我的网站。我的 config/locales 目录中有很多语言环境文件,它们被组织到子文件夹中。

我的所有文件都正确加载,除了一个,我只是不知道为什么。

这是我的文件的内容:

fr:
  categories:
    index:
      page_title: "Toutes les catégories"
      page_description: "Liste de toutes les catégories de tutoriels."
Run Code Online (Sandbox Code Playgroud)

在我的类别控制器的索引视图中,我有以下调用:

%h1= t('.page_title')
Run Code Online (Sandbox Code Playgroud)

我不断得到

翻译缺失:fr.categories.index.page_title

你对这个问题有什么提示吗?


好的,终于找到问题了。

我在另一个文件中有以下内容:

fr:
  categories: "Catégories"
Run Code Online (Sandbox Code Playgroud)

此密钥与我的另一个文件中的密钥冲突,这就是找不到子密钥的原因。

Sam*_*dad 5

如果有人试图加载locale子文件夹中的所有文件,您只需将以下行添加到application.rb

config.i18n.load_path += Dir[Rails.root.join('config', 'locales', '**/*.{rb,yml}').to_s]
Run Code Online (Sandbox Code Playgroud)

在 Rails 上对我来说效果很好5.0.2