1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const PIVOT_LANGUAGE = "en";
const LANGUAGE_PAIRS = [
{ fromLang: PIVOT_LANGUAGE, toLang: "es" },
{ fromLang: "es", toLang: PIVOT_LANGUAGE },
{ fromLang: PIVOT_LANGUAGE, toLang: "fr" },
{ fromLang: "fr", toLang: PIVOT_LANGUAGE },
{ fromLang: PIVOT_LANGUAGE, toLang: "pl" },
{ fromLang: "pl", toLang: PIVOT_LANGUAGE },
];
async function runLangTagsTest(
{
systemLocales,
appLocales,
webLanguages,
page,
languagePairs = LANGUAGE_PAIRS,
},
langTags
) {
const cleanupLocales = await mockLocales({
systemLocales,
appLocales,
webLanguages,
});
const { cleanup: cleanupTestPage } = await loadTestPage({
page,
languagePairs,
});
const actor = getTranslationsParent();
await TestUtils.waitForCondition(
async () => (await actor.getLangTagsForTranslation())?.docLangTag,
"Waiting for a document language tag to be found."
);
Assert.deepEqual(await actor.getLangTagsForTranslation(), langTags);
await cleanupLocales();
await cleanupTestPage();
}
add_task(async function test_lang_tags_direct_translations() {
info(
"Test the detected languages for translations when a translation pair is available"
);
await runLangTagsTest(
{
systemLocales: ["en"],
appLocales: ["en"],
webLanguages: ["en"],
page: TRANSLATIONS_TESTER_ES,
},
{
docLangTag: "es",
userLangTag: "en",
isDocLangTagSupported: true,
}
);
});
add_task(async function test_lang_tags_with_pivots() {
info("Test the detected languages for translations when a pivot is needed.");
await runLangTagsTest(
{
systemLocales: ["fr"],
appLocales: ["fr", "en"],
webLanguages: ["fr", "en"],
page: TRANSLATIONS_TESTER_ES,
},
{
docLangTag: "es",
userLangTag: "fr",
isDocLangTagSupported: true,
}
);
});
add_task(async function test_lang_tags_with_pivots_second_preferred() {
info(
"Test using a pivot language when the first preferred lang tag doesn't match"
);
await runLangTagsTest(
{
systemLocales: ["it"],
appLocales: ["it", "en"],
webLanguages: ["it", "en"],
page: TRANSLATIONS_TESTER_ES,
},
{
docLangTag: "es",
userLangTag: "en",
isDocLangTagSupported: true,
}
);
});
add_task(async function test_lang_tags_with_non_supported_doc_language() {
info("Test using a pivot language when the doc language isn't supported");
await runLangTagsTest(
{
systemLocales: ["fr"],
appLocales: ["fr", "en"],
webLanguages: ["fr", "en"],
page: TRANSLATIONS_TESTER_ES,
languagePairs: [
{ fromLang: PIVOT_LANGUAGE, toLang: "fr" },
{ fromLang: "fr", toLang: PIVOT_LANGUAGE },
// No Spanish support.
],
},
{
docLangTag: "es",
userLangTag: "fr",
isDocLangTagSupported: false,
}
);
});
|