cargo-i18n icon indicating copy to clipboard operation
cargo-i18n copied to clipboard

Cannot parse locale on macOS

Open ancwrd1 opened this issue 4 years ago • 14 comments

Observed on macOS Catalina and Big Sur, when the LC_CTYPE envrionment variable is set to UTF-8 (seems like a default for macOS, at least in the terminal application). The DesktopRequester fails with InvalidLanguage error.

ancwrd1 avatar Mar 06 '21 09:03 ancwrd1

thanks for the issue report, I'll look into it soon

kellpossible avatar Mar 11 '21 20:03 kellpossible

@ancwrd1 Sounds like it could be an issue with our upstream dependency https://github.com/rust-locale/locale_config/ I don't have a Mac to test this properly, would you be happy to try that library with your environment variable and see if it is broken there too?

kellpossible avatar Mar 18 '21 00:03 kellpossible

Considering that dependency looks close to abandoned I'd consider forking it or bringing it into this project, or finding some alternative.

kellpossible avatar Mar 18 '21 00:03 kellpossible

would you be happy to try that library with your environment variable and see if it is broken there too?

Tried the example from locale_config with the same issue.

Generally it depends on the setting of the terminal application, Set locale environment on startup. By default this option is turned on. When it is turned on the LC_CTYPE env variable is set to UTF-8 and obtaining a locale fails. When it is turned off there is no LC_CTYPE variable set and locale_config detects the locale as en-NL (language set to English, region set to Netherlands).

So to my understanding the fix would be to ignore the LC_CTYPE method if it doesn't contain a proper language-region prefix. Or perhaps don't use it at all on macOS.

ancwrd1 avatar Mar 18 '21 11:03 ancwrd1

@ancwrd1 Would it be possible for you to show the output of your LC_CTYPE variable?

kellpossible avatar Mar 23 '21 01:03 kellpossible

Yes, here it is:

lcctype

I tried it on recent macOS versions 10.15 and 11.0.

Depends on this option in the terminal application settings. It is turned on by default.

Screenshot_20210323_203324

If this option is turned off the LC_CTYPE is not set. I think local_config uses macOS API to get the locale in this case.

ancwrd1 avatar Mar 23 '21 19:03 ancwrd1

@ancwrd1 Thanks! Iteresting ohhh it's literally UTF-8 :laughing: for some reason I assumed that it was some UTF-8 string that wasn't able to be parsed by the locale_config library. Makes sense though I guess, the variable represents the encoding type?

kellpossible avatar Mar 23 '21 19:03 kellpossible

Makes sense though I guess, the variable represents the encoding type?

Most likely, yes. So shouldn't be used on mac I guess.

ancwrd1 avatar Mar 23 '21 20:03 ancwrd1

locale_config appears to be fairly abandoned, if someone knows of a good alternative I'm definitely open to replacing it

kellpossible avatar Nov 29 '21 16:11 kellpossible