Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 4 multidomain application with locale set for each domain i18n locale

In a Rails 4 multidomain app, I would need a set of locale files for 4 languages for each domain (3 domains total).

Some of the translations overlap between the domains but some of them are very specific, so I am thinking about a structure that would go somewhat like this:

config/locales/en.yml ..fr.yml ..de.yml ..it.yml  #is picked up by all domains
config/locales/domain1/en.yml ..fr.yml ..de.yml ..it.yml  #is picked up by domain 1
config/locales/domain2/en.yml ..fr.yml ..de.yml ..it.yml  #is picked up by domain 2
config/locales/domain3/en.yml ..fr.yml ..de.yml ..it.yml  #is picked up by domain 3

Is this possible in Rails 4? And if so what would be the best way to go about this setup?

like image 668
mahatmanich Avatar asked Nov 02 '22 01:11

mahatmanich


1 Answers

in config/application you would have:

some_domain = Rails.root.basename.to_s # this will give us "myapp.com" if the app is in "/var/www/myapp.com"
config.i18n.load_path += Dir[Rails.root.join('config', 'locales', some_domain, '*.{rb,yml}').to_s]

this will load only the required files and should overwrite any duplicate keys with the later data, but i haven't tested that bit.

like image 86
TomDunning Avatar answered Nov 08 '22 04:11

TomDunning