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

Allows you set available formats with hyphens but lookups fail #81

Open
mcfilib opened this issue Jun 3, 2016 · 3 comments
Open

Allows you set available formats with hyphens but lookups fail #81

mcfilib opened this issue Jun 3, 2016 · 3 comments

Comments

@mcfilib
Copy link

mcfilib commented Jun 3, 2016

When I use IETF Language Tags instead of POSIX locales in .default_available_locales, fast_gettext formats the hyphen to an underscore when calling .set_locale.

I came across this when trying to use IETF Language Tags instead of POSIX locales in a Rails application and I'm wondering if you could offer some clarification as to whether this is the expected behaviour or whether there might be some room for improvement.

Reproduction Steps

[12] pry(#<DashboardController>)> FastGettext.default_available_locales = ["en-GB", "es-ES"]
=> ["en-GB", "es-ES"]
[13] pry(#<DashboardController>)> FastGettext.available_locales
=> ["en-GB", "es-ES"]
[14] pry(#<DashboardController>)> FastGettext.set_locale("es-ES")
=> "en-GB"

This happens because FastGettext formats my input using #set_locale, replacing the hyphen with an underscore, before doing a lookup on the available locales e.g.

[15] pry(#<DashboardController>)> FastGettext.send(:formatted_sorted_locales, "es-ES")
=> ["es_ES"]
[16] pry(#<DashboardController>)> FastGettext.available_locales.include?("es_ES")
=> false

Question

Should FastGettext be replacing hyphens at all? Is this behaviour also present in gettext?

@mcfilib
Copy link
Author

mcfilib commented Jun 3, 2016

Here's a link the issue which gives more context webhippie/gettext_i18n_rails_js#31.

@grosser
Copy link
Owner

grosser commented Jun 9, 2016

afaik this is expected behavior since po files use underscores and rails wants to use - ... so conversion was added

@grosser
Copy link
Owner

grosser commented Jun 9, 2016

the usage you showed above looks broken though ... so there definitely is room for improvement :/

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

2 participants