Skip to content

Commit af103b9

Browse files
author
Deepak kudi
committed
Fix Steam date locale formatting
1 parent acec192 commit af103b9

5 files changed

Lines changed: 55 additions & 3 deletions

File tree

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"name": "augmented-steam",
33
"scripts": {
4+
"test": "node test/language-locale.test.mjs",
45
"build": "node scripts/build.mjs",
56
"update-locales": "node scripts/locales.mjs download",
67
"compile-locales": "node scripts/locales.mjs compile",

src/js/Content/Features/Store/App/FPurchaseDate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export default class FPurchaseDate extends Feature<CApp> {
3333
date: datetime.toLocaleString({
3434
dateStyle: "medium"
3535
}, {
36-
locale: this.context.language?.code ?? undefined
36+
locale: this.context.language?.locale ?? undefined
3737
})
3838
})})`;
3939
}

src/js/Content/Features/Store/App/FReleaseCountdown.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export default class FReleaseCountdown extends Feature<CApp> {
4646
dateStyle: "medium",
4747
timeStyle: "short"
4848
}, {
49-
locale: this.context.language?.code ?? undefined
49+
locale: this.context.language?.locale ?? undefined
5050
})
5151
const str = ` (${date})`;
5252

src/js/Core/Localization/Language.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,20 @@ export default class Language {
3232
"vietnamese": "vi",
3333
};
3434

35+
public static readonly localeMap: Record<string, string> = {
36+
...Language.map,
37+
"thai": "th-TH-u-ca-gregory",
38+
"ukrainian": "uk",
39+
};
40+
3541
private readonly _name: string;
3642
private readonly _code: string|null;
43+
private readonly _locale: string|null;
3744

3845
constructor(language: string) {
3946
this._name = language;
4047
this._code = Language.map[language] ?? null;
48+
this._locale = Language.localeMap[language] ?? this._code;
4149
// TODO should we throw when there is unsupported language?
4250
}
4351

@@ -49,8 +57,11 @@ export default class Language {
4957
return this._code;
5058
}
5159

60+
get locale(): string|null {
61+
return this._locale;
62+
}
63+
5264
isOneOf(...languages: string[]) {
5365
return languages.includes(this._name);
5466
}
5567
}
56-

test/language-locale.test.mjs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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

Comments
 (0)