aboutsummaryrefslogtreecommitdiff
path: root/contexts/data/lib/closure-library/closure/goog/locale/countrylanguagenames_test.html
blob: 9507c393a1a27936873b79f760cdac818b711560 (plain)
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
<!DOCTYPE html>
<html>
<!--
Copyright 2006 The Closure Library Authors. All Rights Reserved.

Use of this source code is governed by the Apache License, Version 2.0.
See the COPYING file for details.
-->
<!--
-->
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Closure Unit Tests - goog.locale.LocaleNameConstants</title>
<!-- UTF-8 needed for character encoding -->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<script src="../base.js"></script>
<script>
  goog.require('goog.locale');
  goog.require('goog.locale.nativeNameConstants');
  goog.require('goog.testing.jsunit');
</script>
</head>
<body>
<script>

// Test data from //googledata/i18n/js_locale_data/LocaleNameConstants__de.js
var LocaleNameConstants_de = {
  LANGUAGE: {
    'cad': 'Caddo',
    'fr': 'Franz\u00f6sisch',
    'fr_CA': 'Canadian French',
    'fr_CH': 'Swiss French',    'zh': 'Chinesisch',
    'zh_Hans': 'Chinesisch (vereinfacht)',
    'zh_Hant': 'Chinesisch (traditionell)'
  },
  COUNTRY: {
    'CN': 'China',
    'ES': 'Spanien',
    'FR': 'Frankreich'
  }
};
registerLocalNameConstants(LocaleNameConstants_de, 'de');

// Test data from //googledata/i18n/js_locale_data/LocaleNameConstants__en.js
var LocaleNameConstants_en = {
  LANGUAGE: {
    'cad': 'Caddo',
    'fr': 'French',
    'fr_CA': 'Canadian French',
    'fr_CH': 'Swiss French',
    'zh': 'Chinese',
    'zh_Hans': 'Simplified Chinese',
    'zh_Hant': 'Traditional Chinese'
  },
  COUNTRY: {
    'CN': 'China',
    'ES': 'Spain',
    'FR': 'France'
  }
};
registerLocalNameConstants(LocaleNameConstants_en, 'en');

goog.locale.setLocale('de');

function testLoadLoacleSymbols() {
  var result = goog.locale.getLocalizedCountryName('fr-FR');
  assertEquals('Frankreich', result);
}

function testGetNativeCountryName() {
  var result = goog.locale.getNativeCountryName('de-DE');
  assertEquals('Deutschland', result);

  result = goog.locale.getNativeCountryName('de_DE');
  assertEquals('Deutschland', result);

  result = goog.locale.getNativeCountryName('und');
  assertEquals('und', result);

  result = goog.locale.getNativeCountryName('de-CH');
  assertEquals('Schweiz', result);

  result = goog.locale.getNativeCountryName('fr-CH');
  assertEquals('Suisse', result);

  result = goog.locale.getNativeCountryName('it-CH');
  assertEquals('Svizzera', result);
}

function testGetLocalizedCountryName() {
  var result = goog.locale.getLocalizedCountryName('es-ES');
  assertEquals('Spanien', result);

  result = goog.locale.getLocalizedCountryName('es-ES', LocaleNameConstants_en);
  assertEquals('Spain', result);

  result = goog.locale.getLocalizedCountryName('zh-CN-cmn');
  assertEquals('China', result);

  result = goog.locale.getLocalizedCountryName('zh_CN_cmn');
  assertEquals('China', result);

  // 'und' is a non-existing locale, default behavior is to
  // return the locale name itself if no mapping is found.
  result = goog.locale.getLocalizedCountryName('und');
  assertEquals('und', result);
}

function testGetNativeLanguageName() {
  var result = goog.locale.getNativeLanguageName('fr');
  assertEquals('fran\u00E7ais', result);

  result = goog.locale.getNativeLanguageName('fr-latn-FR');
  assertEquals('fran\u00E7ais', result);

  result = goog.locale.getNativeLanguageName('fr_FR');
  assertEquals('fran\u00E7ais', result);

  result = goog.locale.getNativeLanguageName('error');
  assertEquals('error', result);
}

