telegram_libs 0.1.0__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.
@@ -0,0 +1,22 @@
|
|
1
|
+
Metadata-Version: 2.3
|
2
|
+
Name: telegram_libs
|
3
|
+
Version: 0.1.0
|
4
|
+
Summary: Common libraries for Telegram bots
|
5
|
+
Author: Andrey Gritsaenko gricaenko.95a@gmail.com
|
6
|
+
Requires-Python: >=3.11,<4.0
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
8
|
+
Classifier: Programming Language :: Python :: 3.11
|
9
|
+
Classifier: Programming Language :: Python :: 3.12
|
10
|
+
Classifier: Programming Language :: Python :: 3.13
|
11
|
+
Requires-Dist: pytest (>=8.3.5,<9.0.0)
|
12
|
+
Description-Content-Type: text/markdown
|
13
|
+
|
14
|
+
# Telegram Libs
|
15
|
+
|
16
|
+
Common functionality for Andrey Gritsaenko's Telegram bots.
|
17
|
+
|
18
|
+
## Installation
|
19
|
+
|
20
|
+
```bash
|
21
|
+
pip install telegram-libs
|
22
|
+
```
|
@@ -0,0 +1,15 @@
|
|
1
|
+
[tool.poetry]
|
2
|
+
name = "telegram_libs"
|
3
|
+
version = "0.1.0"
|
4
|
+
description = "Common libraries for Telegram bots"
|
5
|
+
authors = ["Andrey Gritsaenko gricaenko.95a@gmail.com"]
|
6
|
+
readme = "README.md"
|
7
|
+
packages = [{include = "telegram_libs", from = "src"}]
|
8
|
+
|
9
|
+
[tool.poetry.dependencies]
|
10
|
+
python = "^3.11"
|
11
|
+
pytest = "^8.3.5"
|
12
|
+
|
13
|
+
[build-system]
|
14
|
+
requires = ["poetry-core"]
|
15
|
+
build-backend = "poetry.core.masonry.api"
|
@@ -0,0 +1,32 @@
|
|
1
|
+
import json
|
2
|
+
import os
|
3
|
+
|
4
|
+
def load_translations():
|
5
|
+
translations = {}
|
6
|
+
locales_dir = os.path.join(os.path.dirname(__file__), 'locales')
|
7
|
+
|
8
|
+
for filename in os.listdir(locales_dir):
|
9
|
+
if filename.endswith('.json'):
|
10
|
+
lang = filename.split('.')[0]
|
11
|
+
with open(os.path.join(locales_dir, filename), 'r', encoding='utf-8') as f:
|
12
|
+
translations[lang] = json.load(f)
|
13
|
+
|
14
|
+
return translations
|
15
|
+
|
16
|
+
TRANSLATIONS = load_translations()
|
17
|
+
|
18
|
+
def t(key, lang='ru', **kwargs):
|
19
|
+
"""Get translation for a key with optional formatting"""
|
20
|
+
try:
|
21
|
+
# Support nested keys like "buttons.start"
|
22
|
+
keys = key.split('.')
|
23
|
+
value = TRANSLATIONS[lang]
|
24
|
+
for k in keys:
|
25
|
+
value = value[k]
|
26
|
+
|
27
|
+
return value.format(**kwargs) if kwargs else value
|
28
|
+
except KeyError:
|
29
|
+
# Fallback to English if translation missing
|
30
|
+
if lang != 'en':
|
31
|
+
return t(key, 'en', **kwargs)
|
32
|
+
return key # Return the key itself as last resort
|