Files
bookorbit/client/scripts/locale-catalog-validation.spec.mjs
T
neon b9e041d1b7 ci(i18n): enforce controlled crowdin localization workflow and pr validation
Add Crowdin pull request validation script, centralize locale configuration, and update GitHub workflows to enforce sparse target catalog validation.
2026-08-06 00:00:04 +00:00

45 lines
1.5 KiB
JavaScript

import { describe, expect, it } from 'vitest'
import { flattenCatalog, validateCatalogs } from './locale-catalog-validation.mjs'
function catalogs(target = {}) {
return new Map([
[
'en',
flattenCatalog({
common: { save: 'Save' },
books: { count: '{count, plural, one {# book} other {# books}}' },
}),
],
['cs', flattenCatalog(target)],
])
}
describe('locale catalog validation', () => {
it('reports invalid catalog objects with their path', () => {
expect(() => flattenCatalog(null)).toThrow('catalog root must be a message object')
expect(() => flattenCatalog(null, 'common')).toThrow('common must be a message object')
})
it('accepts a sparse target catalog', () => {
expect(validateCatalogs({ catalogs: catalogs({ common: { save: 'Uložit' } }) })).toEqual([])
})
it('rejects unknown and empty target messages', () => {
expect(validateCatalogs({ catalogs: catalogs({ common: { save: '', unknown: 'Neznámé' } }) })).toEqual([
'cs: empty message common.save',
'cs: unexpected key common.unknown',
])
})
it('validates ICU structure for translated messages that are present', () => {
const target = {
books: { count: '{count, plural, one {# kniha} other {# knih}}' },
}
expect(validateCatalogs({ catalogs: catalogs(target) })).toEqual([
'cs: ICU plural category few missing for books.count',
'cs: ICU plural category many missing for books.count',
])
})
})