From 0dafc7eb3d79e02bde6fe51d1a9fd22f7ff10d26 Mon Sep 17 00:00:00 2001 From: Puneet Dixit <236133619+puneetdixit200@users.noreply.github.com> Date: Sat, 23 May 2026 01:03:30 +0530 Subject: [PATCH] Fix Steam date locale formatting --- package.json | 1 + .../Features/Store/App/FPurchaseDate.ts | 2 +- .../Features/Store/App/FReleaseCountdown.ts | 2 +- src/js/Core/Localization/Language.ts | 13 +++++- test/language-locale.test.mjs | 40 +++++++++++++++++++ 5 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 test/language-locale.test.mjs diff --git a/package.json b/package.json index 45d3f3063..d31929cad 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,7 @@ { "name": "augmented-steam", "scripts": { + "test": "node test/language-locale.test.mjs", "build": "node scripts/build.mjs", "update-locales": "node scripts/locales.mjs download", "compile-locales": "node scripts/locales.mjs compile", diff --git a/src/js/Content/Features/Store/App/FPurchaseDate.ts b/src/js/Content/Features/Store/App/FPurchaseDate.ts index adb509844..57ff3497d 100644 --- a/src/js/Content/Features/Store/App/FPurchaseDate.ts +++ b/src/js/Content/Features/Store/App/FPurchaseDate.ts @@ -33,7 +33,7 @@ export default class FPurchaseDate extends Feature { date: datetime.toLocaleString({ dateStyle: "medium" }, { - locale: this.context.language?.code ?? undefined + locale: this.context.language?.locale ?? undefined }) })})`; } diff --git a/src/js/Content/Features/Store/App/FReleaseCountdown.ts b/src/js/Content/Features/Store/App/FReleaseCountdown.ts index 486fcd976..1583904f6 100644 --- a/src/js/Content/Features/Store/App/FReleaseCountdown.ts +++ b/src/js/Content/Features/Store/App/FReleaseCountdown.ts @@ -46,7 +46,7 @@ export default class FReleaseCountdown extends Feature { dateStyle: "medium", timeStyle: "short" }, { - locale: this.context.language?.code ?? undefined + locale: this.context.language?.locale ?? undefined }) const str = ` (${date})`; diff --git a/src/js/Core/Localization/Language.ts b/src/js/Core/Localization/Language.ts index 187c13ac1..3afdcdab5 100644 --- a/src/js/Core/Localization/Language.ts +++ b/src/js/Core/Localization/Language.ts @@ -32,12 +32,20 @@ export default class Language { "vietnamese": "vi", }; + public static readonly localeMap: Record = { + ...Language.map, + "thai": "th-TH-u-ca-gregory", + "ukrainian": "uk", + }; + private readonly _name: string; private readonly _code: string|null; + private readonly _locale: string|null; constructor(language: string) { this._name = language; this._code = Language.map[language] ?? null; + this._locale = Language.localeMap[language] ?? this._code; // TODO should we throw when there is unsupported language? } @@ -49,8 +57,11 @@ export default class Language { return this._code; } + get locale(): string|null { + return this._locale; + } + isOneOf(...languages: string[]) { return languages.includes(this._name); } } - diff --git a/test/language-locale.test.mjs b/test/language-locale.test.mjs new file mode 100644 index 000000000..568954ab2 --- /dev/null +++ b/test/language-locale.test.mjs @@ -0,0 +1,40 @@ +import assert from "node:assert/strict"; +import fs from "node:fs/promises"; +import os from "node:os"; +import path from "node:path"; +import {pathToFileURL} from "node:url"; +import {build} from "esbuild"; +import {DateTime} from "luxon"; + +async function importLanguage() { + const result = await build({ + entryPoints: ["src/js/Core/Localization/Language.ts"], + bundle: true, + format: "esm", + platform: "node", + write: false + }); + const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), "as-language-")); + const modulePath = path.join(tempDir, "Language.mjs"); + await fs.writeFile(modulePath, result.outputFiles[0].text); + return import(pathToFileURL(modulePath)); +} + +const {default: Language} = await importLanguage(); + +const ukrainian = new Language("ukrainian"); +assert.equal(ukrainian.code, "ua"); +assert.equal(ukrainian.locale, "uk"); + +const thai = new Language("thai"); +assert.equal(thai.code, "th"); +assert.equal(thai.locale, "th-TH-u-ca-gregory"); + +const formattedThaiDate = DateTime.fromObject({ + year: 2026, + month: 1, + day: 23 +}).toLocaleString({dateStyle: "medium"}, {locale: thai.locale}); + +assert.match(formattedThaiDate, /2026/); +assert.doesNotMatch(formattedThaiDate, /2569/);