update tests for translation registry
This commit is contained in:
@@ -60,7 +60,7 @@ const danishRegional: ManifestTranslations = {
|
|||||||
alias: 'test.da-DK',
|
alias: 'test.da-DK',
|
||||||
name: 'Test Danish (Denmark)',
|
name: 'Test Danish (Denmark)',
|
||||||
meta: {
|
meta: {
|
||||||
culture: 'da-DK',
|
culture: 'da-dk',
|
||||||
translations: {
|
translations: {
|
||||||
general: {
|
general: {
|
||||||
close: 'Luk',
|
close: 'Luk',
|
||||||
@@ -72,6 +72,8 @@ const danishRegional: ManifestTranslations = {
|
|||||||
|
|
||||||
describe('UmbLocalizeController', () => {
|
describe('UmbLocalizeController', () => {
|
||||||
umbExtensionsRegistry.register(english);
|
umbExtensionsRegistry.register(english);
|
||||||
|
umbExtensionsRegistry.register(danish);
|
||||||
|
umbExtensionsRegistry.register(danishRegional);
|
||||||
|
|
||||||
let registry: UmbTranslationRegistry;
|
let registry: UmbTranslationRegistry;
|
||||||
|
|
||||||
@@ -85,6 +87,11 @@ describe('UmbLocalizeController', () => {
|
|||||||
registry.translations.clear();
|
registry.translations.clear();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should set the document language and direction', async () => {
|
||||||
|
expect(document.documentElement.lang).to.equal(english.meta.culture);
|
||||||
|
expect(document.documentElement.dir).to.equal(english.meta.direction);
|
||||||
|
});
|
||||||
|
|
||||||
it('should load translations for the current language', async () => {
|
it('should load translations for the current language', async () => {
|
||||||
expect(registry.translations.has(english.meta.culture)).to.be.true;
|
expect(registry.translations.has(english.meta.culture)).to.be.true;
|
||||||
|
|
||||||
@@ -104,23 +111,24 @@ describe('UmbLocalizeController', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should load a new language', async () => {
|
it('should load a new language', async () => {
|
||||||
umbExtensionsRegistry.register(danish);
|
|
||||||
registry.loadLanguage(danish.meta.culture);
|
registry.loadLanguage(danish.meta.culture);
|
||||||
|
|
||||||
await aTimeout(0);
|
await aTimeout(0);
|
||||||
|
|
||||||
|
// Check that the new language is loaded.
|
||||||
expect(registry.translations.has(danish.meta.culture)).to.be.true;
|
expect(registry.translations.has(danish.meta.culture)).to.be.true;
|
||||||
|
|
||||||
|
// Check that the new language has the correct translations.
|
||||||
const current = registry.translations.get(danish.meta.culture);
|
const current = registry.translations.get(danish.meta.culture);
|
||||||
expect(current).to.have.property('general_close', 'Luk');
|
expect(current).to.have.property('general_close', 'Luk');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should load translations for the current language and regional', async () => {
|
it('should load translations for the current language and regional', async () => {
|
||||||
|
// Load the regional language.
|
||||||
registry.loadLanguage(danishRegional.meta.culture);
|
registry.loadLanguage(danishRegional.meta.culture);
|
||||||
umbExtensionsRegistry.register(danish);
|
|
||||||
umbExtensionsRegistry.register(danishRegional);
|
|
||||||
|
|
||||||
await aTimeout(0);
|
await aTimeout(0);
|
||||||
|
|
||||||
|
// Check that both the regional and the base language is loaded.
|
||||||
expect(registry.translations.has(danishRegional.meta.culture), 'expected "da-dk" to be present').to.be.true;
|
expect(registry.translations.has(danishRegional.meta.culture), 'expected "da-dk" to be present').to.be.true;
|
||||||
expect(registry.translations.has(danish.meta.culture), 'expected "da" to be present').to.be.true;
|
expect(registry.translations.has(danish.meta.culture), 'expected "da" to be present').to.be.true;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ export class UmbTranslationRegistry {
|
|||||||
|
|
||||||
// Notify subscribers that the inner dictionary has changed.
|
// Notify subscribers that the inner dictionary has changed.
|
||||||
return {
|
return {
|
||||||
$code: userCulture,
|
$code: extension.meta.culture.toLowerCase(),
|
||||||
$dir: extension.meta.direction ?? 'ltr',
|
$dir: extension.meta.direction ?? 'ltr',
|
||||||
...innerDictionary,
|
...innerDictionary,
|
||||||
} satisfies TranslationSet;
|
} satisfies TranslationSet;
|
||||||
@@ -66,7 +66,7 @@ export class UmbTranslationRegistry {
|
|||||||
registerTranslation(...translations);
|
registerTranslation(...translations);
|
||||||
|
|
||||||
// Set the document language
|
// Set the document language
|
||||||
document.documentElement.lang = locale.baseName;
|
document.documentElement.lang = locale.baseName.toLowerCase();
|
||||||
|
|
||||||
// Set the document direction to the direction of the primary language
|
// Set the document direction to the direction of the primary language
|
||||||
document.documentElement.dir = translations[0].$dir ?? 'ltr';
|
document.documentElement.dir = translations[0].$dir ?? 'ltr';
|
||||||
|
|||||||
Reference in New Issue
Block a user