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

Locales are case sensitive #484

Open
PanMan opened this issue Oct 26, 2021 · 3 comments
Open

Locales are case sensitive #484

PanMan opened this issue Oct 26, 2021 · 3 comments
Assignees

Comments

@PanMan
Copy link

PanMan commented Oct 26, 2021

This took us some time to debug: Locales are case sensitive when the filesystem is.
On OSX (case insensitive) setting the locale to NL got strings from nl.json
In production, on a linux server, this failed and the strings didn't get translated.
I feel this should at least be in the docs, or always work case-insensitive

@mashpie mashpie self-assigned this Oct 26, 2021
@mashpie
Copy link
Owner

mashpie commented Oct 26, 2021

....well, yes. When started, I decided to leave cases and names of any locale completely untouched and up to the developers or frameworks responsibility to handle it "their way"

File systems act differently - which is a well-known issue when working with git on Mac either way. But that's only part of the story. There are query-parameters, accept-headers and developers setting locales programmatically by setLocale() api. The i18n package kept matching locales "as-provided" to their files for ~ 10 years now, which treats 'en', 'en-EN', 'en_EN' individually. Let's say I got mislead by POSIX examples of locales while BCP 47 and other RTF and ISO Standards clearly state to interpret locales, headers and env variables case insensitively.

I am back referencing to #128 here. And though I can't think of a reasonable use-case, changing that could break. Adding a simpletoLowerCase() looks pretty easy, but should be either opt-in or opt-out (preceded by a deprecation period) with a config switch.

Points left to consider:

  1. handle conflicting files (like: 'en-EN.json', 'en_EN.json', 'en-en.json') while reading & writing?
  2. handle legacy configs like locales: ['en', 'en-EN', 'en_EN']?
  3. setLocale() parameter matching
  4. getLocale() return value matching

Could i18n normalize locales? Yes. Should i18n normalize locales? Only if this won't break existing implementations.

Any further thoughts are welcome.

@PanMan
Copy link
Author

PanMan commented Oct 26, 2021

Thanks for the extensive response!
I understand everybody's usecase is different - and you don't want to break current behaviour. However, we Did run into this in our current project - twice, even :). Especially as it did work in development.
I can understand not changing the behaviour, or making it optional, but I do think it would be good to include in the documentation. I thought about a pull request, but it wasn't immediately obvious to me where it would make most sense in the docs.

@mashpie
Copy link
Owner

mashpie commented Oct 26, 2021 via email

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

No branches or pull requests

2 participants