Files
bookorbit/client/scripts/locale-catalog-validation.spec.mjs
T
neon 9eff914aef fix(client): stop requiring plural categories no count can select
The locale validator demanded every CLDR plural category, so each new ICU plural key took the daily
Crowdin sync red until a `many` branch was hand-added for Spanish and French. That branch can never
render: `many` selects at a million and over in Spanish, French, Italian and Portuguese, and only
for fractional counts in Czech and Slovak, while every catalog plural counts whole items well below
a million and intl-messageformat falls back to `other` regardless. Require only the categories an
integer count 0..1000 can select, which is the same set every integer below a million selects, and
keep `other` always so the categories everyday counts reach stay mandatory.

Drop a target message that still fails validation from the sparse catalog instead of failing the
whole export, so one broken string can no longer block the other 23 languages for days. Report the
rejections in the run log and the pull request body, and keep the retention guard fatal when a
rejected message would replace a translation that is already in Git.
2026-08-12 16:54:51 +00:00

42 lines
1.4 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'])
})
})