mirror of
https://github.com/bookorbit/bookorbit.git
synced 2026-11-03 00:11:37 -06:00
8790208858
Use sparse target catalogs and validate Crowdin exports before proposing updates. Reject translation loss unless a maintainer acknowledges each key.
40 lines
1.2 KiB
JavaScript
40 lines
1.2 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('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',
|
|
])
|
|
})
|
|
})
|