ECOSYSTEM / I18N

janelkit-i18n

Translate your interface with JSON catalogs, plurals and locale-aware formats, and switch language while the application runs.

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 1 / 4~2 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.

What it adds

janelkit-i18n translates the text of your interface. You write one catalog per language, call t("key") in templates, and switch language while the application runs: every translated text updates without a restart. It also formats numbers, currency and dates following the rules of the active language.

The interface language itself belongs to the core (janelkit.locale), because it controls the writing direction of every element. In Arabic, Hebrew or Persian the whole interface mirrors. i18n.set checks that a catalog exists and then changes that core language.

In one minute

Install it next to janelkit with pip install janelkit-i18n. This component adds two small catalogs from Python and switches between them. A real application keeps its catalogs in JSON files and loads them with i18n.load, as the next page shows.

janel
<script lang="python">
from janelkit import state
from janelkit_i18n import i18n, t

i18n.add("en", {"hello": "Hello, {name}", "files": {"zero": "No files", "one": "{n} file", "other": "{n} files"}})
i18n.add("es", {"hello": "Hola, {name}", "files": {"zero": "Ningún archivo", "one": "{n} archivo", "other": "{n} archivos"}})
i18n.default = "en"
i18n.set("en")

count = state(0)

def switch():
    i18n.set("es" if i18n.language == "en" else "en")
</script>

<column padding={24} gap={12}>
  <text>{t("hello", name="Ada")}</text>
  <text>{t("files", n=count)}</text>
  <row gap={8}>
    <button on:click={count += 1}>Add a file</button>
    <button on:click={switch}>Switch language</button>
  </row>
</column>
Copy

Complete component · Save as src/App.janel in a scaffolded project.

How it works

  1. add registers a catalog from a dictionary; load does the same from a folder of JSON files.
  2. t is reactive: it reads the active language, so every text updates when set changes it.
  3. files is a plural entry: n chooses zero, one or other.

What you should see

Hello, Ada and No files. Add a file shows 1 file, then 2 files. Switch language shows Hola, Ada and 2 archivos.

Built on the public API

janelkit-i18n depends on nothing internal to the core; a repository test checks it. The language and the writing direction come from janelkit.locale, which is public, and t is reactive because it reads it.

Learn moreBuild your own package ↗

Versions and changes

janelkit-i18n shares the series with the core: 0.2.x.x works with janelkit 0.2.x.x, and 0.1.x with janelkit 0.1.x, both with Python 3.10 or later.

0.2.0.0 joins the 0.2 series; its API does not change. In 0.1.0 translations left the core: change from janelkit import t, i18n to from janelkit_i18n import t, i18n.

Learn moreChanges and migration ↗

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