mobility icon indicating copy to clipboard operation
mobility copied to clipboard

Not compatible with FastGettext - request for string available locale support

Open kalsan opened this issue 2 years ago • 2 comments

Having the following FastGettext initializer:

# config/initializers/fast_gettext.rb

FastGettext.default_available_locales = %w[de en] # or %i for that matter
FastGettext.default_text_domain = 'app'

and the following Mobility initializer:

# config/initializers/mobility.rb

Mobility.configure do
  plugins do
    backend :column
    active_record
    reader
    writer
    backend_reader
    query
    cache
    presence
    locale_accessors # This line creates the problem

I'm getting the error :de is not a valid locale. I18n.available_locales returns: ["de", "en"]

Appearently, FastGettext sets the array to strings, whereas Mobility is looking for symbols.

Changing the FastGettext initializer to the following is a workaround:

# config/initializers/fast_gettext.rb

FastGettext.default_available_locales = %w[de en] 
FastGettext.default_text_domain = 'app'
I18n.available_locales = %i[de en] # This line is needed

Note that changing FastGettext.default_available_locales to an array of symbols does not help.

Since Mobility is the first Gem that appears to have trouble with the locales being stored as Strings, I would like to propose, if adequate, to add String locales support to Mobility. Ideally, the gem would support both symbol and string keys for I18n.available_locales.

Best, Kalsan

kalsan avatar Feb 22 '23 10:02 kalsan

I would like to propose, if adequate, to add String locales support to Mobility. Ideally, the gem would support both symbol and string keys for I18n.available_locales.

That sounds reasonable, could you make a PR to do that?

shioyama avatar Mar 26 '23 07:03 shioyama

@shioyama I added a pull request including tests. You might wanna review the PR manually anyways.

kalsan avatar Apr 06 '23 09:04 kalsan