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

Always instantiate I18n::Locale::Fallbacks objects when using I18n.fallbacks= #535

Merged
merged 2 commits into from Jul 20, 2020

Conversation

radar
Copy link
Collaborator

@radar radar commented Jul 15, 2020

Should fix #534.

@radar
Copy link
Collaborator Author

radar commented Jul 15, 2020

@sshaw Would you mind trying out this branch within the next ~12ish hours? If it's fine for you and for CI, I'm happy to merge it and do a 1.8.4 release.

@sshaw
Copy link
Contributor

sshaw commented Jul 15, 2020

Using the same config which, from your comments on #534 seems to be the goal, I get:

rails [5.0.7.2] (xxx)$ I18n.l Time.now, :format => :long, :locale => "XX"
Traceback (most recent call last):
       12: from ./bin/rails:4:in `<main>'
       11: from ./bin/rails:4:in `require'
       10: from /Users/sshaw/.rvm/gems/ruby-2.5.2/gems/railties-5.0.7.2/lib/rails/commands.rb:18:in `<top (required)>'
        9: from /Users/sshaw/.rvm/gems/ruby-2.5.2/gems/railties-5.0.7.2/lib/rails/commands/commands_tasks.rb:49:in `run_command!'
        8: from /Users/sshaw/.rvm/gems/ruby-2.5.2/gems/railties-5.0.7.2/lib/rails/commands/commands_tasks.rb:78:in `console'
        7: from /Users/sshaw/.rvm/gems/ruby-2.5.2/gems/railties-5.0.7.2/lib/rails/commands/console_helper.rb:9:in `start'
        6: from /Users/sshaw/.rvm/gems/ruby-2.5.2/gems/railties-5.0.7.2/lib/rails/commands/console.rb:65:in `start'
        5: from (irb):1
        4: from /Users/sshaw/.rvm/gems/ruby-2.5.2/bundler/gems/i18n-741845cfec07/lib/i18n.rb:301:in `localize'
        3: from /Users/sshaw/.rvm/gems/ruby-2.5.2/bundler/gems/i18n-741845cfec07/lib/i18n/backend/base.rb:84:in `localize'
        2: from /Users/sshaw/.rvm/gems/ruby-2.5.2/bundler/gems/i18n-741845cfec07/lib/i18n.rb:211:in `translate'
        1: from /Users/sshaw/.rvm/gems/ruby-2.5.2/bundler/gems/i18n-741845cfec07/lib/i18n.rb:373:in `handle_exception'
I18n::MissingTranslationData (translation missing: XX.time.formats.long)

Config:

require "i18n/backend/fallbacks"

I18n::Backend::Simple.send(:include, I18n::Backend::Fallbacks)
I18n.enforce_available_locales = false

@sshaw
Copy link
Contributor

sshaw commented Jul 15, 2020

But...

I18n::Backend::Simple.send :include, I18n::Backend::Fallbacks
I18n.enforce_available_locales = false
I18n.fallbacks = [I18n.default_locale]

Works 🎆

One thing I do notice is the first calls to I18n.l takes maybe 4 seconds to return. Using rails-i18n too.

@radar
Copy link
Collaborator Author

radar commented Jul 20, 2020

@sshaw That first call to I18n.l will probably be I18n loading in your translations: ref.

@radar radar merged commit 360b8b7 into master Jul 20, 2020
@radar radar deleted the fallbacks branch July 20, 2020 00:26
@radar
Copy link
Collaborator Author

radar commented Jul 20, 2020

@sshaw Thanks for your patience on this one. I have just pushed 1.8.4 with the changes from this PR.

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 this pull request may close these issues.

TypeError (no implicit conversion of String into Integer) -- While using I18n.l
2 participants