Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recent I18n fallback fix causes failure to load translations hash in Rails #238

Closed
johnnyshields opened this issue Jan 6, 2014 · 12 comments · Fixed by #260
Closed

Recent I18n fallback fix causes failure to load translations hash in Rails #238

johnnyshields opened this issue Jan 6, 2014 · 12 comments · Fixed by #260

Comments

@johnnyshields
Copy link

For some reason (still investigating) this commit: 12aa0f0 causes my app to fail to load the translations hash in my Rails app, and I get missing translation errors.

The load failure occurs irrespective whether config.i18n.enforce_available_locales is true or false.

Rolling back to the immediate previous commit resolves the issue.

Still investigating root cause, may be a toxic interaction with another gem.

johnnyshields referenced this issue Jan 6, 2014
Fallbacks should check whether each fallback
location being tried was set by
store_translations before deferring to
I18n.translate. Otherwise a I18n::InvalidLocale
may be raised when enforce_available_locales is
set.
@johnnyshields
Copy link
Author

I found that adding the following to Backend::Fallbacks::#translate method solves the issue:

init_translations unless initialized?

Some basic debugging indicates that I18n#reload! is called by the ActiveSupport i18n_railtie, and using fallbacks there is nowhere that I18n.init_translations is called.

Here is the code I'm using to initialize I18n in my Rails config for reference. Am using simple (YAML-based) store:

    config.i18n.default_locale = :ja
    config.i18n.available_locales = [:en, :ja, :'zh-CN']
    config.i18n.enforce_available_locales = true
    require 'i18n/backend/fallbacks'
    I18n::Backend::Simple.send(:include, I18n::Backend::Fallbacks)
    I18n.fallbacks[:en] = [:en, :ja, :'zh-CN']
    I18n.fallbacks[:ja] = [:ja, :en, :'zh-CN']
    I18n.fallbacks[:'zh-CN'] = [:'zh-CN', :ja, :en]

@johnnyshields
Copy link
Author

@guigs
Copy link

guigs commented Feb 17, 2014

I have the same issue, but only when config.i18n.enforce_available_locales is false. @johnnyshields, I tried your branch and it fixes the problem.

@johnnyshields
Copy link
Author

Can someone please take a look at this? Believe this is a legitimate problem...

@johnnyshields
Copy link
Author

@klishevich I'm surprised this is not an issue for more people. Do you have any idea what's going on here?

@klishevich
Copy link

@johnnyshields in my case problem was in bad ru.yml file.
it was

en:
    date:
      abbr_day_names:
      - Вс
      - Пн
      - Вт
      - Ср
      - Чт
      - Пт
      - Сб 

it should be

ru:
    date:
      abbr_day_names:
      - Вс
      - Пн
      - Вт
      - Ср
      - Чт
      - Пт
      - Сб 

After I changed everything works fine!

@carlosantoniodasilva
Copy link
Member

@johnnyshields it seems someone else is having a similar issue after the 0.6.10 release. I'll try to take a look when I find some time here.

@johnnyshields
Copy link
Author

@carlosantoniodasilva thank you, your help is much appreciated!

@arthurnn
Copy link
Contributor

@johnnyshields are you using the I18n.backend = I18n::Backend::Chain backend?

arthurnn added a commit to arthurnn/i18n that referenced this issue May 29, 2014
Commit 12aa0f0 introduced a bug, where
if `Fallbacks` module is included in a class that doesnt define
`translations` the code would fail. This is a pretty common
scenario, for instance when the backend is a `Chain`. Also this was
pretty common case to fail in rails, as its include Fallbacks in the
I18n.backend, like this:
```
I18n.backend.class.send(:include, I18n::Backend::Fallbacks)
```

This stops using the `translations` method in the fallbacks, and instead
ignores `I18n::InvalidLocale` errors.

[fixes ruby-i18n#238]
[fixes ruby-i18n#258]
[fixes ruby-i18n#259]
@johnnyshields
Copy link
Author

@arthurnn I think I'm using I18n::Backend::Simple

$> bundle exec rails console
irb(main):006:0> I18n.backend.class == I18n::Backend::Simple
=> true
irb(main):007:0> I18n.backend.class > I18n::Backend::Chain
=> nil
irb(main):008:0> I18n.backend.class == I18n::Backend::Chain
=> false

@carlosantoniodasilva
Copy link
Member

Can you guys try with current master and let us know whether it's working or you are still having issues? Thanks.

@johnnyshields
Copy link
Author

@carlosantoniodasilva @arthurnn this seems to have resolved the issue. Thank you very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants