telegram_libs 0.1.6__py3-none-any.whl → 0.1.7__py3-none-any.whl

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/__init__.py CHANGED
@@ -2,4 +2,4 @@
2
2
  Telegram Libs - Common libraries for Telegram bots
3
3
  """
4
4
 
5
- __version__ = "0.1.6"
5
+ __version__ = "0.1.7"
@@ -0,0 +1,10 @@
1
+ {
2
+ "subscription": {
3
+ "choose_plan": "Choose a subscription plan:",
4
+ "plans": {
5
+ "1month": "1 Month - 250 Stars",
6
+ "3months": "3 Months - 500 Stars",
7
+ "1year": "1 Year - 1600 Stars"
8
+ }
9
+ }
10
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "subscription": {
3
+ "choose_plan": "Выберите план подписки:",
4
+ "plans": {
5
+ "1month": "1 месяц - 250 Stars",
6
+ "3months": "3 месяца - 500 Stars",
7
+ "1year": "1 год - 1600 Stars"
8
+ }
9
+ }
10
+ }
@@ -52,4 +52,4 @@ def check_subscription_status(user_id: int) -> bool:
52
52
  return False
53
53
 
54
54
  expiration = datetime.fromisoformat(subscription["premium_expiration"])
55
- return expiration > datetime.now()
55
+ return expiration > datetime.now()
@@ -3,37 +3,55 @@ import os
3
3
  from typing import Any
4
4
 
5
5
 
6
- def load_translations() -> dict:
7
- """Load translations from locales directory
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 {project_root}")
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
- value = TRANSLATIONS[lang]
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
telegram_libs/utils.py CHANGED
@@ -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
  ]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: telegram_libs
3
- Version: 0.1.6
3
+ Version: 0.1.7
4
4
  Summary: Common libraries for Telegram bots
5
5
  Author: Andrey Gritsaenko gricaenko.95a@gmail.com
6
6
  Requires-Python: >=3.11,<4.0
@@ -0,0 +1,11 @@
1
+ telegram_libs/__init__.py,sha256=d36zPCq6j5RJuKHhr4Y3CvoUFuCUJihdLlJOZh3QW9o,81
2
+ telegram_libs/constants.py,sha256=F6pgwAuv2FgGZxxFwYYJomM4_hosexLoYsvHXQiuVNg,538
3
+ telegram_libs/locales/en.json,sha256=KBSPceLmnXofYombDIsF9tMQ_slidi6BGZ_64MYVI1A,216
4
+ telegram_libs/locales/ru.json,sha256=xM_6OFya8jRpQoNepwUjNXvTa_voNkqHkqZc-oSl8-Y,245
5
+ telegram_libs/subscription.py,sha256=qUFo8QLOUoAZFvlQM1lWojpKwVwzhLvWPeyk45nP2sg,1844
6
+ telegram_libs/translation.py,sha256=8Kb2cgqKKZH4X_i2Le0V_K1imZdoaCzYAca831DOBig,2049
7
+ telegram_libs/utils.py,sha256=B3-ckW0G6dHzdi79pt0R7-VVL7_fc9S4XUdJD8ccS6Q,1711
8
+ telegram_libs-0.1.7.dist-info/LICENSE,sha256=ZXkWPZbCc61L29Gz6ZHPwn1c4Pm0TnfIqtx8jGWi9F4,1069
9
+ telegram_libs-0.1.7.dist-info/METADATA,sha256=7TDy4XEkecsd01a6VG9oemBqWmxXxFhlKTSRmUHLXgE,803
10
+ telegram_libs-0.1.7.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
11
+ telegram_libs-0.1.7.dist-info/RECORD,,
@@ -1,9 +0,0 @@
1
- telegram_libs/__init__.py,sha256=AVIn-Xg8urpHrIPL6D6eYjLlG_J7l5nQQ3e8AnB8D_s,82
2
- telegram_libs/constants.py,sha256=F6pgwAuv2FgGZxxFwYYJomM4_hosexLoYsvHXQiuVNg,538
3
- telegram_libs/subscription.py,sha256=3NenqG9JL7FJEu56TqnYBF5piJg-r4j8mT4-TjPtoBM,1845
4
- telegram_libs/translation.py,sha256=OB89EyvwA89hxDfOJQcod96xoR5FSM4hsexl3_muqq0,1434
5
- telegram_libs/utils.py,sha256=d_abNI0xj6WXIpj9tsjO9f3GzqWZ2x4x1VHBcfGStO4,1672
6
- telegram_libs-0.1.6.dist-info/LICENSE,sha256=ZXkWPZbCc61L29Gz6ZHPwn1c4Pm0TnfIqtx8jGWi9F4,1069
7
- telegram_libs-0.1.6.dist-info/METADATA,sha256=sw2xdps8RR4I81O7k19qpXRDXVPTm5uAS3rUy_LLYW0,803
8
- telegram_libs-0.1.6.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
9
- telegram_libs-0.1.6.dist-info/RECORD,,