Add Persian viewer and tutorial translations

This commit is contained in:
coyotte508 2026-09-27 00:52:38 +02:00
commit d46c69fd0e
23 changed files with 1705 additions and 17 deletions

View file

@ -1,6 +1,6 @@
# Viewer translations
The viewer follows BGS's shared `preferences.locale` value. Tutorials receive `options.locale`. Supported locales match BGS: English, German, French, Polish, Romanian, Greek, Hindi, Russian, Danish, Brazilian Portuguese, Korean, Traditional Chinese, Vietnamese, Italian and Dutch.
The viewer follows BGS's shared `preferences.locale` value. Tutorials receive `options.locale`. Supported locales match BGS: English, German, French, Polish, Romanian, Greek, Hindi, Russian, Danish, Brazilian Portuguese, Korean, Traditional Chinese, Vietnamese, Italian, Dutch and Persian (`fa`, including `fa-IR`).
`en.json` contains source UI text, including tutorial explanations and engine-generated descriptions rendered by the viewer. The other catalogues use the same keys. `{p0}`, `{p1}`, etc. represent dynamic display values: translators may reorder them but must preserve every placeholder. Add or update the corresponding entries in all catalogues when changing source wording. Component names and terminology need game-specific review; translations were initially machine-assisted.
@ -9,3 +9,5 @@ The rendering adapter translates text and accessible labels, including tooltips,
For rich text that is split into icons and spans, call `translateText` on the complete sentence before splitting it; localize the tokenizer's resource labels too. This preserves sentence grammar. Avoid relying on rendered labels to identify an action—use action IDs or data attributes.
Run `node scripts/check-locales.mjs packages/viewer/src/localization` to verify catalogue coverage and placeholders. The viewer's normal build and browser tests should also cover language switching, action controls, translated tutorial progression and narrow layouts. Browser text must remain readable if a translation is missing; English is the fallback.
Persian translations are authored directly, without a translation API. Equipment, skill and terrain names use consistent Persian terms in instructions and controls. Proper names, technical selectors, SVG paths and extracted code snippets retain their source spelling. Scoped RTL styles apply to prose and controls; the map, explorer positions and dice order stay LTR so spatial tutorial instructions remain accurate. Run `node tests/persian-browser.mjs` after building to exercise Persian lessons and layout at phone and desktop widths.

View file

@ -1273,5 +1273,19 @@
"{p0} steps": "{p0} felter",
"Eruption: entering or crossing triggers {p0} extra eruption. One-time trigger.": "Udbrud: når feltet betrædes eller passeres, udløses {p0} ekstra udbrud. Kun én gang.",
"Eruption: entering or crossing triggers {p0} extra eruptions. One-time trigger.": "Udbrud: når feltet betrædes eller passeres, udløses {p0} ekstra udbrud. Kun én gang.",
"{p0} · {p1}": "{p0} · {p1}"
"{p0} · {p1}": "{p0} · {p1}",
"Change dice": "Change dice",
"Keep dice": "Keep dice",
"Set die aside · free": "Set die aside · free",
"Select 1 die to set aside": "Select 1 die to set aside",
"✓ Die set aside": "✓ Die set aside",
"Select dice ↑": "Select dice ↑",
"Choose on map ↑": "Choose on map ↑",
"Zoom in on the map": "Zoom in on the map",
"Show the whole map": "Show the whole map",
"+{p0} bar if kept": "+{p0} bar if kept",
"+{p0} bars if kept": "+{p0} bars if kept",
"· gain {p0} bar": "· gain {p0} bar",
"{p0} · +{p1} bar if kept": "{p0} · +{p1} bar if kept",
"{p0} · +{p1} bars if kept": "{p0} · +{p1} bars if kept"
}

View file

@ -1273,5 +1273,19 @@
"{p0} steps": "{p0} Felder",
"Eruption: entering or crossing triggers {p0} extra eruption. One-time trigger.": "Eruption: Betreten oder Überqueren löst einmalig {p0} zusätzliche Eruption aus.",
"Eruption: entering or crossing triggers {p0} extra eruptions. One-time trigger.": "Eruption: Betreten oder Überqueren löst einmalig {p0} zusätzliche Eruptionen aus.",
"{p0} · {p1}": "{p0} · {p1}"
"{p0} · {p1}": "{p0} · {p1}",
"Change dice": "Change dice",
"Keep dice": "Keep dice",
"Set die aside · free": "Set die aside · free",
"Select 1 die to set aside": "Select 1 die to set aside",
"✓ Die set aside": "✓ Die set aside",
"Select dice ↑": "Select dice ↑",
"Choose on map ↑": "Choose on map ↑",
"Zoom in on the map": "Zoom in on the map",
"Show the whole map": "Show the whole map",
"+{p0} bar if kept": "+{p0} bar if kept",
"+{p0} bars if kept": "+{p0} bars if kept",
"· gain {p0} bar": "· gain {p0} bar",
"{p0} · +{p1} bar if kept": "{p0} · +{p1} bar if kept",
"{p0} · +{p1} bars if kept": "{p0} · +{p1} bars if kept"
}

View file

@ -1273,5 +1273,19 @@
"{p0} steps": "{p0} θέσεις",
"Eruption: entering or crossing triggers {p0} extra eruption. One-time trigger.": "Έκρηξη: η είσοδος ή η διέλευση προκαλεί {p0} επιπλέον έκρηξη. Μόνο μία ενεργοποίηση.",
"Eruption: entering or crossing triggers {p0} extra eruptions. One-time trigger.": "Έκρηξη: η είσοδος ή η διέλευση προκαλεί {p0} επιπλέον εκρήξεις. Μόνο μία ενεργοποίηση.",
"{p0} · {p1}": "{p0} · {p1}"
"{p0} · {p1}": "{p0} · {p1}",
"Change dice": "Change dice",
"Keep dice": "Keep dice",
"Set die aside · free": "Set die aside · free",
"Select 1 die to set aside": "Select 1 die to set aside",
"✓ Die set aside": "✓ Die set aside",
"Select dice ↑": "Select dice ↑",
"Choose on map ↑": "Choose on map ↑",
"Zoom in on the map": "Zoom in on the map",
"Show the whole map": "Show the whole map",
"+{p0} bar if kept": "+{p0} bar if kept",
"+{p0} bars if kept": "+{p0} bars if kept",
"· gain {p0} bar": "· gain {p0} bar",
"{p0} · +{p1} bar if kept": "{p0} · +{p1} bar if kept",
"{p0} · +{p1} bars if kept": "{p0} · +{p1} bars if kept"
}

View file

@ -1273,5 +1273,19 @@
"{p0} steps": "{p0} steps",
"Eruption: entering or crossing triggers {p0} extra eruption. One-time trigger.": "Eruption: entering or crossing triggers {p0} extra eruption. One-time trigger.",
"Eruption: entering or crossing triggers {p0} extra eruptions. One-time trigger.": "Eruption: entering or crossing triggers {p0} extra eruptions. One-time trigger.",
"{p0} · {p1}": "{p0} · {p1}"
"{p0} · {p1}": "{p0} · {p1}",
"Change dice": "Change dice",
"Keep dice": "Keep dice",
"Set die aside · free": "Set die aside · free",
"Select 1 die to set aside": "Select 1 die to set aside",
"✓ Die set aside": "✓ Die set aside",
"Select dice ↑": "Select dice ↑",
"Choose on map ↑": "Choose on map ↑",
"Zoom in on the map": "Zoom in on the map",
"Show the whole map": "Show the whole map",
"+{p0} bar if kept": "+{p0} bar if kept",
"+{p0} bars if kept": "+{p0} bars if kept",
"· gain {p0} bar": "· gain {p0} bar",
"{p0} · +{p1} bar if kept": "{p0} · +{p1} bar if kept",
"{p0} · +{p1} bars if kept": "{p0} · +{p1} bars if kept"
}

File diff suppressed because it is too large Load diff

View file

@ -1273,5 +1273,19 @@
"{p0} steps": "{p0} cases",
"Eruption: entering or crossing triggers {p0} extra eruption. One-time trigger.": "Éruption : entrer ou traverser déclenche {p0} éruption supplémentaire. Une seule fois.",
"Eruption: entering or crossing triggers {p0} extra eruptions. One-time trigger.": "Éruption : entrer ou traverser déclenche {p0} éruptions supplémentaires. Une seule fois.",
"{p0} · {p1}": "{p0} · {p1}"
"{p0} · {p1}": "{p0} · {p1}",
"Change dice": "Change dice",
"Keep dice": "Keep dice",
"Set die aside · free": "Set die aside · free",
"Select 1 die to set aside": "Select 1 die to set aside",
"✓ Die set aside": "✓ Die set aside",
"Select dice ↑": "Select dice ↑",
"Choose on map ↑": "Choose on map ↑",
"Zoom in on the map": "Zoom in on the map",
"Show the whole map": "Show the whole map",
"+{p0} bar if kept": "+{p0} bar if kept",
"+{p0} bars if kept": "+{p0} bars if kept",
"· gain {p0} bar": "· gain {p0} bar",
"{p0} · +{p1} bar if kept": "{p0} · +{p1} bar if kept",
"{p0} · +{p1} bars if kept": "{p0} · +{p1} bars if kept"
}

View file

@ -1273,5 +1273,19 @@
"{p0} steps": "{p0} खाने",
"Eruption: entering or crossing triggers {p0} extra eruption. One-time trigger.": "विस्फोट: यहाँ आने या यहाँ से गुज़रने पर {p0} अतिरिक्त विस्फोट होता है। केवल एक बार सक्रिय होता है।",
"Eruption: entering or crossing triggers {p0} extra eruptions. One-time trigger.": "विस्फोट: यहाँ आने या यहाँ से गुज़रने पर {p0} अतिरिक्त विस्फोट होते हैं। केवल एक बार सक्रिय होता है।",
"{p0} · {p1}": "{p0} · {p1}"
"{p0} · {p1}": "{p0} · {p1}",
"Change dice": "Change dice",
"Keep dice": "Keep dice",
"Set die aside · free": "Set die aside · free",
"Select 1 die to set aside": "Select 1 die to set aside",
"✓ Die set aside": "✓ Die set aside",
"Select dice ↑": "Select dice ↑",
"Choose on map ↑": "Choose on map ↑",
"Zoom in on the map": "Zoom in on the map",
"Show the whole map": "Show the whole map",
"+{p0} bar if kept": "+{p0} bar if kept",
"+{p0} bars if kept": "+{p0} bars if kept",
"· gain {p0} bar": "· gain {p0} bar",
"{p0} · +{p1} bar if kept": "{p0} · +{p1} bar if kept",
"{p0} · +{p1} bars if kept": "{p0} · +{p1} bars if kept"
}

View file

@ -13,6 +13,8 @@ import catalog11 from "./zh-TW.json";
import catalog12 from "./vi.json";
import catalog13 from "./it.json";
import catalog14 from "./nl.json";
import catalog15 from "./fa.json";
import "./rtl.css";
import { mountLocalization as mount, createTranslator } from "./runtime.js";
export { languages, resolveLocale } from "./runtime.js";
export const catalogs = {
@ -31,6 +33,7 @@ export const catalogs = {
vi: catalog12,
it: catalog13,
nl: catalog14,
fa: catalog15,
};
const translators = new Map();
export function translateText(text, locale = "en") {

View file

@ -1273,5 +1273,19 @@
"{p0} steps": "{p0} caselle",
"Eruption: entering or crossing triggers {p0} extra eruption. One-time trigger.": "Eruzione: entrare o passare qui provoca {p0} eruzione aggiuntiva. Si attiva una sola volta.",
"Eruption: entering or crossing triggers {p0} extra eruptions. One-time trigger.": "Eruzione: entrare o passare qui provoca {p0} eruzioni aggiuntive. Si attiva una sola volta.",
"{p0} · {p1}": "{p0} · {p1}"
"{p0} · {p1}": "{p0} · {p1}",
"Change dice": "Change dice",
"Keep dice": "Keep dice",
"Set die aside · free": "Set die aside · free",
"Select 1 die to set aside": "Select 1 die to set aside",
"✓ Die set aside": "✓ Die set aside",
"Select dice ↑": "Select dice ↑",
"Choose on map ↑": "Choose on map ↑",
"Zoom in on the map": "Zoom in on the map",
"Show the whole map": "Show the whole map",
"+{p0} bar if kept": "+{p0} bar if kept",
"+{p0} bars if kept": "+{p0} bars if kept",
"· gain {p0} bar": "· gain {p0} bar",
"{p0} · +{p1} bar if kept": "{p0} · +{p1} bar if kept",
"{p0} · +{p1} bars if kept": "{p0} · +{p1} bars if kept"
}

View file

@ -1273,5 +1273,19 @@
"{p0} steps": "{p0}칸",
"Eruption: entering or crossing triggers {p0} extra eruption. One-time trigger.": "분출: 진입하거나 통과하면 추가 분출이 {p0}회 발생합니다. 한 번만 발동합니다.",
"Eruption: entering or crossing triggers {p0} extra eruptions. One-time trigger.": "분출: 진입하거나 통과하면 추가 분출이 {p0}회 발생합니다. 한 번만 발동합니다.",
"{p0} · {p1}": "{p0} · {p1}"
"{p0} · {p1}": "{p0} · {p1}",
"Change dice": "Change dice",
"Keep dice": "Keep dice",
"Set die aside · free": "Set die aside · free",
"Select 1 die to set aside": "Select 1 die to set aside",
"✓ Die set aside": "✓ Die set aside",
"Select dice ↑": "Select dice ↑",
"Choose on map ↑": "Choose on map ↑",
"Zoom in on the map": "Zoom in on the map",
"Show the whole map": "Show the whole map",
"+{p0} bar if kept": "+{p0} bar if kept",
"+{p0} bars if kept": "+{p0} bars if kept",
"· gain {p0} bar": "· gain {p0} bar",
"{p0} · +{p1} bar if kept": "{p0} · +{p1} bar if kept",
"{p0} · +{p1} bars if kept": "{p0} · +{p1} bars if kept"
}

View file

@ -1273,5 +1273,19 @@
"{p0} steps": "{p0} vakken",
"Eruption: entering or crossing triggers {p0} extra eruption. One-time trigger.": "Uitbarsting: betreden of passeren veroorzaakt eenmalig {p0} extra uitbarsting.",
"Eruption: entering or crossing triggers {p0} extra eruptions. One-time trigger.": "Uitbarsting: betreden of passeren veroorzaakt eenmalig {p0} extra uitbarstingen.",
"{p0} · {p1}": "{p0} · {p1}"
"{p0} · {p1}": "{p0} · {p1}",
"Change dice": "Change dice",
"Keep dice": "Keep dice",
"Set die aside · free": "Set die aside · free",
"Select 1 die to set aside": "Select 1 die to set aside",
"✓ Die set aside": "✓ Die set aside",
"Select dice ↑": "Select dice ↑",
"Choose on map ↑": "Choose on map ↑",
"Zoom in on the map": "Zoom in on the map",
"Show the whole map": "Show the whole map",
"+{p0} bar if kept": "+{p0} bar if kept",
"+{p0} bars if kept": "+{p0} bars if kept",
"· gain {p0} bar": "· gain {p0} bar",
"{p0} · +{p1} bar if kept": "{p0} · +{p1} bar if kept",
"{p0} · +{p1} bars if kept": "{p0} · +{p1} bars if kept"
}

View file

@ -1273,5 +1273,19 @@
"{p0} steps": "Liczba pól: {p0}",
"Eruption: entering or crossing triggers {p0} extra eruption. One-time trigger.": "Erupcja: wejście lub przejście wywołuje dodatkową erupcję. Liczba: {p0}. Tylko raz.",
"Eruption: entering or crossing triggers {p0} extra eruptions. One-time trigger.": "Erupcja: wejście lub przejście wywołuje dodatkowe erupcje. Liczba: {p0}. Tylko raz.",
"{p0} · {p1}": "{p0} · {p1}"
"{p0} · {p1}": "{p0} · {p1}",
"Change dice": "Change dice",
"Keep dice": "Keep dice",
"Set die aside · free": "Set die aside · free",
"Select 1 die to set aside": "Select 1 die to set aside",
"✓ Die set aside": "✓ Die set aside",
"Select dice ↑": "Select dice ↑",
"Choose on map ↑": "Choose on map ↑",
"Zoom in on the map": "Zoom in on the map",
"Show the whole map": "Show the whole map",
"+{p0} bar if kept": "+{p0} bar if kept",
"+{p0} bars if kept": "+{p0} bars if kept",
"· gain {p0} bar": "· gain {p0} bar",
"{p0} · +{p1} bar if kept": "{p0} · +{p1} bar if kept",
"{p0} · +{p1} bars if kept": "{p0} · +{p1} bars if kept"
}

View file

@ -1273,5 +1273,19 @@
"{p0} steps": "{p0} espaços",
"Eruption: entering or crossing triggers {p0} extra eruption. One-time trigger.": "Erupção: entrar ou passar aqui provoca {p0} erupção extra. Ativa uma única vez.",
"Eruption: entering or crossing triggers {p0} extra eruptions. One-time trigger.": "Erupção: entrar ou passar aqui provoca {p0} erupções extras. Ativa uma única vez.",
"{p0} · {p1}": "{p0} · {p1}"
"{p0} · {p1}": "{p0} · {p1}",
"Change dice": "Change dice",
"Keep dice": "Keep dice",
"Set die aside · free": "Set die aside · free",
"Select 1 die to set aside": "Select 1 die to set aside",
"✓ Die set aside": "✓ Die set aside",
"Select dice ↑": "Select dice ↑",
"Choose on map ↑": "Choose on map ↑",
"Zoom in on the map": "Zoom in on the map",
"Show the whole map": "Show the whole map",
"+{p0} bar if kept": "+{p0} bar if kept",
"+{p0} bars if kept": "+{p0} bars if kept",
"· gain {p0} bar": "· gain {p0} bar",
"{p0} · +{p1} bar if kept": "{p0} · +{p1} bar if kept",
"{p0} · +{p1} bars if kept": "{p0} · +{p1} bars if kept"
}

View file

@ -1273,5 +1273,19 @@
"{p0} steps": "{p0} spații",
"Eruption: entering or crossing triggers {p0} extra eruption. One-time trigger.": "Erupție: intrarea sau trecerea pe aici declanșează {p0} erupție suplimentară. O singură activare.",
"Eruption: entering or crossing triggers {p0} extra eruptions. One-time trigger.": "Erupție: intrarea sau trecerea pe aici declanșează {p0} erupții suplimentare. O singură activare.",
"{p0} · {p1}": "{p0} · {p1}"
"{p0} · {p1}": "{p0} · {p1}",
"Change dice": "Change dice",
"Keep dice": "Keep dice",
"Set die aside · free": "Set die aside · free",
"Select 1 die to set aside": "Select 1 die to set aside",
"✓ Die set aside": "✓ Die set aside",
"Select dice ↑": "Select dice ↑",
"Choose on map ↑": "Choose on map ↑",
"Zoom in on the map": "Zoom in on the map",
"Show the whole map": "Show the whole map",
"+{p0} bar if kept": "+{p0} bar if kept",
"+{p0} bars if kept": "+{p0} bars if kept",
"· gain {p0} bar": "· gain {p0} bar",
"{p0} · +{p1} bar if kept": "{p0} · +{p1} bar if kept",
"{p0} · +{p1} bars if kept": "{p0} · +{p1} bars if kept"
}

View file

@ -0,0 +1,41 @@
/* Keep physical map coordinates and left-to-right dice indices stable. */
.expedition:lang(fa),
.landscape:lang(fa),
.map-scroll:lang(fa),
.expedition svg:lang(fa),
.dice-row:lang(fa),
.mini-dice:lang(fa),
.comparison-dice:lang(fa),
.die:lang(fa) {
direction: ltr;
}
.bgs-tutorial-guide:lang(fa),
.expedition p:lang(fa),
.expedition h1:lang(fa),
.expedition h2:lang(fa),
.expedition h3:lang(fa),
.expedition button:not(.die):lang(fa),
.expedition legend:lang(fa),
.instruction:lang(fa),
.location-detail:lang(fa),
.equipment-description:lang(fa),
.equipment-preview:lang(fa),
.journal-entry:lang(fa),
.journal-header:lang(fa),
.modal:lang(fa) {
direction: rtl;
text-align: start;
}
.bgs-tutorial-body p:lang(fa),
.journal-entry:lang(fa),
.instruction:lang(fa) {
unicode-bidi: plaintext;
}
/* Persian status labels need to wrap inside compact teammate cards. */
.ready-label:lang(fa) {
white-space: normal;
overflow-wrap: anywhere;
}

View file

@ -1273,5 +1273,19 @@
"{p0} steps": "Клеток: {p0}",
"Eruption: entering or crossing triggers {p0} extra eruption. One-time trigger.": "Извержение: вход или проход вызывает дополнительное извержение. Количество: {p0}. Срабатывает один раз.",
"Eruption: entering or crossing triggers {p0} extra eruptions. One-time trigger.": "Извержение: вход или проход вызывает дополнительные извержения. Количество: {p0}. Срабатывает один раз.",
"{p0} · {p1}": "{p0} · {p1}"
"{p0} · {p1}": "{p0} · {p1}",
"Change dice": "Change dice",
"Keep dice": "Keep dice",
"Set die aside · free": "Set die aside · free",
"Select 1 die to set aside": "Select 1 die to set aside",
"✓ Die set aside": "✓ Die set aside",
"Select dice ↑": "Select dice ↑",
"Choose on map ↑": "Choose on map ↑",
"Zoom in on the map": "Zoom in on the map",
"Show the whole map": "Show the whole map",
"+{p0} bar if kept": "+{p0} bar if kept",
"+{p0} bars if kept": "+{p0} bars if kept",
"· gain {p0} bar": "· gain {p0} bar",
"{p0} · +{p1} bar if kept": "{p0} · +{p1} bar if kept",
"{p0} · +{p1} bars if kept": "{p0} · +{p1} bars if kept"
}

View file

@ -14,6 +14,7 @@ export const languages = {
vi: "Tiếng Việt",
it: "Italiano",
nl: "Nederlands",
fa: "فارسی",
};
export function resolveLocale(value) {

View file

@ -1273,5 +1273,19 @@
"{p0} steps": "{p0} ô",
"Eruption: entering or crossing triggers {p0} extra eruption. One-time trigger.": "Phun trào: vào hoặc đi qua đây gây thêm {p0} đợt phun trào. Chỉ kích hoạt một lần.",
"Eruption: entering or crossing triggers {p0} extra eruptions. One-time trigger.": "Phun trào: vào hoặc đi qua đây gây thêm {p0} đợt phun trào. Chỉ kích hoạt một lần.",
"{p0} · {p1}": "{p0} · {p1}"
"{p0} · {p1}": "{p0} · {p1}",
"Change dice": "Change dice",
"Keep dice": "Keep dice",
"Set die aside · free": "Set die aside · free",
"Select 1 die to set aside": "Select 1 die to set aside",
"✓ Die set aside": "✓ Die set aside",
"Select dice ↑": "Select dice ↑",
"Choose on map ↑": "Choose on map ↑",
"Zoom in on the map": "Zoom in on the map",
"Show the whole map": "Show the whole map",
"+{p0} bar if kept": "+{p0} bar if kept",
"+{p0} bars if kept": "+{p0} bars if kept",
"· gain {p0} bar": "· gain {p0} bar",
"{p0} · +{p1} bar if kept": "{p0} · +{p1} bar if kept",
"{p0} · +{p1} bars if kept": "{p0} · +{p1} bars if kept"
}

View file

@ -1273,5 +1273,19 @@
"{p0} steps": "{p0} 格",
"Eruption: entering or crossing triggers {p0} extra eruption. One-time trigger.": "噴發:進入或穿過此地會額外噴發 {p0} 次。僅觸發一次。",
"Eruption: entering or crossing triggers {p0} extra eruptions. One-time trigger.": "噴發:進入或穿過此地會額外噴發 {p0} 次。僅觸發一次。",
"{p0} · {p1}": "{p0} · {p1}"
"{p0} · {p1}": "{p0} · {p1}",
"Change dice": "Change dice",
"Keep dice": "Keep dice",
"Set die aside · free": "Set die aside · free",
"Select 1 die to set aside": "Select 1 die to set aside",
"✓ Die set aside": "✓ Die set aside",
"Select dice ↑": "Select dice ↑",
"Choose on map ↑": "Choose on map ↑",
"Zoom in on the map": "Zoom in on the map",
"Show the whole map": "Show the whole map",
"+{p0} bar if kept": "+{p0} bar if kept",
"+{p0} bars if kept": "+{p0} bars if kept",
"· gain {p0} bar": "· gain {p0} bar",
"{p0} · +{p1} bar if kept": "{p0} · +{p1} bar if kept",
"{p0} · +{p1} bars if kept": "{p0} · +{p1} bars if kept"
}

View file

@ -7,7 +7,7 @@ if (!directory) {
}
const source = JSON.parse(await readFile(join(directory, "en.json"), "utf8"));
const placeholders = (text) => [...text.matchAll(/\{\w+\}/g)].map((match) => match[0]).sort();
const locales = ["en", "de", "fr", "pl", "ro", "el", "hi", "ru", "da", "pt-BR", "ko", "zh-TW", "vi", "it", "nl"];
const locales = ["en", "de", "fr", "pl", "ro", "el", "hi", "ru", "da", "pt-BR", "ko", "zh-TW", "vi", "it", "nl", "fa"];
for (const locale of locales) {
const catalog = JSON.parse(await readFile(join(directory, `${locale}.json`), "utf8"));
assert.deepEqual(Object.keys(catalog).sort(), Object.keys(source).sort(), `${locale}: missing or extra strings`);

View file

@ -79,3 +79,23 @@ test("Fuji tutorial headings beat generic fragments and plurals stay whole", asy
const zh = createTranslator(locales, "zh-TW");
assert.equal(zh.translate("Choose 2 of your 3 equipment cards to keep."), "從你的 3 張裝備卡中選擇 2 張保留。");
});
test("Persian uses regional tags and keeps dynamic game values and names intact", async () => {
assert.equal(resolveLocale("fa-IR"), "fa");
assert.equal(resolveLocale("FA_IR"), "fa");
const fa = JSON.parse(
await readFile(new URL("../packages/viewer/src/localization/fa.json", import.meta.url), "utf8")
);
const t = createTranslator({ fa }, "fa-IR");
t.setNames(["Map"]);
assert.equal(t.translate("Map gave Rope to Ren."), "Map وسیلهٔ طناب را به Ren داد.");
assert.equal(t.translate("Use 2 bars · total 18"), "مصرف 2 خوراکی · مجموع 18");
assert.equal(
t.translate("Scenario 3 · Level 2. Everyone must reach a house-marked location."),
"سناریوی 3 · سطح 2. همه باید به مکانی با نشان خانه برسند."
);
assert.equal(t.translate("translate(120,0)"), "translate(120,0)");
assert.equal(t.translate("Map"), "Map");
t.setLocale("en");
assert.equal(t.translate("Use 2 bars · total 18"), "Use 2 bars · total 18");
});

120
tests/persian-browser.mjs Normal file
View file

