import test from 'brittle'
import { checkTranslationErrors, checkTranslationWarnings, checkReferenceQuality } from './check-consistency.js'
import { translations } from './index.js'
const failOnConsistencyError = true
const failOnConsistencyWarning = false
test(`Translations ok--check errors (Fail on error: ${failOnConsistencyError})`, function (t) {
const { summary } = checkTranslationErrors()
const allGood = summary.length === 0
if (!allGood) {
console.error('Translation error summary:')
console.error(` ${summary.join('\n ')}`)
if (failOnConsistencyError) t.fail()
if (summary.join().includes('extra segments')) {
t.fail(
'Intermediary fix: extra segments are already under control, so fail on introducing new ones'
)
}
}
})
test(`Translations ok--check warnings (fail on warning: ${failOnConsistencyWarning})`, function (t) {
const { summary } = checkTranslationWarnings()
const allGood = summary.length === 0
if (!allGood) {
console.warn('Translation warning summary:')
console.warn(` ${summary.join('\n ')}`)
if (failOnConsistencyWarning) t.fail()
}
})
test('Has expected languages', function (t) {
const locales = new Set(Object.keys(translations))
const expected = new Set(['en', 'es-ES', 'de-DE', 'hi-IN', 'it-IT', 'ka-GE', 'nl-NL', 'pt-PT', 'ro-RO', 'ru-RU', 'tr-TR', 'uk-UA', 'vi-VN', 'zh-CN', 'zh-TW'])
t.alike(expected, locales)
})
test('No issues with reference', function (t) {
const issues = checkReferenceQuality()
t.is(issues.length, 0, issues.join('\n'))
})