function testGetLocalizedLanguageName() {
  var result = goog.locale.getLocalizedLanguageName('fr');
  assertEquals('Franz\u00F6sisch', result);

  result = goog.locale.getLocalizedLanguageName('fr',
                 LocaleNameConstants_en);
  assertEquals('French', result);

  result = goog.locale.getLocalizedLanguageName('fr-latn-FR');
  assertEquals('Franz\u00F6sisch', result);

  result = goog.locale.getLocalizedLanguageName('fr_FR');
  assertEquals('Franz\u00F6sisch', result);

  result = goog.locale.getLocalizedLanguageName('cad');
  assertEquals('Caddo', result);

  result = goog.locale.getLocalizedLanguageName('error');
  assertEquals('error', result);

  result = goog.locale.getLocalizedLanguageName('zh_Hans',
      LocaleNameConstants_en);
  assertEquals('Simplified Chinese', result);
}


function testGetLocalizedLanguageNameForGivenSymbolset() {
  var result = goog.locale.getLocalizedCountryName('fr-FR');
  assertEquals('Frankreich', result);

  result = goog.locale.getLocalizedCountryName(
      'fr-FR',
      LocaleNameConstants_en);
  assertEquals('France', result);

  result = goog.locale.getLocalizedCountryName('fr-FR');
  assertEquals('Frankreich', result);
}

/**
 * Valid combination of sub tags:
 *  1)  LanguageSubtag'-'RegionSubtag
 *  2)  LanguageSubtag'-'ScriptSubtag'-'RegionSubtag
 *  3)  LanguageSubtag'-'RegionSubtag'-'VariantSubtag
 *  4)  LanguageSubtag'-'ScriptSubTag'-'RegionSubtag'-'VariantSubtag
 */

function testGetRegionSubTag() {

  var result = goog.locale.getRegionSubTag('de-CH');
  assertEquals('CH',result);

  result = goog.locale.getRegionSubTag('de-latn-CH');
  assertEquals('CH',result);

  result = goog.locale.getRegionSubTag('de_latn_CH');
  assertEquals('CH',result);

  result = goog.locale.getRegionSubTag('de-CH-xxx');
  assertEquals('CH',result);

  result = goog.locale.getRegionSubTag('de-latn-CH-xxx');
  assertEquals('CH',result);

  result = goog.locale.getRegionSubTag('es-latn-419-xxx');
  assertEquals('419',result);

  result = goog.locale.getRegionSubTag('es_latn_419_xxx');
  assertEquals('419',result);

  // No region sub tag present
  result = goog.locale.getRegionSubTag('de');
  assertEquals('',result);
}

function testGetLanguageSubTag() {

  var result = goog.locale.getLanguageSubTag('de');
  assertEquals('de', result);

  result = goog.locale.getLanguageSubTag('de-DE');
  assertEquals('de', result);

  result = goog.locale.getLanguageSubTag('de-latn-DE-xxx');
  assertEquals('de', result);

  result = goog.locale.getLanguageSubTag('nds');
  assertEquals('nds', result);

  result = goog.locale.getLanguageSubTag('nds-DE');
  assertEquals('nds', result);
}

function testGetScriptSubTag() {

  var result = goog.locale.getScriptSubTag('fr');
  assertEquals('', result);

  result = goog.locale.getScriptSubTag('fr-Latn');
  assertEquals('Latn', result);

  result = goog.locale.getScriptSubTag('fr-Arab-AA');
  assertEquals('Arab', result);

  result = goog.locale.getScriptSubTag('de-Latin-DE');
  assertEquals('', result);

  result = goog.locale.getScriptSubTag('srn-Ar-DE');
  assertEquals('', result);
}

</script>
</body>
</html>