MOBILE-4288 multilang: Use fallback language
parent
a0b4c8259d
commit
46f3da7d8f
|
@ -58,15 +58,13 @@ export class AddonFilterMultilangHandlerService extends CoreFilterDefaultHandler
|
|||
}
|
||||
|
||||
// Find language to use.
|
||||
let language: string | undefined = await CoreLang.getCurrentLanguage();
|
||||
|
||||
if (!languages.has(language)) {
|
||||
language = CoreLang.getParentLanguage();
|
||||
}
|
||||
|
||||
if (!language) {
|
||||
language = firstLanguage;
|
||||
}
|
||||
const language = [
|
||||
await CoreLang.getCurrentLanguage(),
|
||||
CoreLang.getParentLanguage(),
|
||||
CoreLang.getFallbackLanguage(),
|
||||
firstLanguage,
|
||||
]
|
||||
.find(candidate => candidate && languages.has(candidate));
|
||||
|
||||
if (!language) {
|
||||
return text;
|
||||
|
|
|
@ -122,7 +122,7 @@ describe('Lang', () => {
|
|||
`, 'Japanese text');
|
||||
});
|
||||
|
||||
it('filters multilang text using unknown language', async () => {
|
||||
it('filters multilang text using the fallback language', async () => {
|
||||
currentLanguage = 'ca';
|
||||
parentLanguage = undefined;
|
||||
|
||||
|
@ -131,7 +131,7 @@ describe('Lang', () => {
|
|||
<span class="multilang" lang="en">English</span>
|
||||
<span class="multilang" lang="ja">Japanese</span>
|
||||
text
|
||||
`, 'Spanish text');
|
||||
`, 'English text');
|
||||
|
||||
await expectMultilangFilter(`
|
||||
{mlang es}Spanish{mlang}
|
||||
|
@ -141,6 +141,23 @@ describe('Lang', () => {
|
|||
`, 'text');
|
||||
});
|
||||
|
||||
it('filters multilang text using the first language', async () => {
|
||||
currentLanguage = 'ca';
|
||||
parentLanguage = undefined;
|
||||
|
||||
await expectMultilangFilter(`
|
||||
<span class="multilang" lang="es">Spanish</span>
|
||||
<span class="multilang" lang="ja">Japanese</span>
|
||||
text
|
||||
`, 'Spanish text');
|
||||
|
||||
await expectMultilangFilter(`
|
||||
{mlang es}Spanish{mlang}
|
||||
{mlang ja}Japanese{mlang}
|
||||
text
|
||||
`, 'text');
|
||||
});
|
||||
|
||||
/**
|
||||
* Test multilang filter (normalizing whitespace).
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue