ECOSYSTEM / I18N

Formats and writing direction

Numbers, currency and dates in the rules of the active language, and interfaces that mirror from right to left.

Ecosystem package janelkit-i18n Translation catalogs, plurals, locale-aware number, currency and date formats, and language switching at run time. pip install janelkit-i18n
I18N · PAGE 3 / 4~1 min read
Alpha / 0.2 — These pages document JanelKit 0.2 and its packages. Each series (0.1, 0.2…) may change the public API, always with migration notes: see Changes and migration. The website uses Svelte; the desktop examples use Python and JanelKit, not JavaScript.

Format with the rules of the language

The formatting helpers follow the active language through Qt’s QLocale, and they are reactive in templates like t. number(x, decimals) groups thousands and uses the right decimal mark, currency(x, symbol) places the symbol where the language expects it, and date(value, "short" | "long") writes a date or a datetime.

janel
<!-- Partial template; the script imports i18n and t from janelkit_i18n,
     and defines total, price and today. -->
<text>{i18n.number(total, 2)} · {i18n.currency(price, "€")} · {i18n.date(today, "long")}</text>
Copy

Fragment · Add it to an existing component; it is not a complete file.

Right-to-left languages

When the active language is written from right to left, such as Arabic, Hebrew or Persian, the whole interface mirrors: rows, text alignment and the indicators of the controls. You do not write anything for it. i18n.rtl, the same as janelkit.locale.rtl, tells you whether the active language is one of them, for the rare case where your own drawing must change.

janel
<!-- Partial template: a button that switches to Arabic. -->
<button on:click={i18n.set("ar")}>العربية</button>
Copy

Fragment · Add it to an existing component; it is not a complete file.

Learn morePython API reference ↗

A complete example

apps/examples/idiomas, in the JanelKit repository, switches between Spanish, English and Arabic while running, with plurals, formats and a mirrored layout.

English documentation based on the JanelKit source. For additional details, browse the source docs ↗.