-
-
Notifications
You must be signed in to change notification settings - Fork 987
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
wrong locale set by kitty #1233
Comments
the locale comes from your OS language settings. Change them and you will be fine. |
@kovidgoyal settings are fine. this is what happens in Terminal.app
this is what happens in kitty
|
that just means terminal.app is using a different technique to deduce the locale, which happens to work on your system. |
oh and the relevant function in kitty code is cocoa_get_lang() if you think there is a bug in that, feel free to submit a patch, I can see no bug. |
I also got this issue and fixed it by setting
|
I'm having this as well. It's pretty annoying, if I'm not able to fix this, I'll have to find another terminal. I did not find a fix for this anywhere also, so perhaps some action should be taken on behaf of kitty devs? iTerm works out of the box, as does the built in terminal app |
As of 0.16.0, Kitty sets LC_CTYPE='UTF-8' which is wrong. (iTerm2, Terminal do not) |
No, it doesn't. grep the codebase for LC_CTYPE |
I also experience the invalid setting of Apparently for some applications I have now helped myself with a dirty workaround, by explicitly setting the locale I want via:
After doing that (and restarting kitty) the |
Even though the linked comments refer to iOS instead of macOS, they might still point in the correct direction: |
According to those posts currentLocale should return only a locale kitty is localized for. kitty is not localized for de_DE, so I dont see how the issue could be that. |
You are right: It shouldn't. This matches the problem description for me and all of the posters above that it doesn't. It returns It does only return the correct identifier, when forced to do so via the |
Well if you have a suggestion that works better, I'm all ears, as I said before, the relevant function is cocoa_get_lang() which is just a wrapper around currentLocale(). A possible alternative is to use preferredLanguages() instead of currentLocale(). Or alternately to validate the locale returned by currentLocale() by using newlocale() to construct a locale based on it. |
I already played around with an alternate implementation of In the "Swift Playground" that exhibits the same behavior as kitty, I also evaluated What bothers me is that even after a few hours of investigating I don't yet have the slightest clue, what causes macOS to behave that way for certain applications. |
On Wed, Jun 17, 2020 at 11:44:19PM -0700, Kimon Hoffmann wrote:
In the "Swift Playground" that exhibits the same behavior as kitty, I also evaluated `perferredLanguages`, which *does* contain the desired identifier, but in practice it might be difficult to determine, which array element is the one to use.
According to https://developer.apple.com/documentation/foundation/nslocale/1415614-preferredlanguages
the first language is the "primary language".
|
Yes, I am aware of that, but in the case of the affected "Swift Playground" this is not the case. In an application that does not exhibit the problematic behavior, on my local system
In an application that does exhibit the problematic behaviour, the values are:
This leads me to another suspicion, namely that for applications affected by this behavior the locale information is not somehow restricted - as suspected in the comments linked earlier - but instead that the language code Please note: Observing this behavior is notoriously difficult, because any context, in which the environment contains a properly set
Does not exhibit the problem, while starting it via
or via
does. |
Found it!
|
I think the best solution is to check the validity of the locale in |
See my latest comment above. I attached a patch that does not change the behaviour as it is right now, but hopefully makes the function more resilient in general. Feel free to use it if you like. |
Interesting, I wonder thought what side-effects removing that would have.
I looked at for example iterms plist, and it has it set to an invalid
value of "English" https://github.com/gnachman/iTerm2/blob/master/plists/iTerm2.plist#L24
…On Thu, Jun 18, 2020 at 05:42:43AM -0700, Kimon Hoffmann wrote:
Found it!
Removing the following key value pair from `Info.plist` solves the problem:
```
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
```
--
You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub:
#1233 (comment)
--
_____________________________________
Dr. Kovid Goyal
https://www.kovidgoyal.net
https://calibre-ebook.com
_____________________________________
|
Looking at https://bugreports.qt.io/browse/QTBUG-63324?focusedCommentId=371735&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel
apparently either creating an empty file at Resources/empty.lproj
or adding CFBundleAllowMixedLocalizations might also work. Can you
confirm?
…On Thu, Jun 18, 2020 at 05:50:10AM -0700, Kimon Hoffmann wrote:
See my latest comment above.
With this change `cocoa_get_locale()` works as advertised.
I attached a patch that does not change the behaviour as it is right now, but hopefully makes the function more resilient in general. Feel free to use it if you like.
[patch-cocoa_get_locale.txt](https://github.com/kovidgoyal/kitty/files/4798606/locale.txt)
--
You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub:
#1233 (comment)
--
_____________________________________
Dr. Kovid Goyal
https://www.kovidgoyal.net
https://calibre-ebook.com
_____________________________________
|
I've also looked at various applications and what is "correct" (for those that have it) is not that clear cut. Some have Removing it should make no difference as this setting corresponds to a setting in Xcode (Edit Scheme -> Run -> Options) where you can set the application locale to explicitly differ from the system locale, mostly for debugging purposes. |
I'll check that out and report back. |
Yes, I can confirm that both options also have the desired effect, both independently and combined. |
I just investigated a little bit further and realized that one statement I made earlier is not quite correct: While all the workarounds and solutions discussed fix the incorrect setting of the |
That will be coming from the shell, kitty itself does not set LC_CTYPE, |
Yes, I didn't want to imply that kitty is explicitly setting it. [*] other emulators tested:
|
Like what?? The only way kitty has to communicate with child processes In fact iTerm for example, actually does set LC_CTYPE https://github.com/gnachman/iTerm2/blob/faf3b633cee9d8749ca2f02a5b3226af4f93411f/sources/PTYSession.m#L1656 |
I followed the See: $ env -i /usr/bin/python3
Python 3.7.3 (default, Apr 24 2020, 18:51:23)
[Clang 11.0.3 (clang-1103.0.32.62)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.environ
environ({'__CF_USER_TEXT_ENCODING': '0x1F5:0x0:0x3', 'SDKROOT': '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk', 'CPATH': '/usr/local/include', 'LIBRARY_PATH': '/usr/local/lib', '__PYVENV_LAUNCHER__': '/Applications/Xcode.app/Contents/Developer/usr/bin/python3', 'LC_CTYPE': 'UTF-8'}) Compared to: $ env -i /usr/bin/python
Python 2.7.16 (default, Apr 17 2020, 18:29:03)
[GCC 4.2.1 Compatible Apple LLVM 11.0.3 (clang-1103.0.29.20) (-macos10.15-objc- on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.environ
{'__CF_USER_TEXT_ENCODING': '0x1F5:0x0:0x3', 'VERSIONER_PYTHON_VERSION': '2.7'} According to various discussions around this topic macOSs (or python on macOSs) setting of It might be an option to apply some kind of heuristic to determine whether |
Does running
kitty +runpy 'import os, pprint; pprint.pprint(dict(os.environ))'
also insert LC_CTYPE into the environment?
…On Wed, Jun 24, 2020 at 05:20:30AM -0700, Kimon Hoffmann wrote:
I followed the `LC_CTYPE` rabbit hole a bit further and it seems to be a behavior inherent to python 3 on macOS (at least on macOS Catalina).
See:
```sh
$ env -i /usr/bin/python3
Python 3.7.3 (default, Apr 24 2020, 18:51:23)
[Clang 11.0.3 (clang-1103.0.32.62)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.environ
environ({'__CF_USER_TEXT_ENCODING': '0x1F5:0x0:0x3', 'SDKROOT': '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk', 'CPATH': '/usr/local/include', 'LIBRARY_PATH': '/usr/local/lib', '__PYVENV_LAUNCHER__': '/Applications/Xcode.app/Contents/Developer/usr/bin/python3', 'LC_CTYPE': 'UTF-8'})
```
Compared to:
```sh
$ env -i /usr/bin/python
Python 2.7.16 (default, Apr 17 2020, 18:29:03)
[GCC 4.2.1 Compatible Apple LLVM 11.0.3 (clang-1103.0.29.20) (-macos10.15-objc- on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.environ
{'__CF_USER_TEXT_ENCODING': '0x1F5:0x0:0x3', 'VERSIONER_PYTHON_VERSION': '2.7'}
```
According to various discussions around this topic macOSs (or python on macOSs) setting of `LC_CTYPE=UTF-8` is actually conforming to POSIX, but a lot of tools have trouble with it, because they expect the `locale.encoding` format.
It might be an option to apply some kind of heuristic to determine whether `LC_CTYPE` in the environment should be considered an artifact (and not an intentional choice made by the user) that should be remedied by unsetting it.
--
You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub:
#1233 (comment)
--
_____________________________________
Dr. Kovid Goyal
https://www.kovidgoyal.net
https://calibre-ebook.com
_____________________________________
|
Yes, it does: $ env -i ./kitty.app/Contents/MacOS/kitty +runpy 'import os, pprint; pprint.pprint(dict(os.environ))'
{'LC_CTYPE': 'UTF-8', '__CF_USER_TEXT_ENCODING': '0x1F5:0x0:0x3'} |
Hmm not sure what a good solution is here then. Since UTF-8 is a valid |
Yes, I agree that it's tricky. One heuristic I could imagine would be (only on macOS) to see, whether
|
… the language and country code do not form a valid locale Fixes #1233
Should be fixed by my latest commit
…On Wed, Jun 24, 2020 at 08:10:03AM -0700, Kimon Hoffmann wrote:
Yes, I agree that it's tricky.
One heuristic I could imagine would be (only on macOS) to see, whether
1. `LC_CTYPE` is equal to `UTF-8` and
2. `LC_ALL` is unset (or alternatively no other `LC_*` variable is set)
--
You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub:
#1233 (comment)
--
_____________________________________
Dr. Kovid Goyal
https://www.kovidgoyal.net
https://calibre-ebook.com
_____________________________________
|
… the language and country code do not form a valid locale Fixes #1233
Yes, I can confirm that the erroneous And i really like the way you solved it, because no guessing is involved. |
The spotlight search in the "Help" menu of the menu bar did not appear when the system language is set to a language other than English. macOS magically adds the search box when the text in that menu matches the translation of "Help" in the system language. On my German system for example replacing "Help" with "Hilfe" will make the search box appear again. This is however not a good solution for kitty as it would require implementing localization support for all languages. Removing `CFBundleAllowMixedLocalizations=True` from `setup.py` also brings back the search box but that may break the locale again. The line was added in 8818b5d to fix an issue related to kovidgoyal#1233. Luckily I found a seemingly undocumented function that helps us out here, which does not rely the text comparison magic.
locale |
this happens on macOS Mojave with kitty 0.13.1
locale
en_IT
is wrong and it also it breaks nvim math functions, because e.g.str2float("3.3")
returns "3.0"The text was updated successfully, but these errors were encountered: