Skip to content

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

@philipcunningham

Description

@philipcunningham

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions