| 1 | from pytermgui import tim |
| 2 | |
| 3 | LANGUAGE = "en" |
| 4 | |
| 5 | TRANSLATIONS = { |
| 6 | "welcome": { |
| 7 | "en": "Welcome to the documentation", |
| 8 | "hu": "Üdv a dokumentációban", |
| 9 | } |
| 10 | } |
| 11 | |
| 12 | |
| 13 | def macro_lang(key: str) -> str: |
| 14 | translation = TRANSLATIONS.get(key) |
| 15 | |
| 16 | if translation is None: |
| 17 | return key |
| 18 | |
| 19 | return translation[LANGUAGE] |
| 20 | |
| 21 | |
| 22 | tim.define("!lang", macro_lang) |
| 23 | |
| 24 | for LANGUAGE in ["en", "hu"]: |
| 25 | tim.clear_cache() |
| 26 | |
| 27 | tim.print(f"[bold]LANGUAGE: [/ 157]{LANGUAGE!r}") |
| 28 | tim.print("--> [!lang]welcome[/!lang]") |
| 29 | tim.print() |