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

Problem with locales containing underscores #143

Open
krukgit opened this issue Oct 9, 2015 · 3 comments
Open

Problem with locales containing underscores #143

krukgit opened this issue Oct 9, 2015 · 3 comments

Comments

@krukgit
Copy link

krukgit commented Oct 9, 2015

The locale.gsub('_', '-') i18n hack is preventing the page from loading on Rails 4.2.3 and i18n 0.7.0

2.1.5 :010 > I18n.available_locales
 => ["en", "th", "zh_CN", "zh_HK"] 
2.1.5 :011 > I18n.locale = :en
 => :en 
2.1.5 :012 > I18n.locale
 => :en 
2.1.5 :013 > I18n.locale = :zh_HK
 => :zh_HK 
2.1.5 :014 > I18n.locale 
 => :"zh-HK" 

This results in I18n::InvalidLocale: :"zh-HK" is not a valid locale exception.

Monkey patching I18n to remove this hack fixes the problem.

@grosser
Copy link
Owner

grosser commented Oct 9, 2015

you can turn off the enforce_available_locales ... not sure if that just silences or fixed the problem ...

I think the hack is there to make gettext locales look like i18n locales for compatibility ... maybe also patch available_locales ... or just the place that raises the exception ...

alternatively remove the hack and see which tests blows up ...

@martyphee
Copy link

@krukgit What ended up working for you? I'm running into the same issue.

@martyphee
Copy link

This seems to be working for me.

In the initializer I have:

module I18n
  class Config
    def locale
      FastGettext.locale.to_sym
    end
  end
end

In the application.rb I changed our I18n config to use underscores instead of hyphens:

config.i18n.available_locales = [:en, :fr, :de, :nl, :es, :it, :nl_BE]

I renamed our nl-BE.yml to nl_BE.yml`

So far this looks to be working.

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

No branches or pull requests

3 participants