How do I set the default locale in rails application.rb so I don't have to add unit every time I call the following?
如何在rails应用程序中设置缺省语言环境。所以我不需要每次调用下面的时候都添加单元?
number_to_currency(@course.price, unit: "£")
Rails guides says my locale is :en-GB
for the UK, but the following obviously creates an error in application.rb
Rails指南说我的语言环境是:en-GB表示英国,但是下面的代码显然会在application.rb中产生错误
config.i18n.default_locale = :en-GB
3 个解决方案
#1
23
The rails-i18n
gem contains a lot of locale configurations for Rails and en-GB is one of them. en-GB isn't included in Rails itself.
Rails -i18n gem包含许多Rails的本地化配置,en-GB就是其中之一。en-GB并不包括在Rails中。
- Add the
rails-i18n
gem - 添加rails-i18n宝石
- Add
config.i18n.default_locale = :'en-GB'
toapplication.rb
- 将config.i18n.default_locale =:'en-GB'添加到application.rb
#2
4
Try this:
试试这个:
config.i18n.default_locale = :'en-GB'
#3
-1
You need to install the rails-i18n gem first ( https://github.com/svenfuchs/rails-i18n ) or create 'config/locales/en-GB.yml' file with 'en-GB.number.currency.format.unit: £' entry
您需要先安装rails-i18n gem (https://github.com/svenfuchs/rails-i18n)或创建“配置/本地环境/en-GB”。yml‘文件’en-GB.number.currency.format。单位:£条目
#1
23
The rails-i18n
gem contains a lot of locale configurations for Rails and en-GB is one of them. en-GB isn't included in Rails itself.
Rails -i18n gem包含许多Rails的本地化配置,en-GB就是其中之一。en-GB并不包括在Rails中。
- Add the
rails-i18n
gem - 添加rails-i18n宝石
- Add
config.i18n.default_locale = :'en-GB'
toapplication.rb
- 将config.i18n.default_locale =:'en-GB'添加到application.rb
#2
4
Try this:
试试这个:
config.i18n.default_locale = :'en-GB'
#3
-1
You need to install the rails-i18n gem first ( https://github.com/svenfuchs/rails-i18n ) or create 'config/locales/en-GB.yml' file with 'en-GB.number.currency.format.unit: £' entry
您需要先安装rails-i18n gem (https://github.com/svenfuchs/rails-i18n)或创建“配置/本地环境/en-GB”。yml‘文件’en-GB.number.currency.format。单位:£条目