Files
pp-tcms/frontend/messages/strings.test.ts
2025-12-14 12:14:38 +09:00

38 lines
1.1 KiB
TypeScript

import { describe, it, expect } from 'vitest';
import en from './en.json';
import ja from './ja.json';
import ptBR from './pt-BR.json';
import zhCN from './zh-CN.json';
import de from './de.json';
function getAllKeys(obj: unknown, prefix = ''): string[] {
if (typeof obj !== 'object' || obj === null) return [];
return Object.entries(obj as Record<string, unknown>).flatMap(([key, value]) => {
const fullKey = prefix ? `${prefix}.${key}` : key;
if (value && typeof value === 'object' && !Array.isArray(value)) {
return getAllKeys(value, fullKey);
}
return [fullKey];
});
}
describe('Locale message keys consistency', () => {
const locales = [
{ name: 'en', data: en },
{ name: 'ja', data: ja },
{ name: 'pt-BR', data: ptBR },
{ name: 'zh-CN', data: zhCN },
{ name: 'de', data: de },
];
const base = locales[0];
const baseKeys = getAllKeys(base.data);
for (const locale of locales.slice(1)) {
it(`should have the same keys as ${base.name} in ${locale.name}`, () => {
const localeKeys = getAllKeys(locale.data);
expect(localeKeys).toEqual(baseKeys);
});
}
});