Rails 4 多域应用程序,为每个域 i18n 语言环境设置了语言环境 [英] Rails 4 multidomain application with locale set for each domain i18n locale

查看:40
本文介绍了Rails 4 多域应用程序,为每个域 i18n 语言环境设置了语言环境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Rails 4 多域应用程序中,我需要为每个域(总共 3 个域)设置 4 种语言的区域设置文件.

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

这在 Rails 4 中可行吗?如果是这样,进行此设置的最佳方法是什么?

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

推荐答案

config/application 中,您将拥有:

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.

这篇关于Rails 4 多域应用程序,为每个域 i18n 语言环境设置了语言环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