|
| 1 | +import assert from "node:assert/strict"; |
| 2 | +import fs from "node:fs/promises"; |
| 3 | +import os from "node:os"; |
| 4 | +import path from "node:path"; |
| 5 | +import {pathToFileURL} from "node:url"; |
| 6 | +import {build} from "esbuild"; |
| 7 | +import {DateTime} from "luxon"; |
| 8 | + |
| 9 | +async function importLanguage() { |
| 10 | + const result = await build({ |
| 11 | + entryPoints: ["src/js/Core/Localization/Language.ts"], |
| 12 | + bundle: true, |
| 13 | + format: "esm", |
| 14 | + platform: "node", |
| 15 | + write: false |
| 16 | + }); |
| 17 | + const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), "as-language-")); |
| 18 | + const modulePath = path.join(tempDir, "Language.mjs"); |
| 19 | + await fs.writeFile(modulePath, result.outputFiles[0].text); |
| 20 | + return import(pathToFileURL(modulePath)); |
| 21 | +} |
| 22 | + |
| 23 | +const {default: Language} = await importLanguage(); |
| 24 | + |
| 25 | +const ukrainian = new Language("ukrainian"); |
| 26 | +assert.equal(ukrainian.code, "ua"); |
| 27 | +assert.equal(ukrainian.locale, "uk"); |
| 28 | + |
| 29 | +const thai = new Language("thai"); |
| 30 | +assert.equal(thai.code, "th"); |
| 31 | +assert.equal(thai.locale, "th-TH-u-ca-gregory"); |
| 32 | + |
| 33 | +const formattedThaiDate = DateTime.fromObject({ |
| 34 | + year: 2026, |
| 35 | + month: 1, |
| 36 | + day: 23 |
| 37 | +}).toLocaleString({dateStyle: "medium"}, {locale: thai.locale}); |
| 38 | + |
| 39 | +assert.match(formattedThaiDate, /2026/); |
| 40 | +assert.doesNotMatch(formattedThaiDate, /2569/); |
0 commit comments