@ -0,0 +1,120 @@
import assert from "node:assert/strict";
import { createServer } from "node:http";
import { readFile } from "node:fs/promises";
import { chromium } from "playwright";
import { initGame, stripSecret } from "../packages/engine/dist/index.js";
const server = createServer(async (req, res) => {
if (req.url.startsWith("/dist/")) {
res.setHeader("content-type", req.url.endsWith("css") ? "text/css" : "text/javascript; charset=utf-8");
res.end(await readFile(`packages/viewer${req.url}`));
} else {
res.setHeader("content-type", "text/html; charset=utf-8");
res.end(
'<!doctype html><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="stylesheet" href="/dist/fuji-viewer.css"><div id="app"></div><script src="/dist/fuji-viewer.iife.js"></script>'
);
}
});
await new Promise((resolve) => server.listen(0, "127.0.0.1", resolve));
const browser = await chromium.launch({ executablePath: process.env.FUJI_CHROMIUM_EXECUTABLE });
const errors = [];
try {
for (const width of [390, 1440]) {
const page = await browser.newPage({ viewport: { width, height: 1000 }, reducedMotion: "reduce" });
page.on("pageerror", (error) => errors.push(error.message));
await page.goto(`http://127.0.0.1:${server.address().port}`);
for (const chapter of ["first-steps", "equipment", "terrain-bonuses", "lava", "village"]) {
await page.evaluate(async (chapter) => {
await fuji.launchTutorial("#app", { chapter, locale: "fa-IR" });
}, chapter);
await page.getByRole("button", { name: "بازگشت به آغاز", exact: true }).waitFor();
assert.match(await page.locator(".bgs-tutorial-body").innerText(), /[\u0600-\u06ff]/u);
assert.doesNotMatch(await page.locator(".bgs-tutorial-body").innerText(), /Choose |Your |You |Help |Routes /);
assert.equal(await page.locator(".bgs-tutorial-guide").evaluate((el) => getComputedStyle(el).direction), "rtl");
assert.equal(await page.locator("svg.map").evaluate((el) => getComputedStyle(el).direction), "ltr");
assert.ok(
await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth + 1),
`${chapter}: no overflow at ${width}px`
);
}
await page.evaluate(async () => {
localStorage.clear();
await fuji.launchTutorial("#app", { chapter: "first-steps", locale: "fa-IR" });
});
const guide = page.locator(".bgs-tutorial-guide");
const step = (n) =>
page.waitForFunction(
(n) => document.querySelector(".bgs-tutorial-heading strong")?.textContent.startsWith(`${n}/8`),
n
);
await step(1);
await guide.getByRole("button", { name: "ادامه", exact: true }).click();
await step(2);
await page.locator('[data-tutorial="tile:1,3"]').click();
await step(3);
await guide.getByRole("button", { name: "ادامه", exact: true }).click();
await step(4);
await page.locator('[data-tutorial="confirm"]:visible').first().click();
await step(5);
const dice = page.locator(".personal .dice-row .die");
const xs = await dice.evaluateAll((nodes) => nodes.map((el) => el.getBoundingClientRect().x));
assert.ok(
xs.every((x, i) => !i || x > xs[i - 1]),
"Persian keeps dice in original left-to-right order"
);
for (const index of [3, 4, 5]) await dice.nth(index).click();
await page.getByRole("button", { name: /تکرار.*3.*↻/ }).click();
await step(6);
await page.locator(".personal .die.bgs-tutorial-highlight").click();
await page.getByRole("button", { name: "کنار گذاشتن تاس انتخاب‌شده", exact: true }).click();
await step(7);
await page.locator('[data-tutorial="confirm"]:visible').first().click();
await step(8);
await page.locator('[data-tutorial="resolve"]:visible').first().click();
await page.waitForFunction(
() => document.querySelector(".bgs-tutorial-heading strong")?.textContent === "فصل تمام شد"
);
assert.match(await guide.innerText(), /به دیده‌بانی تپه رسیدید/);
const state = initGame(3, { autoMovement: false, autoProgress: false, skillAssignment: "fixed" }, "persian");
state.players[2].name = "Map";
await page.evaluate(
(state) => {
window.bridge = fuji.launch("#app");
bridge.emit("player", { index: 2 });
bridge.emit("state", state);
bridge.emit("preferences", { locale: "en" });
},
stripSecret(state, 2)
);
await page.waitForFunction(() =>
document.querySelector(".expedition")?.textContent.includes("Prepare your expedition")
);
const geometry = () =>
page
.locator("svg.map")
.evaluate((el) =>
[...el.querySelectorAll("path,circle,rect,g")].map((node) =>
["d", "x", "y", "cx", "cy", "transform"].map((a) => node.getAttribute(a))
)
);
const before = await geometry();
await page.evaluate(() => bridge.emit("preferences", { locale: "fa-IR" }));
await page.waitForFunction(() =>
document.querySelector(".expedition")?.textContent.includes("ماجراجویی خود را آماده کنید")
);
assert.deepEqual(await geometry(), before, "Persian leaves map geometry unchanged");
assert.ok(await page.getByText("Map", { exact: true }).count(), "player name remains unchanged");
await page.evaluate(() => bridge.emit("preferences", { locale: "en" }));
await page.waitForFunction(() =>
document.querySelector(".expedition")?.textContent.includes("Prepare your expedition")
);
assert.deepEqual(await geometry(), before);
await page.close();
console.log(`Persian chapters, complete interactive lesson, dice order and locale switching: ${width}px passed`);
}
assert.deepEqual(errors, []);
} finally {
await browser.close();
await new Promise((resolve) => server.close(resolve));
}