Two languages
The build writes every page twice: the English page next to the assets folder (index.html) and its Indonesian twin in the id/ folder (id/index.html). Both use the same CSS, scripts and images.
Four layers take part in a translation:
| Layer | How it is translated |
|---|---|
| Text in the HTML | At build time, from the dictionary i18n/id.json. |
| Text written by scripts | In the browser, with _t(text, values) and _tn(n, one, other). |
| Numbers, money, dates | In the browser, with the shared formatter window.slFmt. |
| Demo data | Each app has its own Indonesian sample data and saves it separately. |
The language switch
The ID button in the top bar (EN on Indonesian pages) opens the same page in the other language and keeps the query string and the #hash, so a filtered list or an open tab stays where it was.
- The button is part of the admin layout: dashboards, apps, UI Kit pages and this documentation. Pages without the admin top bar — sign in, error pages and the storefront — have no button; open their
id/version directly. - A click also stores the chosen language in
localStorageunder the keysl-lang(enorid). The template does not read this value itself — it is there for your own code, for example a start page that sends returning visitors to their language. - Scripts learn the page language from
<html lang="…">. The build sets it toidon the Indonesian pages.
How page text is translated
You write the pages in src/pages/ in English only. When you run node build.mjs, the build looks up each piece of visible text — and attributes such as placeholder, title, alt and aria-label — in i18n/id.json and writes the Indonesian page with the translation in its place.
- The key is the English text itself, exactly as it appears on the page, with runs of spaces counted as one. There are no key names to invent.
- Inline elements stay in the sentence. When a sentence contains inline tags such as
strong,em,codeorkbd, the whole sentence is one key and each inline element becomes a numbered marker, so the translation can put them in a different order. An inline element without letters, such as an icon or a bare number, splits the sentence into separate keys instead. - One page can differ. A key that starts with
@page-name|(the file name without.html) applies to that page only and wins over the shared entry. - Same text in both languages. An entry whose value equals its key (a product name, a brand) marks text that stays as it is.
- Code samples are left alone, apart from text that exactly matches a dictionary key, so a sample still matches the live example above it.
{
"Close shift": "Tutup shift",
"Drag cards, or use {0}Alt{/0} + arrow keys": "Seret kartu, atau pakai {0}Alt{/0} + tombol panah",
"Delivery": "Antar",
"@ecommerce-order|Delivery": "Pengiriman",
"Kanban": "Kanban"
} Figures without letters need no entry: the build rewrites them the way Indonesian writes numbers.
5,717 → 5.717
+12.4% → +12,4%
10:32 → 10.32
$8,800.00 → Rp8.800 The automatic rewrite only changes the separators and the currency sign — it does not convert dollars to rupiah. For a fixed amount written in the HTML, add a dictionary entry with a realistic rupiah value.
Text written by scripts
Text that a script puts on the page goes through window.slI18n. Page scripts usually start with two short aliases:
var _t = window.slI18n.t, _tn = window.slI18n.tn;
// a sentence with a value: {name} is filled in after translating
el.textContent = _t('Viewed by {name}', { name: 'Dewi' });
// a count: English needs two forms, the dictionary maps both to one Indonesian form
label.textContent = _tn(count, '{n} invoice', '{n} invoices');
// a word with two meanings: the prefix before | is a context, English shows only the text after it
chip.textContent = _t('status|Void'); - On the English pages
_t(text, values)returns the English text with the values filled in, so the English behavior never depends on the dictionary. - The Indonesian pages load
assets/i18n/id.jsbeforeselaras.js. The build generates that file fromi18n/id.json— edit the JSON, never the generated file. - Context keys (
status|Void,cat|Home) are for script text. In the HTML, use a page-specific key instead.
Numbers, money and dates
All formatting goes through window.slFmt, which reads the page language. English pages show dollars with cents and a 12-hour clock; Indonesian pages show rupiah without decimals and a 24-hour clock.
var F = window.slFmt;
F.money(1250); // '$1,250.00' Indonesian: 'Rp1.250'
F.num(5717); // '5,717' Indonesian: '5.717'
F.pct(12.4, 1); // '12.4%' Indonesian: '12,4%'
F.date('2026-09-23'); // 'Sep 23, 2026' Indonesian: '23 Sep 2026'
F.clock('2026-09-23T14:00'); // '2:00 PM' Indonesian: '14.00'
F.parse('25,000'); // 25000 — on Indonesian pages type '25.000' | Function | Use it for |
|---|---|
money, moneyShort, bigMoney | Amounts, short amounts for chart axes, and large amounts split into number and unit for a KPI. |
num, int, pct | Numbers, whole numbers with a real minus sign, and percentages. |
date, short, dayDate, monthYear, span | Dates from an ISO string or a Date, with or without the year or weekday, and date ranges. |
time, clock, clockRange, hour | Times and time ranges. |
parse, loose | Reading a typed amount back into a number. parse returns null for an empty field and NaN for text that is not an amount. |
The bundled libraries follow the page language too: the page scripts give the charts, the calendar, the date pickers and the other UI Kit libraries Indonesian month names, labels and number formats.
Demo data and saved data
- The Indonesian demo has its own sample data. Amounts are scaled to realistic rupiah prices rather than converted at an exchange rate, and where it fits the apps use Indonesian customer names and addresses, local couriers and 11% VAT (PPN).
- Saved data is kept per language. On the Indonesian pages a storage key gets the suffix
@id—sl-shop-ordersbecomessl-shop-orders@id— so changes in one language never overwrite the other. Usewindow.slI18n.key('sl-my-app')to get the right key for your own app.
Add or change a translation
- Write new text in English as usual: in the HTML of
src/pages/, or wrapped in_t('Your text')in a script. - Run
node build.mjs. Every text that still has no Indonesian entry is listed ini18n/missing-id.txt, one per line: the text, a tab, and the pages it appears on. - Add the translations. Either edit
i18n/id.jsondirectly, or write a two-column file (English, a tab, Indonesian) and add it in one go — a single equals sign as the value means "same as the English text":The script never overwrites an existing entry with a different translation; it reports the clash instead. To change a translation, editpython tools/i18n/add-translations.py my-translations.tsvi18n/id.json; for a word that needs two translations, use a page-specific or context key. - Rebuild and check the Indonesian page.
Two more helpers in tools/i18n/ (Python 3):
missing-keys.pylists the keys still missing for the pages and script files you name — the HTML text fromi18n/missing-id.txtplus the text of every_t(text)and_tn(n, one, other)call in the scripts:python tools/i18n/missing-keys.py app-kanban kanban.jswrap-strings.pywraps the text inside HTML strings of a script file in_t(text)calls. It only prints the changes unless you add--write.
The English text is the key, so editing a sentence in the source leaves its old translation unused. The new sentence shows up in i18n/missing-id.txt until you add its translation.
Use only one language
Build a single language with the --lang option:
node build.mjs --lang en This writes only the English pages and skips the dictionary. The build does not delete pages it built earlier, so remove the id/ folder yourself if you do not ship it, and remove the language link (the element with data-sl-lang-switch) from the top bar in src/layout.html.
The documentation’s own dictionary
These documentation pages are translated the same way, from a separate dictionary: i18n/docs-id.json. On docs-* pages the build looks there first and falls back to i18n/id.json. Keeping the long prose apart means it is not loaded on every app page through assets/i18n/id.js.
To add documentation translations from a file, pass --docs:
python tools/i18n/add-translations.py --docs my-docs-translations.tsv If you do not ship the documentation, delete the docs-*.html files from src/pages/ and the built folders, and remove the Help center link in src/layout.html.
Adding a third language
Selaras is built for exactly two languages, English and Indonesian. A third language is possible, but it is a code change in several places, not a setting:
build.mjs—LANGSlists the languages to build, andDICTandDOCSload only the Indonesian dictionaries. The output folderid, thelangattribute, the language link and the generatedassets/i18n/id.jsare written specifically for Indonesian intoIndonesian, andautoFigrewrites figures in the Indonesian format. Each needs a version for the new language and its own output folder.assets/js/selaras.js— the page language is detected as eitherenorid, andLOCALESholds the month and day names, currency, decimals and date order for those two. Add a locale for the new language and extend the detection.- The language switch toggles between two folders. With three languages it becomes a menu in
src/layout.htmlplus a matching click handler inselaras.js. - Page scripts — the demo data and the library settings (charts, calendar, pickers) check for Indonesian. A new language falls back to the English data and settings until you add its own.