Files
factorio-expcluster/exp_scenario/test/locales.test.js
T
bbassieandClaude Opus 5.5 ebe7504c00 Show the language of players on their user page
exp_legacy recorded each player's locale in PlayerData statistics
which nothing read. The lua side now sends one ipc event with the
player's locale when they join and when they change language, the
instance forwards it, and the controller stores it on the player
record.

The Scenario section of the user page shows the language by name with
a flag made from regional indicator symbols. Locales with a region use
it directly, the rest map to a country through a small table covering
Factorio's locale list. Arabic, Catalan, Basque, and Esperanto have no
single country and get no flag.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-14 22:10:31 +00:00

27 lines
1.2 KiB
JavaScript

import t from "tap";
import { localeFlag, localeName } from "../dist/node/locales.js";
// The locale folders of Factorio 2.1
const factorioLocales = [
"af", "ar", "be", "bg", "ca", "cs", "da", "de", "el", "en", "eo", "es-ES", "et", "eu", "fa", "fi", "fil", "fr",
"fy-NL", "ga-IE", "he", "hr", "hu", "id", "is", "it", "ja", "ka", "kk", "ko", "lt", "lv", "nl", "no", "pl",
"pt-BR", "pt-PT", "ro", "ru", "sk", "sl", "sq", "sr", "sv-SE", "th", "tr", "uk", "vi", "zh-CN", "zh-TW",
];
const noFlag = ["ar", "ca", "eo", "eu"];
t.test("localeFlag()", async t2 => {
t2.equal(localeFlag("de"), "\u{1F1E9}\u{1F1EA}", "language codes use the table");
t2.equal(localeFlag("pt-BR"), "\u{1F1E7}\u{1F1F7}", "regions are used directly");
t2.equal(localeFlag("zh-TW"), "\u{1F1F9}\u{1F1FC}");
for (const locale of factorioLocales) {
t2.equal(localeFlag(locale) === "", noFlag.includes(locale), `${locale} has a flag unless it has no country`);
}
t2.equal(localeFlag("xx"), "", "unknown languages have no flag");
t2.equal(localeFlag(""), "");
});
t.test("localeName()", async t2 => {
t2.equal(localeName("de"), "German");
t2.equal(localeName("not a locale"), "not a locale", "invalid codes are shown as they are");
});