mike-fabian / ibus-typing-booster

ibus-typing-booster is a completion input method for faster typing
https://mike-fabian.github.io/ibus-typing-booster/
Other
233 stars 15 forks source link

Need to distinguish between ks_IN and ks_IN@devanagari when getting the default input methods #209

Closed mike-fabian closed 3 years ago

mike-fabian commented 3 years ago

https://docs.python.org/3/library/locale.html says:

locale.getlocale(category=LC_CTYPE)

Returns the current setting for the given locale category as sequence containing language code, encoding. category may be one of the LC_* values except LC_ALL. It defaults to LC_CTYPE.

That doesn’t return the @devanagari !

mike-fabian commented 3 years ago

It ignores all modifiers except @euro:

$ LC_ALL=de_DE python3
Python 3.9.5 (default, May 14 2021, 00:00:00) 
[GCC 11.1.1 20210428 (Red Hat 11.1.1-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import locale
>>> locale.getlocale(category=locale.LC_CTYPE)
('de_DE', 'ISO8859-1')
>>> 
$ LC_ALL=de_DE@euro python3
Python 3.9.5 (default, May 14 2021, 00:00:00) 
[GCC 11.1.1 20210428 (Red Hat 11.1.1-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import locale
>>> locale.getlocale(category=locale.LC_CTYPE)
('de_DE', 'ISO8859-15')
>>> 
$ LC_ALL=ks_IN python3
Python 3.9.5 (default, May 14 2021, 00:00:00) 
[GCC 11.1.1 20210428 (Red Hat 11.1.1-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import locale
>>> locale.getlocale(category=locale.LC_CTYPE)
('ks_IN', 'UTF-8')
>>> 
$ LC_ALL=ks_IN@devanagari python3
Python 3.9.5 (default, May 14 2021, 00:00:00) 
[GCC 11.1.1 20210428 (Red Hat 11.1.1-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import locale
>>> locale.getlocale(category=locale.LC_CTYPE)
('ks_IN', 'UTF-8')
>>> 
$
mike-fabian commented 3 years ago

https://github.com/python/cpython/blob/main/Lib/locale.py#L385 :

def _append_modifier(code, modifier):
    if modifier == 'euro':
        if '.' not in code:
            return code + '.ISO8859-15'
        _, _, encoding = code.partition('.')
        if encoding in ('ISO8859-15', 'UTF-8'):
            return code
        if encoding == 'ISO8859-1':
            return _replace_encoding(code, 'ISO8859-15')
    return code + '@' + modifier
mike-fabian commented 3 years ago

https://github.com/python/cpython/blob/main/Lib/locale.py#L479

    if '@' in code:
        # Deal with locale modifiers
        code, modifier = code.split('@', 1)
        if modifier == 'euro' and '.' not in code:
            # Assume Latin-9 for @euro locales. This is bogus,
            # since some systems may use other encodings for these
            # locales. Also, we ignore other modifiers.
            return code, 'iso-8859-15'