Add Persian viewer and tutorial translations
This commit is contained in:
parent
37fa7d4449
commit
4d41681ad5
21 changed files with 1270 additions and 17 deletions
|
|
@ -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 (`fa`, including `fa-IR`) uses RTL text isolates. Board and control layout remains unchanged. Technical extraction identifiers are retained verbatim.
|
||||
|
|
|
|||
|
|
@ -1173,5 +1173,9 @@
|
|||
"{p0} cards: {p1}": "{p0}-kort: {p1}",
|
||||
"Factories staffed: {p0}/{p1}.": "Bemandede fabrikker: {p0}/{p1}.",
|
||||
"Production: choose Mega cards before drawing. Each Mega replaces the production of 4 staffed factories; other factories produce single cards.": "Produktion: Vælg Mega-kort, før du trækker. Hvert Mega-kort erstatter produktionen fra 4 bemandede fabrikker; de øvrige fabrikker producerer enkeltkort.",
|
||||
"Purchase order this round: {p0}": "Købsrækkefølge i denne runde: {p0}"
|
||||
"Purchase order this round: {p0}": "Købsrækkefølge i denne runde: {p0}",
|
||||
"New factory": "New factory",
|
||||
"How to buy": "How to buy",
|
||||
"Remaining upgrades": "Remaining upgrades",
|
||||
"Remaining Kicker cards": "Remaining Kicker cards"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1173,5 +1173,9 @@
|
|||
"{p0} cards: {p1}": "{p0}-Karten: {p1}",
|
||||
"Factories staffed: {p0}/{p1}.": "Besetzte Fabriken: {p0}/{p1}.",
|
||||
"Production: choose Mega cards before drawing. Each Mega replaces the production of 4 staffed factories; other factories produce single cards.": "Produktion: Wähle Mega-Karten, bevor du ziehst. Jede Mega-Karte ersetzt die Produktion von 4 besetzten Fabriken; die übrigen Fabriken produzieren einzelne Karten.",
|
||||
"Purchase order this round: {p0}": "Kaufreihenfolge in dieser Runde: {p0}"
|
||||
"Purchase order this round: {p0}": "Kaufreihenfolge in dieser Runde: {p0}",
|
||||
"New factory": "New factory",
|
||||
"How to buy": "How to buy",
|
||||
"Remaining upgrades": "Remaining upgrades",
|
||||
"Remaining Kicker cards": "Remaining Kicker cards"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1173,5 +1173,9 @@
|
|||
"{p0} cards: {p1}": "Κάρτες {p0}: {p1}",
|
||||
"Factories staffed: {p0}/{p1}.": "Στελεχωμένα εργοστάσια: {p0}/{p1}.",
|
||||
"Production: choose Mega cards before drawing. Each Mega replaces the production of 4 staffed factories; other factories produce single cards.": "Παραγωγή: επίλεξε κάρτες Mega πριν τραβήξεις. Κάθε Mega αντικαθιστά την παραγωγή 4 στελεχωμένων εργοστασίων· τα υπόλοιπα εργοστάσια παράγουν μεμονωμένες κάρτες.",
|
||||
"Purchase order this round: {p0}": "Σειρά αγοράς σε αυτόν τον γύρο: {p0}"
|
||||
"Purchase order this round: {p0}": "Σειρά αγοράς σε αυτόν τον γύρο: {p0}",
|
||||
"New factory": "New factory",
|
||||
"How to buy": "How to buy",
|
||||
"Remaining upgrades": "Remaining upgrades",
|
||||
"Remaining Kicker cards": "Remaining Kicker cards"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1173,5 +1173,9 @@
|
|||
"{p0} cards: {p1}": "{p0} cards: {p1}",
|
||||
"Factories staffed: {p0}/{p1}.": "Factories staffed: {p0}/{p1}.",
|
||||
"Production: choose Mega cards before drawing. Each Mega replaces the production of 4 staffed factories; other factories produce single cards.": "Production: choose Mega cards before drawing. Each Mega replaces the production of 4 staffed factories; other factories produce single cards.",
|
||||
"Purchase order this round: {p0}": "Purchase order this round: {p0}"
|
||||
"Purchase order this round: {p0}": "Purchase order this round: {p0}",
|
||||
"New factory": "New factory",
|
||||
"How to buy": "How to buy",
|
||||
"Remaining upgrades": "Remaining upgrades",
|
||||
"Remaining Kicker cards": "Remaining Kicker cards"
|
||||
}
|
||||
|
|
|
|||
1181
packages/viewer/src/localization/fa.json
Normal file
1181
packages/viewer/src/localization/fa.json
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -1173,5 +1173,9 @@
|
|||
"{p0} cards: {p1}": "Cartes {p0} : {p1}",
|
||||
"Factories staffed: {p0}/{p1}.": "Usines avec opérateur : {p0}/{p1}.",
|
||||
"Production: choose Mega cards before drawing. Each Mega replaces the production of 4 staffed factories; other factories produce single cards.": "Production : choisissez les cartes Mega avant de piocher. Chaque Mega remplace la production de 4 usines avec opérateur ; les autres usines produisent des cartes individuelles.",
|
||||
"Purchase order this round: {p0}": "Ordre d’achat ce round : {p0}"
|
||||
"Purchase order this round: {p0}": "Ordre d’achat ce round : {p0}",
|
||||
"New factory": "New factory",
|
||||
"How to buy": "How to buy",
|
||||
"Remaining upgrades": "Remaining upgrades",
|
||||
"Remaining Kicker cards": "Remaining Kicker cards"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1173,5 +1173,9 @@
|
|||
"{p0} cards: {p1}": "{p0} कार्ड: {p1}",
|
||||
"Factories staffed: {p0}/{p1}.": "कार्यरत फ़ैक्ट्रियाँ: {p0}/{p1}।",
|
||||
"Production: choose Mega cards before drawing. Each Mega replaces the production of 4 staffed factories; other factories produce single cards.": "उत्पादन: कार्ड खींचने से पहले मेगा कार्ड चुनें। हर मेगा कार्ड 4 संचालक वाले कारखानों के उत्पादन की जगह लेता है; बाकी कारखाने अलग-अलग कार्ड बनाते हैं।",
|
||||
"Purchase order this round: {p0}": "इस दौर में खरीद का क्रम: {p0}"
|
||||
"Purchase order this round: {p0}": "इस दौर में खरीद का क्रम: {p0}",
|
||||
"New factory": "New factory",
|
||||
"How to buy": "How to buy",
|
||||
"Remaining upgrades": "Remaining upgrades",
|
||||
"Remaining Kicker cards": "Remaining Kicker cards"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ 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 { mountLocalization as mount, createTranslator } from "./runtime.js";
|
||||
export { languages, resolveLocale } from "./runtime.js";
|
||||
export const catalogs = {
|
||||
|
|
@ -31,6 +32,7 @@ export const catalogs = {
|
|||
vi: catalog12,
|
||||
it: catalog13,
|
||||
nl: catalog14,
|
||||
fa: catalog15,
|
||||
};
|
||||
const translators = new Map();
|
||||
export function translateText(text, locale = "en") {
|
||||
|
|
|
|||
|
|
@ -1173,5 +1173,9 @@
|
|||
"{p0} cards: {p1}": "Carte {p0}: {p1}",
|
||||
"Factories staffed: {p0}/{p1}.": "Fabbriche con operatori: {p0}/{p1}.",
|
||||
"Production: choose Mega cards before drawing. Each Mega replaces the production of 4 staffed factories; other factories produce single cards.": "Produzione: scegli le carte Mega prima di pescare. Ogni Mega sostituisce la produzione di 4 fabbriche con operatore; le altre fabbriche producono carte singole.",
|
||||
"Purchase order this round: {p0}": "Ordine di acquisto in questo round: {p0}"
|
||||
"Purchase order this round: {p0}": "Ordine di acquisto in questo round: {p0}",
|
||||
"New factory": "New factory",
|
||||
"How to buy": "How to buy",
|
||||
"Remaining upgrades": "Remaining upgrades",
|
||||
"Remaining Kicker cards": "Remaining Kicker cards"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1173,5 +1173,9 @@
|
|||
"{p0} cards: {p1}": "{p0} 카드: {p1}",
|
||||
"Factories staffed: {p0}/{p1}.": "작업자가 배치된 공장: {p0}/{p1}.",
|
||||
"Production: choose Mega cards before drawing. Each Mega replaces the production of 4 staffed factories; other factories produce single cards.": "생산: 카드를 뽑기 전에 메가 카드를 선택하세요. 메가 카드 1장은 인력이 배치된 공장 4곳의 생산을 대체합니다. 나머지 공장은 개별 카드를 생산합니다.",
|
||||
"Purchase order this round: {p0}": "이번 라운드 구매 순서: {p0}"
|
||||
"Purchase order this round: {p0}": "이번 라운드 구매 순서: {p0}",
|
||||
"New factory": "New factory",
|
||||
"How to buy": "How to buy",
|
||||
"Remaining upgrades": "Remaining upgrades",
|
||||
"Remaining Kicker cards": "Remaining Kicker cards"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1173,5 +1173,9 @@
|
|||
"{p0} cards: {p1}": "{p0}-kaarten: {p1}",
|
||||
"Factories staffed: {p0}/{p1}.": "Bemande fabrieken: {p0}/{p1}.",
|
||||
"Production: choose Mega cards before drawing. Each Mega replaces the production of 4 staffed factories; other factories produce single cards.": "Productie: kies Mega-kaarten voordat je trekt. Elke Mega vervangt de productie van 4 bemande fabrieken; de andere fabrieken produceren losse kaarten.",
|
||||
"Purchase order this round: {p0}": "Aankoopvolgorde deze ronde: {p0}"
|
||||
"Purchase order this round: {p0}": "Aankoopvolgorde deze ronde: {p0}",
|
||||
"New factory": "New factory",
|
||||
"How to buy": "How to buy",
|
||||
"Remaining upgrades": "Remaining upgrades",
|
||||
"Remaining Kicker cards": "Remaining Kicker cards"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1173,5 +1173,9 @@
|
|||
"{p0} cards: {p1}": "Karty {p0}: {p1}",
|
||||
"Factories staffed: {p0}/{p1}.": "Obsadzone fabryki: {p0}/{p1}.",
|
||||
"Production: choose Mega cards before drawing. Each Mega replaces the production of 4 staffed factories; other factories produce single cards.": "Produkcja: wybierz karty Mega przed dobraniem kart. Każda karta Mega zastępuje produkcję 4 obsadzonych fabryk; pozostałe fabryki produkują pojedyncze karty.",
|
||||
"Purchase order this round: {p0}": "Kolejność zakupów w tej rundzie: {p0}"
|
||||
"Purchase order this round: {p0}": "Kolejność zakupów w tej rundzie: {p0}",
|
||||
"New factory": "New factory",
|
||||
"How to buy": "How to buy",
|
||||
"Remaining upgrades": "Remaining upgrades",
|
||||
"Remaining Kicker cards": "Remaining Kicker cards"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1173,5 +1173,9 @@
|
|||
"{p0} cards: {p1}": "Cartas de {p0}: {p1}",
|
||||
"Factories staffed: {p0}/{p1}.": "Fábricas com operadores: {p0}/{p1}.",
|
||||
"Production: choose Mega cards before drawing. Each Mega replaces the production of 4 staffed factories; other factories produce single cards.": "Produção: escolha as cartas Mega antes de comprar cartas. Cada Mega substitui a produção de 4 fábricas com operadores; as outras fábricas produzem cartas individuais.",
|
||||
"Purchase order this round: {p0}": "Ordem de compra nesta rodada: {p0}"
|
||||
"Purchase order this round: {p0}": "Ordem de compra nesta rodada: {p0}",
|
||||
"New factory": "New factory",
|
||||
"How to buy": "How to buy",
|
||||
"Remaining upgrades": "Remaining upgrades",
|
||||
"Remaining Kicker cards": "Remaining Kicker cards"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1173,5 +1173,9 @@
|
|||
"{p0} cards: {p1}": "Cărți {p0}: {p1}",
|
||||
"Factories staffed: {p0}/{p1}.": "Fabrici cu operatori: {p0}/{p1}.",
|
||||
"Production: choose Mega cards before drawing. Each Mega replaces the production of 4 staffed factories; other factories produce single cards.": "Producție: alege cărțile Mega înainte de a trage. Fiecare carte Mega înlocuiește producția a 4 fabrici cu operatori; celelalte fabrici produc cărți individuale.",
|
||||
"Purchase order this round: {p0}": "Ordinea cumpărăturilor în această rundă: {p0}"
|
||||
"Purchase order this round: {p0}": "Ordinea cumpărăturilor în această rundă: {p0}",
|
||||
"New factory": "New factory",
|
||||
"How to buy": "How to buy",
|
||||
"Remaining upgrades": "Remaining upgrades",
|
||||
"Remaining Kicker cards": "Remaining Kicker cards"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1173,5 +1173,9 @@
|
|||
"{p0} cards: {p1}": "Карты {p0}: {p1}",
|
||||
"Factories staffed: {p0}/{p1}.": "Заводы с операторами: {p0}/{p1}.",
|
||||
"Production: choose Mega cards before drawing. Each Mega replaces the production of 4 staffed factories; other factories produce single cards.": "Производство: выберите мегакарты до добора карт. Каждая мегакарта заменяет продукцию 4 фабрик с операторами; остальные фабрики производят отдельные карты.",
|
||||
"Purchase order this round: {p0}": "Порядок покупок в этом раунде: {p0}"
|
||||
"Purchase order this round: {p0}": "Порядок покупок в этом раунде: {p0}",
|
||||
"New factory": "New factory",
|
||||
"How to buy": "How to buy",
|
||||
"Remaining upgrades": "Remaining upgrades",
|
||||
"Remaining Kicker cards": "Remaining Kicker cards"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ export const languages = {
|
|||
vi: "Tiếng Việt",
|
||||
it: "Italiano",
|
||||
nl: "Nederlands",
|
||||
fa: "فارسی",
|
||||
};
|
||||
|
||||
export function resolveLocale(value) {
|
||||
|
|
@ -203,7 +204,9 @@ export function mountLocalization(target, catalogs, initialLocale = "en") {
|
|||
const key = attribute ?? "text";
|
||||
const previous = record.get(key);
|
||||
const source = previous?.output === value ? previous.source : value;
|
||||
const output = translator.translate(source);
|
||||
const translated = translator.translate(source);
|
||||
const output =
|
||||
translator.locale === "fa" && /[\u0600-\u06ff]/.test(translated) ? `\u2067${translated}\u2069` : translated;
|
||||
record.set(key, { source, output });
|
||||
if (value !== output) {
|
||||
if (attribute) {
|
||||
|
|
|
|||
|
|
@ -1173,5 +1173,9 @@
|
|||
"{p0} cards: {p1}": "Thẻ {p0}: {p1}",
|
||||
"Factories staffed: {p0}/{p1}.": "Nhà máy có người vận hành: {p0}/{p1}.",
|
||||
"Production: choose Mega cards before drawing. Each Mega replaces the production of 4 staffed factories; other factories produce single cards.": "Sản xuất: chọn thẻ Mega trước khi rút bài. Mỗi thẻ Mega thay thế sản lượng của 4 nhà máy có người vận hành; các nhà máy còn lại sản xuất các thẻ riêng lẻ.",
|
||||
"Purchase order this round: {p0}": "Thứ tự mua trong vòng này: {p0}"
|
||||
"Purchase order this round: {p0}": "Thứ tự mua trong vòng này: {p0}",
|
||||
"New factory": "New factory",
|
||||
"How to buy": "How to buy",
|
||||
"Remaining upgrades": "Remaining upgrades",
|
||||
"Remaining Kicker cards": "Remaining Kicker cards"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1173,5 +1173,9 @@
|
|||
"{p0} cards: {p1}": "{p0} 卡:{p1} 張",
|
||||
"Factories staffed: {p0}/{p1}.": "已配置操作員的工廠:{p0}/{p1}。",
|
||||
"Production: choose Mega cards before drawing. Each Mega replaces the production of 4 staffed factories; other factories produce single cards.": "生產:抽牌前先選擇巨型牌。每張巨型牌取代 4 座已配置操作員工廠的產出;其他工廠各自生產單張牌。",
|
||||
"Purchase order this round: {p0}": "本回合購買順位:{p0}"
|
||||
"Purchase order this round: {p0}": "本回合購買順位:{p0}",
|
||||
"New factory": "New factory",
|
||||
"How to buy": "How to buy",
|
||||
"Remaining upgrades": "Remaining upgrades",
|
||||
"Remaining Kicker cards": "Remaining Kicker cards"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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`);
|
||||
|
|
|
|||
|
|
@ -137,3 +137,8 @@ test("colony ship lists translate each upgrade without rewriting player names",
|
|||
t.setLocale("en");
|
||||
assert.equal(t.translate(input), input);
|
||||
});
|
||||
|
||||
test("Persian regional tags select Farsi", () => {
|
||||
assert.equal(resolveLocale("fa-IR"), "fa");
|
||||
assert.equal(resolveLocale("fa_IR"), "fa");
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue