Skip to content

Commit 0bab471

Browse files
committed
test: Add localized text type and associated tests
pr: RaidTheory#291
1 parent f613717 commit 0bab471

4 files changed

Lines changed: 399 additions & 1 deletion

File tree

bun.lock

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,9 @@
1010
"prettier-plugin-sort-json": "^4.1.1",
1111
"safe-stable-stringify": "^2.5.0"
1212
},
13-
"private": true
13+
"private": true,
14+
"dependencies": {
15+
"jsonpath-plus": "^10.4.0",
16+
"zod": "^4.3.6"
17+
}
1418
}

src/types/localized-text.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import * as z from "zod"; // https://zod.dev/basics
2+
3+
// TODO: When the arctracker-ui directory is normalized to use "ko-KR" as the locale
4+
// key for Korean, we can rename this to LocalizedText and remove the other private schemas.
5+
const LocalizedTextCanonical = z
6+
.object({
7+
// Match the locales defined by:
8+
// https://github.com/RaidTheory/arcraiders-data/tree/main/arctracker-ui
9+
da: z.string(),
10+
de: z.string(),
11+
en: z.string(),
12+
es: z.string(),
13+
fr: z.string(),
14+
he: z.string(),
15+
hr: z.string(),
16+
it: z.string(),
17+
ja: z.string(),
18+
"ko-KR": z.string(),
19+
no: z.string(),
20+
pl: z.string(),
21+
"pt-BR": z.string(),
22+
pt: z.string(),
23+
ru: z.string(),
24+
sr: z.string(),
25+
tr: z.string(),
26+
uk: z.string(),
27+
"zh-CN": z.string(),
28+
"zh-TW": z.string()
29+
})
30+
.describe("LocalizedTextCanonical");
31+
32+
const LocalizedTextRaw = LocalizedTextCanonical.extend({
33+
ko: z.string().optional(),
34+
"ko-KR": z.string().optional(),
35+
kr: z.string().optional()
36+
}).describe("LocalizedTextRaw");
37+
38+
export const LocalizedText = LocalizedTextRaw.transform((data) => {
39+
const { ko, ["ko-KR"]: _koKR, kr, ...rest } = data;
40+
41+
return {
42+
...rest,
43+
"ko-KR": _koKR ?? ko ?? kr
44+
};
45+
})
46+
.pipe(LocalizedTextCanonical.strict())
47+
.describe("LocalizedText");
48+
49+
// Private data exported for testing purposes only. Not intended for public use.
50+
export const __internal__ = {
51+
LocalizedTextCanonical,
52+
LocalizedTextRaw
53+
};

0 commit comments

Comments
 (0)