]> git.proxmox.com Git - mirror_novnc.git/blame - tests/test.localization.js
Merge branch 'camelcase' of https://github.com/samhed/noVNC
[mirror_novnc.git] / tests / test.localization.js
CommitLineData
2b5f94fa 1const expect = chai.expect;
8727f598 2import { l10n } from '../app/localization.js';
7279364c 3
2c5491e1 4describe('Localization', function () {
7279364c
SM
5 "use strict";
6
7 describe('language selection', function () {
2b5f94fa 8 let origNavigator;
7279364c
SM
9 beforeEach(function () {
10 // window.navigator is a protected read-only property in many
11 // environments, so we need to redefine it whilst running these
12 // tests.
13 origNavigator = Object.getOwnPropertyDescriptor(window, "navigator");
14 if (origNavigator === undefined) {
15 // Object.getOwnPropertyDescriptor() doesn't work
16 // properly in any version of IE
17 this.skip();
18 }
19
20 Object.defineProperty(window, "navigator", {value: {}});
21 if (window.navigator.languages !== undefined) {
22 // Object.defineProperty() doesn't work properly in old
23 // versions of Chrome
24 this.skip();
25 }
26
27 window.navigator.languages = [];
28 });
29 afterEach(function () {
eb05b45b
PO
30 if (origNavigator !== undefined) {
31 Object.defineProperty(window, "navigator", origNavigator);
32 }
7279364c
SM
33 });
34
2c5491e1 35 it('should use English by default', function () {
7279364c
SM
36 expect(l10n.language).to.equal('en');
37 });
2c5491e1 38 it('should use English if no user language matches', function () {
7279364c
SM
39 window.navigator.languages = ["nl", "de"];
40 l10n.setup(["es", "fr"]);
41 expect(l10n.language).to.equal('en');
42 });
2c5491e1 43 it('should use the most preferred user language', function () {
7279364c
SM
44 window.navigator.languages = ["nl", "de", "fr"];
45 l10n.setup(["es", "fr", "de"]);
46 expect(l10n.language).to.equal('de');
47 });
2c5491e1 48 it('should prefer sub-languages languages', function () {
7279364c
SM
49 window.navigator.languages = ["pt-BR"];
50 l10n.setup(["pt", "pt-BR"]);
51 expect(l10n.language).to.equal('pt-BR');
52 });
2c5491e1 53 it('should fall back to language "parents"', function () {
7279364c
SM
54 window.navigator.languages = ["pt-BR"];
55 l10n.setup(["fr", "pt", "de"]);
56 expect(l10n.language).to.equal('pt');
57 });
2c5491e1 58 it('should not use specific language when user asks for a generic language', function () {
7279364c
SM
59 window.navigator.languages = ["pt", "de"];
60 l10n.setup(["fr", "pt-BR", "de"]);
61 expect(l10n.language).to.equal('de');
62 });
2c5491e1 63 it('should handle underscore as a separator', function () {
7279364c
SM
64 window.navigator.languages = ["pt-BR"];
65 l10n.setup(["pt_BR"]);
66 expect(l10n.language).to.equal('pt_BR');
67 });
2c5491e1 68 it('should handle difference in case', function () {
7279364c
SM
69 window.navigator.languages = ["pt-br"];
70 l10n.setup(["pt-BR"]);
71 expect(l10n.language).to.equal('pt-BR');
72 });
73 });
74});