A Python implementation of i18next. Documentation is available at pyi18next.readthedocs.io.
python -m pip install -U pyi18next
We can define a I18next
object with translations loaded as follow:
import pyi18next.i18next
i18n = pyi18next.i18next.I18next(
resources={
'en': {
'translation': {
'key': 'value',
'interpolation': 'Hello, {{name}}!',
'nested': '$t(key)',
}
}
},
default_lng='en',
default_ns='translation'
)
We can use the i18n
object we defined to translate:
print(f'{i18n.t("key")=}')
print(f'{i18n.t("interpolation", name="world")=}')
print(f'{i18n.t("nested")=}')
The results are:
i18n.t("key")='value'
i18n.t("interpolation", name="world")='Hello, world!'
i18n.t("nested")='value'