telegram_libs 0.1.6__tar.gz → 0.1.7__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {telegram_libs-0.1.6 → telegram_libs-0.1.7}/PKG-INFO +1 -1
- {telegram_libs-0.1.6 → telegram_libs-0.1.7}/pyproject.toml +1 -1
- {telegram_libs-0.1.6 → telegram_libs-0.1.7}/src/telegram_libs/__init__.py +1 -1
- telegram_libs-0.1.7/src/telegram_libs/locales/en.json +10 -0
- telegram_libs-0.1.7/src/telegram_libs/locales/ru.json +10 -0
- {telegram_libs-0.1.6 → telegram_libs-0.1.7}/src/telegram_libs/subscription.py +1 -1
- {telegram_libs-0.1.6 → telegram_libs-0.1.7}/src/telegram_libs/translation.py +34 -16
- {telegram_libs-0.1.6 → telegram_libs-0.1.7}/src/telegram_libs/utils.py +3 -3
- {telegram_libs-0.1.6 → telegram_libs-0.1.7}/LICENSE +0 -0
- {telegram_libs-0.1.6 → telegram_libs-0.1.7}/README.md +0 -0
- {telegram_libs-0.1.6 → telegram_libs-0.1.7}/src/telegram_libs/constants.py +0 -0
@@ -3,37 +3,55 @@ import os
|
|
3
3
|
from typing import Any
|
4
4
|
|
5
5
|
|
6
|
-
def
|
7
|
-
"""
|
8
|
-
|
9
|
-
Returns:
|
10
|
-
dict: Translations dictionary
|
11
|
-
"""
|
6
|
+
def _load_translations_from_dir(locales_dir: str) -> dict:
|
7
|
+
"""Helper to load translations from a given directory"""
|
12
8
|
translations = {}
|
13
|
-
# Get the project's root directory (where the script is being run from)
|
14
|
-
project_root = os.path.abspath(os.getcwd())
|
15
|
-
locales_dir = os.path.join(project_root, 'locales')
|
16
|
-
|
17
9
|
if not os.path.exists(locales_dir):
|
18
|
-
print(f"Warning: No 'locales' directory found in {
|
10
|
+
print(f"Warning: No 'locales' directory found in {locales_dir}")
|
19
11
|
return translations
|
20
|
-
|
21
12
|
for filename in os.listdir(locales_dir):
|
22
13
|
if filename.endswith('.json'):
|
23
14
|
lang = filename.split('.')[0]
|
24
15
|
with open(os.path.join(locales_dir, filename), 'r', encoding='utf-8') as f:
|
25
16
|
translations[lang] = json.load(f)
|
26
|
-
|
27
17
|
return translations
|
28
18
|
|
19
|
+
|
20
|
+
def load_translations() -> dict:
|
21
|
+
"""Load translations from locales directory
|
22
|
+
|
23
|
+
Returns:
|
24
|
+
dict: Translations dictionary
|
25
|
+
"""
|
26
|
+
# Get the project's root directory (where the script is being run from)
|
27
|
+
project_root = os.path.abspath(os.getcwd())
|
28
|
+
locales_dir = os.path.join(project_root, 'locales')
|
29
|
+
return _load_translations_from_dir(locales_dir)
|
30
|
+
|
31
|
+
|
32
|
+
def load_common_translations() -> dict:
|
33
|
+
"""Load translations from locales directory in the project
|
34
|
+
|
35
|
+
Returns:
|
36
|
+
dict: Translations dictionary
|
37
|
+
"""
|
38
|
+
locales_dir = os.path.join(os.path.dirname(__file__), 'locales')
|
39
|
+
return _load_translations_from_dir(locales_dir)
|
40
|
+
|
41
|
+
|
29
42
|
TRANSLATIONS = load_translations()
|
43
|
+
COMMON_TRANSLATIONS = load_common_translations()
|
44
|
+
|
30
45
|
|
31
|
-
def t(key: str, lang: str = 'ru', **kwargs: Any) -> str:
|
46
|
+
def t(key: str, lang: str = 'ru', common: bool = False, **kwargs: Any) -> str:
|
32
47
|
"""Get translation for a key with optional formatting"""
|
33
48
|
try:
|
34
49
|
# Support nested keys like "buttons.start"
|
35
50
|
keys = key.split('.')
|
36
|
-
|
51
|
+
if common:
|
52
|
+
value = COMMON_TRANSLATIONS[lang]
|
53
|
+
else:
|
54
|
+
value = TRANSLATIONS[lang]
|
37
55
|
for k in keys:
|
38
56
|
value = value[k]
|
39
57
|
|
@@ -41,5 +59,5 @@ def t(key: str, lang: str = 'ru', **kwargs: Any) -> str:
|
|
41
59
|
except KeyError:
|
42
60
|
# Fallback to English if translation missing
|
43
61
|
if lang != 'en':
|
44
|
-
return t(key, 'en', **kwargs)
|
62
|
+
return t(key, 'en', common=common, **kwargs)
|
45
63
|
return key # Return the key itself as last resort
|
@@ -24,15 +24,15 @@ async def get_subscription_keyboard(update: Update, lang: str) -> InlineKeyboard
|
|
24
24
|
return [
|
25
25
|
[
|
26
26
|
InlineKeyboardButton(
|
27
|
-
t("subscription.plans.1month", lang), callback_data="sub_1month"
|
27
|
+
t("subscription.plans.1month", lang, common=True), callback_data="sub_1month"
|
28
28
|
),
|
29
29
|
InlineKeyboardButton(
|
30
|
-
t("subscription.plans.3months", lang), callback_data="sub_3months"
|
30
|
+
t("subscription.plans.3months", lang, common=True), callback_data="sub_3months"
|
31
31
|
),
|
32
32
|
],
|
33
33
|
[
|
34
34
|
InlineKeyboardButton(
|
35
|
-
t("subscription.plans.1year", lang), callback_data="sub_1year"
|
35
|
+
t("subscription.plans.1year", lang, common=True), callback_data="sub_1year"
|
36
36
|
),
|
37
37
|
],
|
38
38
|
]
|
File without changes
|
File without changes
|
File without changes
|