summaryrefslogtreecommitdiff
path: root/lib/i18n.py
diff options
context:
space:
mode:
authorcapellancitizen <thecapellancitizen@gmail.com>2025-03-09 21:21:48 -0400
committerGitHub <noreply@github.com>2025-03-09 21:21:48 -0400
commit99509df8d8abf1e7b701a4a09cf170a362f6d878 (patch)
treea461549502fa9f37dc287789b6c7db81dfcd5368 /lib/i18n.py
parent0d2fc24f25f87562f0755b53dad6204efad1330d (diff)
Mypy type correctness (#3199)
Diffstat (limited to 'lib/i18n.py')
-rw-r--r--lib/i18n.py16
1 files changed, 6 insertions, 10 deletions
diff --git a/lib/i18n.py b/lib/i18n.py
index 2a901a0e..b2a2b002 100644
--- a/lib/i18n.py
+++ b/lib/i18n.py
@@ -5,30 +5,27 @@
import gettext
import os
+from typing import Callable, Tuple
from .utils import cache, get_resource_dir
-_ = translation = None
-locale_dir = None
-
# Use N_ to mark a string for translation but _not_ immediately translate it.
# reference: https://docs.python.org/3/library/gettext.html#deferred-translations
# Makefile configures pybabel to treat N_() the same as _()
-def N_(message): return message
+def N_(message: str) -> str:
+ return message
-def _set_locale_dir():
- global locale_dir
+def localize(languages=None) -> Tuple[Callable[[str], str], gettext.NullTranslations]:
locale_dir = get_resource_dir('locales')
-
-def localize(languages=None):
global translation, _
translation = gettext.translation("inkstitch", locale_dir, fallback=True)
_ = translation.gettext
+ return (_, translation)
@cache
@@ -53,5 +50,4 @@ def get_languages():
return languages
-_set_locale_dir()
-localize()
+_, translation = localize()