Bash.tv → GitHub → itch.io

Multiple languages and translated interfaces for browser games. A tested i18n module with string tables, {name} placeholders, plurals for every language through Intl.PluralRules (Polish, Arabic, Russian forms), fallback to the base language, picking the player's browser language, number and date formats, missing-key reports, right-to-left detection, and canvas text that shrinks and wraps to fit...

Download skill (.zip) Files on GitHub

Game localization

Plan for it early: no text in code or images, only keys. Adding a language later is then just a new file.

assets/i18n.js

import { createI18n, fitText, checkTables } from "./i18n.js";
import en from "./lang/en.js"; import es from "./lang/es.js";
const i18n = createI18n({ base: "en", tables: { en, es }, lang: settings.get("language"), onMissing: (key, lang) => console.warn("missing", lang, key) });
const t = i18n.t;
t("menu.play"); t("hud.coins", { count: 3 }); t("greet", { name });   i18n.number(12345); i18n.setLang("es")
// en.js: export default { "language.name": "English", menu: { play: "Play" }, hud: { coins: { one: "{count} coin", other: "{count} coins" } }, greet: "Hi {name}!" }

Text that fits

German and Finnish run ~30% longer than English, Chinese and Japanese shorter but taller. On canvas:

const f = fitText(ctx, t("menu.settings"), 360, { size: 24, minSize: 14, maxLines: 2 }); ctx.font = f.font; f.lines.forEach(...)

It shrinks the font, then wraps (per word, or per character for Chinese and Japanese). Design buttons with room to grow; in HTML, let buttons grow and test with the longest language.

Check tables

const report = checkTables({ en, es, de });   // { es: { missing, extra, placeholders, plurals }, ... }

Run it in a test (node) before every release. A placeholder mismatch ({name} dropped) is a bug.

More rules

Tested

Node tests: browser language pick, Spanish plurals and number format, placeholders, fallback with a report, unknown keys, Polish plural forms, unsupported language, RTL, language names, text fitting and per-character wrapping, the table checker. Used in the UI kit demo (English and Spanish, switching at runtime).

Pitfalls

Text in images, string concatenation, a font without accents, buttons sized for English, forgetting plural forms, and dates or numbers formatted by hand.