2

我目前正在国际化Rails应用程序,并在config/locales /中拥有我所有的翻译。 我有我的一般环境配置设置config/application.yml,就像API键。我不知道在哪里放置特定于语言环境的配置设置?像默认位置等?rails i18n locale特定的配置设置?

我可以为每种语言嵌套不同部分的配置文件,然后只加载与当前语言环境相关的配置文件?

###/config/config.yml  

de: 
    DEFAULT_LOCATION: 
    location: Berlin 
    country: Germany 
    country_code: de 
    HOST: http://www.germanwebsite.de 
pt: 
    DEFAULT_LOCATION: 
    location: Lisbon 
    country: Portgual 
    country_code: pt 
    HOST: http://www.portuguesewebsite.pt 

,然后像

#config/environment.rb or somewhere else? 
APP_CONFIG = YAML.load_file("#{RAILS_ROOT}/config/config.yml")['mylocale'] 

我怎样才能获得 “mylocale”?

我明白任何提示和最佳实践的建议!

回答

1

我把这些单独的文件在另一个目录和目录添加到国际化的负载路径。

例如

配置/ localized_config/PT

config: 
    default_location: 
    location: Lisbon 
    ... 

然后,你可以做I18n.t('config.default_location.location'),它应该抓住基于当前语言环境的正确翻译。

如何加入到国际化loadpath在这里介绍:

http://guides.rubyonrails.org/i18n.html#configure-the-i18n-module

这样你就可以重新使用内置的功能,而不必把敏感或不相关的翻译在主翻译文件。