Dan Sharp
Dan Sharp

Reputation: 1279

How to add available locales to i18n for a Ruby only project?

I'm working on a Ruby only project (not Ruby on Rails) that uses Mongoid for persistence. Mongoid supports language translations using I18n via localized fields: http://mongoid.org/en/mongoid/docs/documents.html#localized_fields

However, I can't figure out how to add additional locales as a configuration option. I18n.available_locales reports only :en

All the searching I've done shows how to configure and use I18n within the context of Rails. Can anyone help me with how to configure I18n and add additional locales so that I can set localized field values for the Mongoid documents.

Thanks!

Upvotes: 16

Views: 9999

Answers (2)

User128848244
User128848244

Reputation: 3470

Also if you want to list that includes symbolized and string versions which can be handy if you have to check both types.

> I18n.config.available_locales_set
=> [
    [ 0] "en",
    [ 1] :en,
    [ 2] "en-GB",
    ...

Upvotes: 1

Dan Sharp
Dan Sharp

Reputation: 1279

Wow.

I don't know how I overlooked it, but it was simpler than I thought:

I18n.available_locales = [:fr, :de, :es, :en]

I can drop that in an initializer and be good to go.

Upvotes: 23

Related Questions