|
| 1 | +import { getTranslationInMap } from '../lib/shared/languageSpecificTranslation.js' |
| 2 | +import { expect } from 'chai' |
| 3 | + |
| 4 | +describe('test language specific translation', function () { |
| 5 | + it('test getTranslationInMap', function () { |
| 6 | + const translationMaps = new Map([ |
| 7 | + ['de', new Map([['I18nTestKey', 'translationDe']])], |
| 8 | + ['de-AT', new Map([['I18nTestKey', 'translationAT']])], |
| 9 | + ['en', new Map([['I18nTestKey', 'translationEn']])], |
| 10 | + ['zh-Hans-CN', new Map([['I18nTestKey', 'translationZh-Hans-CN']])], |
| 11 | + ['sr', new Map([['I18nTestKey', 'translationSr']])], |
| 12 | + ]) |
| 13 | + |
| 14 | + expect( |
| 15 | + getTranslationInMap('de', 'I18nTestKey', translationMaps), |
| 16 | + 'Translate language code de' |
| 17 | + ).to.equal('translationDe') |
| 18 | + expect( |
| 19 | + getTranslationInMap('de-AT', 'I18nTestKey', translationMaps), |
| 20 | + 'Translate language and region code' |
| 21 | + ).to.equal('translationAT') |
| 22 | + expect( |
| 23 | + getTranslationInMap('en', 'I18nTestKey', translationMaps), |
| 24 | + 'Translate language code en' |
| 25 | + ).to.equal('translationEn') |
| 26 | + expect( |
| 27 | + getTranslationInMap('en-US', 'I18nTestKey', translationMaps), |
| 28 | + 'Fallback to language code en on region us' |
| 29 | + ).to.equal('translationEn') |
| 30 | + expect( |
| 31 | + getTranslationInMap('zh-Hans-CN', 'I18nTestKey', translationMaps), |
| 32 | + 'Translate language, region and script code' |
| 33 | + ).to.equal('translationZh-Hans-CN') |
| 34 | + expect( |
| 35 | + getTranslationInMap('sr-Cyrl-RS', 'I18nTestKey', translationMaps), |
| 36 | + 'Fallback to language code en on region an sript code' |
| 37 | + ).to.equal('translationSr') |
| 38 | + }) |
| 39 | +}) |
0 commit comments