Skip to content

gzttech/pyi18next

Repository files navigation

pyi18next

Documentation Status

A Python implementation of i18next. Documentation is available at pyi18next.readthedocs.io.

Quick Start

Install

python -m pip install -U pyi18next

Init

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'
)

Translate

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'

About

A Python implementation of i18next

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages