Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 95a7052

Browse files
feat: add locale unit test (#388)
1 parent 3066a4c commit 95a7052

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

‎__test__/locale.spec.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { describe, it, expect } from 'vitest'
2+
import { resolve } from 'node:path'
3+
import { readdirSync } from 'node:fs'
4+
import en from '../locales/en-US.json'
5+
6+
function getKeys(obj: any, path = '', result: string[] = []) {
7+
for (let key in obj) {
8+
if (typeof obj[key] === 'object') {
9+
getKeys(obj[key], path ? `${path}.${key}` : key, result);
10+
} else {
11+
result.push(path ? `${path}.${key}` : key);
12+
}
13+
}
14+
return result;
15+
}
16+
17+
const localesOtherThanEnglish = readdirSync(resolve(__dirname, '../locales')).filter((file) => {
18+
return file.endsWith('.json') && !file.startsWith('en-US')
19+
})
20+
const defaultKeys = getKeys(en);
21+
22+
describe("locale files should include all keys", () => {
23+
localesOtherThanEnglish.forEach((locale) => {
24+
it(`for ${locale}`, () => {
25+
expect(getKeys(require(`../locales/${locale}`))).toEqual(defaultKeys)
26+
})
27+
})
28+
})

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /