i18n-tasks无法路由密钥

时间:2015-11-26 11:55:04

标签: ruby-on-rails ruby rubygems rails-i18n i18n-tasks

我的i18n-tasks配置文件:

data:
  read:
    # Default:
     - config/locales/%{locale}.yml
    # More files:
     - config/locales/**/*.%{locale}.yml
     - config/locales/views/*.{locale}.yml
     - config/locales/models/*.{locale}.yml
     - config/locales/helpers/*.{locale}.yml

  # Locale files to write new keys to, based on a list of key pattern => file rules. Matched from top to bottom:
  # `i18n-tasks normalize -p` will force move the keys according to these rules
  write:
      # write models.* and views.* keys to the respective files,
      - ['{models,views,helpers}.*', 'config/locales/\1.%{locale}.yml']

当我在控制台中输入i18n-tasks add-missing时,我遇到错误: i18n-tasks: Cannot route key objects.no_objects_yet Routes are [["{models,views,helpers}.*", "config/locales/\\1.%{locale}.yml"]] 我应该编辑什么来添加缺失的参数?我希望每个添加缺失的翻译到views / {viewname} /en.yml

1 个答案:

答案 0 :(得分:0)

库存机制将未知的密钥名称路由到文件路径。由于objects.no_objects_yet与任何模式({models,views,helpers}.*)都不匹配,因此无法对其进行路由。您可以编写自定义路由器来解决该问题(implementationdocumentation)。

但请注意,许多视图可能会共享密钥。当密钥严格特定于给定视图时,您可以改为使用视图名称命名密钥,例如:

<%= 'my_view.title' %>

然后,有以下路线:

- ['{:}.*', 'config/locales/\1.%{locale}.yml']

这将根据每个密钥的第一部分路由未知密钥,例如上面的密钥将路由到config/locales/my_view.en.yml