Skip to content

Commit

Permalink
GUI startup/locale. Changed so that if there's an error when setting …
Browse files Browse the repository at this point in the history
…locale, it shows an error notification on the console and tries to continue. This is to address part of issue #3 on GitHub (comment 17 June 2024).
  • Loading branch information
semiprime committed Jul 21, 2024
1 parent 32c0b9a commit 8d19d8a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
6 changes: 3 additions & 3 deletions docs/config-examples/defaults.ini
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@

# language = language string (e.g. en_GB, en_US, fr)
# UI language. Note: the selected locale must be installed on the
# operating system, otherwise it will give an error and fail to
# start. (To enable a locale on Debian, edit the /etc/locale.gen
# file and then run (sudo) locale-gen.)
# operating system, otherwise it will show an error in the console
# and fall back to the default. (To enable a locale on Debian, edit
# the /etc/locale.gen file and then run (sudo) locale-gen.)
# Default: Use operating system locale

# date_sep = string
Expand Down
11 changes: 10 additions & 1 deletion pygenda/pygenda_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from importlib import import_module
from os import path as ospath
from sys import stderr
from pathlib import Path
import signal
import ctypes
from typing import Optional, Tuple, List, Union, Any, Type
Expand Down Expand Up @@ -427,7 +428,15 @@ def _init_locale(cls) -> None:
if isinstance(lang,str) and '.' not in lang:
# Need to include encoding
lang = (lang,'UTF-8')
locale.setlocale(locale.LC_ALL, lang)
try:
locale.setlocale(locale.LC_ALL, lang)
except locale.Error:
lang_dname = lang if isinstance(lang,str) else '.'.join(lang)
print("Error loading locale {:s} (not installed on OS?)".format(lang_dname), file=stderr)
if Path('/etc/debian_version').exists():
# Add extra info for users on Debian-like systems
print(" On Debian try: uncomment corresponding line in /etc/locale.gen & run locale-gen", file=stderr)
print(" Trying to continue with default locale...", file=stderr)
locale.bindtextdomain('pygenda', cls._LOCALE_DIR)
locale.textdomain('pygenda')

Expand Down

0 comments on commit 8d19d8a

Please sign in to comment.