Reputation: 1300
I am currently internationalizing a rails app and have all my translations in config/locales/. I have my general environment config settings in config/application.yml, like API keys. I dont know where to put the locale specific config settings though? Like default locations and such?
Could I have a config file with different sections nested for each language and then only load the one relevant to my current locale?
something like
###/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
and then something like
#config/environment.rb or somewhere else?
APP_CONFIG = YAML.load_file("#{RAILS_ROOT}/config/config.yml")['mylocale']
How can I get the "mylocale"?
I appreciate any hints and best practice advice!
Upvotes: 2
Views: 792
Reputation: 1286
I would put these in separate files in another directory and add the directory to the i18n load path.
e.g.
config/localized_config/pt
config:
default_location:
location: Lisbon
...
Then you can do I18n.t('config.default_location.location')
and it should grab the right translation based on the current locale.
How to add to the i18n loadpath is covered here:
http://guides.rubyonrails.org/i18n.html#configure-the-i18n-module
This way you can re-use the built in functionality without having to put sensitive or non relevant translations in the main translation files.
Upvotes: 1