]>
git.proxmox.com Git - mirror_novnc.git/blob - tests/test.localization.js
1 /* jshint expr: true */
3 var assert
= chai
.assert
;
4 var expect
= chai
.expect
;
6 import l10nGet
, { l10n
} from '../app/localization.js';
8 describe('Localization', function() {
11 describe('language selection', function () {
13 beforeEach(function () {
14 // window.navigator is a protected read-only property in many
15 // environments, so we need to redefine it whilst running these
17 origNavigator
= Object
.getOwnPropertyDescriptor(window
, "navigator");
18 if (origNavigator
=== undefined) {
19 // Object.getOwnPropertyDescriptor() doesn't work
20 // properly in any version of IE
24 Object
.defineProperty(window
, "navigator", {value
: {}});
25 if (window
.navigator
.languages
!== undefined) {
26 // Object.defineProperty() doesn't work properly in old
31 window
.navigator
.languages
= [];
33 afterEach(function () {
34 Object
.defineProperty(window
, "navigator", origNavigator
);
37 it('should use English by default', function() {
38 expect(l10n
.language
).to
.equal('en');
40 it('should use English if no user language matches', function() {
41 window
.navigator
.languages
= ["nl", "de"];
42 l10n
.setup(["es", "fr"]);
43 expect(l10n
.language
).to
.equal('en');
45 it('should use the most preferred user language', function() {
46 window
.navigator
.languages
= ["nl", "de", "fr"];
47 l10n
.setup(["es", "fr", "de"]);
48 expect(l10n
.language
).to
.equal('de');
50 it('should prefer sub-languages languages', function() {
51 window
.navigator
.languages
= ["pt-BR"];
52 l10n
.setup(["pt", "pt-BR"]);
53 expect(l10n
.language
).to
.equal('pt-BR');
55 it('should fall back to language "parents"', function() {
56 window
.navigator
.languages
= ["pt-BR"];
57 l10n
.setup(["fr", "pt", "de"]);
58 expect(l10n
.language
).to
.equal('pt');
60 it('should not use specific language when user asks for a generic language', function() {
61 window
.navigator
.languages
= ["pt", "de"];
62 l10n
.setup(["fr", "pt-BR", "de"]);
63 expect(l10n
.language
).to
.equal('de');
65 it('should handle underscore as a separator', function() {
66 window
.navigator
.languages
= ["pt-BR"];
67 l10n
.setup(["pt_BR"]);
68 expect(l10n
.language
).to
.equal('pt_BR');
70 it('should handle difference in case', function() {
71 window
.navigator
.languages
= ["pt-br"];
72 l10n
.setup(["pt-BR"]);
73 expect(l10n
.language
).to
.equal('pt-BR');