petronny / pinyin-completion

complete path name based upon the pinyin acronym of Chinese characters
GNU General Public License v3.0
63 stars 13 forks source link

[bug] unsupported locale setting #14

Closed Freed-Wu closed 1 year ago

Freed-Wu commented 1 year ago

In ubuntu-20.04 LTS:

❯ pinyin-comp -d a
Traceback (most recent call last):
  File "/home/wzy/.local/share/zinit/plugins/pinyin-completion/pinyin-comp", line 233, in <module>
    locale.setlocale(locale.LC_ALL, "")
  File "/usr/lib/python3.10/locale.py", line 620, in setlocale
    return _setlocale(category, locale)
locale.Error: unsupported locale setting

I find comment locale.setlocale(locale.LC_ALL, "") can make this plugin work. What is the function of this line? Can we remove it or change it to:

from contextlib import suppress
import locale

with suppress(locale.Error):
    locale.setlocale(locale.LC_ALL, "")
Freed-Wu commented 1 year ago

Oh, it looks like locale's bug:

$ locale
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_MESSAGES to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory
Freed-Wu commented 1 year ago

Solution:

sudo sed -i 's/^# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/g' /etc/locale.gen
sudo locale-gen