Fluent i18n implementation for telegrinder
Project description
Usage
pip install fluent-telegrinder
CLI
# Pre-compile .ftl files into .ftlc (pickled AST) for faster startup:
ftl-compile locales/
# Write compiled files to a separate directory:
ftl-compile locales/ --output locales_compiled/
# Force overwrite existing .ftlc files:
ftl-compile locales/ --force
Then enable compiled loading in your config:
config = FluentConfig(
folder="locales/",
source=DefaultLocaleSource,
use_compiled=True, # loads .ftlc files, falls back to .ftl if absent
)
from telegrinder import API, Message, Telegrinder, Token
from fluent_telegrinder import (
DefaultLocaleSource, # / UserLanguageSource
FluentConfig,
Translator,
TextEquals,
)
config = FluentConfig(
folder="locales/",
source=DefaultLocaleSource, # any node that returns str - source for locale
default_locale="ru",
replace_underscore=True, # i_love_telegrinder -> i-love-telegrinder
)
Translator.configure(config)
bot = Telegrinder(API(Token.from_env()))
@bot.on.message(TextEquals("hello", ignore_case=True)) # hello - i18n key (hello, привет)
async def on_hello(msg: Message, _: Translator):
await msg.reply(_.hello_answer(user=msg.from_user.first_name))
bot.run_forever(skip_updates=True)
License
Fluent Telegrinder is MIT licensed.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fluent_telegrinder-1.1.0.tar.gz.
File metadata
- Download URL: fluent_telegrinder-1.1.0.tar.gz
- Upload date:
- Size: 8.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9a187b7681543f8b9ca8e3e15fb76cf829725cd4c03c31644c7c6598471f8641
|
|
| MD5 |
5604d6988a5d451015b0704fdcd595f5
|
|
| BLAKE2b-256 |
8f7f901c99f6bd322b440afede2acf43e3814eb8e93b233b724e5e923aec607d
|
File details
Details for the file fluent_telegrinder-1.1.0-py3-none-any.whl.
File metadata
- Download URL: fluent_telegrinder-1.1.0-py3-none-any.whl
- Upload date:
- Size: 9.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bb85dda711677d16b5d6293bf8df9fe5ddad136c244b5a78a3bf9c8aa98b470d
|
|
| MD5 |
fcc12a9b2dc9d7d918bd3b6d0a8f8d73
|
|
| BLAKE2b-256 |
15f0f1635c8fe22e9062d2cccfd94668ee2d213f94b69b50c7bf8ce97ede062c
|