| 1 |
// Copyright 2006 The Closure Library Authors. All Rights Reserved. |
| 2 |
// |
| 3 |
// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
// you may not use this file except in compliance with the License. |
| 5 |
// You may obtain a copy of the License at |
| 6 |
// |
| 7 |
// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
// |
| 9 |
// Unless required by applicable law or agreed to in writing, software |
| 10 |
// distributed under the License is distributed on an "AS-IS" BASIS, |
| 11 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 |
// See the License for the specific language governing permissions and |
| 13 |
// limitations under the License. |
| 14 |
|
| 15 |
goog.provide('goog.locale.countryLanguageNamesTest'); |
| 16 |
goog.setTestOnly('goog.locale.countryLanguageNamesTest'); |
| 17 |
|
| 18 |
goog.require('goog.locale'); |
| 19 |
goog.require('goog.testing.jsunit'); |
| 20 |
|
| 21 |
var LocaleNameConstants_en; |
| 22 |
|
| 23 |
function setUpPage() { |
| 24 |
// Test data from //googledata/i18n/js_locale_data/LocaleNameConstants__de.js |
| 25 |
var LocaleNameConstants_de = { |
| 26 |
LANGUAGE: { |
| 27 |
'cad': 'Caddo', |
| 28 |
'fr': 'Franz\u00f6sisch', |
| 29 |
'fr_CA': 'Canadian French', |
| 30 |
'fr_CH': 'Swiss French', |
| 31 |
'zh': 'Chinesisch', |
| 32 |
'zh_Hans': 'Chinesisch (vereinfacht)', |
| 33 |
'zh_Hant': 'Chinesisch (traditionell)' |
| 34 |
}, |
| 35 |
COUNTRY: {'CN': 'China', 'ES': 'Spanien', 'FR': 'Frankreich'} |
| 36 |
}; |
| 37 |
registerLocalNameConstants(LocaleNameConstants_de, 'de'); |
| 38 |
|
| 39 |
// Test data from //googledata/i18n/js_locale_data/LocaleNameConstants__en.js |
| 40 |
LocaleNameConstants_en = { |
| 41 |
LANGUAGE: { |
| 42 |
'cad': 'Caddo', |
| 43 |
'fr': 'French', |
| 44 |
'fr_CA': 'Canadian French', |
| 45 |
'fr_CH': 'Swiss French', |
| 46 |
'zh': 'Chinese', |
| 47 |
'zh_Hans': 'Simplified Chinese', |
| 48 |
'zh_Hant': 'Traditional Chinese' |
| 49 |
}, |
| 50 |
COUNTRY: {'CN': 'China', 'ES': 'Spain', 'FR': 'France'} |
| 51 |
}; |
| 52 |
registerLocalNameConstants(LocaleNameConstants_en, 'en'); |
| 53 |
|
| 54 |
goog.locale.setLocale('de'); |
| 55 |
} |
| 56 |
|
| 57 |
function testLoadLoacleSymbols() { |
| 58 |
var result = goog.locale.getLocalizedCountryName('fr-FR'); |
| 59 |
assertEquals('Frankreich', result); |
| 60 |
} |
| 61 |
|
| 62 |
function testGetNativeCountryName() { |
| 63 |
var result = goog.locale.getNativeCountryName('de-DE'); |
| 64 |
assertEquals('Deutschland', result); |
| 65 |
|
| 66 |
result = goog.locale.getNativeCountryName('de_DE'); |
| 67 |
assertEquals('Deutschland', result); |
| 68 |
|
| 69 |
result = goog.locale.getNativeCountryName('und'); |
| 70 |
assertEquals('und', result); |
| 71 |
|
| 72 |
result = goog.locale.getNativeCountryName('de-CH'); |
| 73 |
assertEquals('Schweiz', result); |
| 74 |
|
| 75 |
result = goog.locale.getNativeCountryName('fr-CH'); |
| 76 |
assertEquals('Suisse', result); |
| 77 |
|
| 78 |
result = goog.locale.getNativeCountryName('it-CH'); |
| 79 |
assertEquals('Svizzera', result); |
| 80 |
} |
| 81 |
|
| 82 |
function testGetLocalizedCountryName() { |
| 83 |
var result = goog.locale.getLocalizedCountryName('es-ES'); |
| 84 |
assertEquals('Spanien', result); |
| 85 |
|
| 86 |
result = goog.locale.getLocalizedCountryName('es-ES', LocaleNameConstants_en); |
| 87 |
assertEquals('Spain', result); |
| 88 |
|
| 89 |
result = goog.locale.getLocalizedCountryName('zh-CN-cmn'); |
| 90 |
assertEquals('China', result); |
| 91 |
|
| 92 |
result = goog.locale.getLocalizedCountryName('zh_CN_cmn'); |
| 93 |
assertEquals('China', result); |
| 94 |
|
| 95 |
// 'und' is a non-existing locale, default behavior is to |
| 96 |
// return the locale name itself if no mapping is found. |
| 97 |
result = goog.locale.getLocalizedCountryName('und'); |
| 98 |
assertEquals('und', result); |
| 99 |
} |
| 100 |
|
| 101 |
|
| 102 |
function testGetLocalizedRegionNameFromRegionCode() { |
| 103 |
var result = goog.locale.getLocalizedRegionNameFromRegionCode('ES'); |
| 104 |
assertEquals('Spanien', result); |
| 105 |
|
| 106 |
result = goog.locale.getLocalizedRegionNameFromRegionCode( |
| 107 |
'ES', LocaleNameConstants_en); |
| 108 |
assertEquals('Spain', result); |
| 109 |
|
| 110 |
result = goog.locale.getLocalizedRegionNameFromRegionCode('CN'); |
| 111 |
assertEquals('China', result); |
| 112 |
|
| 113 |
// 'XX' is a non-existing country code, default behavior is to |
| 114 |
// return the code itself if no mapping is found. |
| 115 |
result = goog.locale.getLocalizedRegionNameFromRegionCode('XX'); |
| 116 |
assertEquals('XX', result); |
| 117 |
} |
| 118 |
|
| 119 |
function testGetNativeLanguageName() { |
| 120 |
var result = goog.locale.getNativeLanguageName('fr'); |
| 121 |
assertEquals('fran\u00E7ais', result); |
| 122 |
|
| 123 |
result = goog.locale.getNativeLanguageName('fr-latn-FR'); |
| 124 |
assertEquals('fran\u00E7ais', result); |
| 125 |
|
| 126 |
result = goog.locale.getNativeLanguageName('fr_FR'); |
| 127 |
assertEquals('fran\u00E7ais', result); |
| 128 |
|
| 129 |
result = goog.locale.getNativeLanguageName('error'); |
| 130 |
assertEquals('error', result); |
| 131 |
} |
| 132 |
|
| 133 |
function testGetLocalizedLanguageName() { |
| 134 |
var result = goog.locale.getLocalizedLanguageName('fr'); |
| 135 |
assertEquals('Franz\u00F6sisch', result); |
| 136 |
|
| 137 |
result = goog.locale.getLocalizedLanguageName('fr', LocaleNameConstants_en); |
| 138 |
assertEquals('French', result); |
| 139 |
|
| 140 |
result = goog.locale.getLocalizedLanguageName('fr-latn-FR'); |
| 141 |
assertEquals('Franz\u00F6sisch', result); |
| 142 |
|
| 143 |
result = goog.locale.getLocalizedLanguageName('fr_FR'); |
| 144 |
assertEquals('Franz\u00F6sisch', result); |
| 145 |
|
| 146 |
result = goog.locale.getLocalizedLanguageName('cad'); |
| 147 |
assertEquals('Caddo', result); |
| 148 |
|
| 149 |
result = goog.locale.getLocalizedLanguageName('error'); |
| 150 |
assertEquals('error', result); |
| 151 |
|
| 152 |
result = |
| 153 |
goog.locale.getLocalizedLanguageName('zh_Hans', LocaleNameConstants_en); |
| 154 |
assertEquals('Simplified Chinese', result); |
| 155 |
} |
| 156 |
|
| 157 |
|
| 158 |
function testGetLocalizedLanguageNameForGivenSymbolset() { |
| 159 |
var result = goog.locale.getLocalizedCountryName('fr-FR'); |
| 160 |
assertEquals('Frankreich', result); |
| 161 |
|
| 162 |
result = goog.locale.getLocalizedCountryName('fr-FR', LocaleNameConstants_en); |
| 163 |
assertEquals('France', result); |
| 164 |
|
| 165 |
result = goog.locale.getLocalizedCountryName('fr-FR'); |
| 166 |
assertEquals('Frankreich', result); |
| 167 |
} |
| 168 |
|
| 169 |
/** |
| 170 |
* Valid combination of sub tags: |
| 171 |
* 1) LanguageSubtag'-'RegionSubtag |
| 172 |
* 2) LanguageSubtag'-'ScriptSubtag'-'RegionSubtag |
| 173 |
* 3) LanguageSubtag'-'RegionSubtag'-'VariantSubtag |
| 174 |
* 4) LanguageSubtag'-'ScriptSubTag'-'RegionSubtag'-'VariantSubtag |
| 175 |
*/ |
| 176 |
|
| 177 |
function testGetRegionSubTag() { |
| 178 |
var result = goog.locale.getRegionSubTag('de-CH'); |
| 179 |
assertEquals('CH', result); |
| 180 |
|
| 181 |
result = goog.locale.getRegionSubTag('de-latn-CH'); |
| 182 |
assertEquals('CH', result); |
| 183 |
|
| 184 |
result = goog.locale.getRegionSubTag('de_latn_CH'); |
| 185 |
assertEquals('CH', result); |
| 186 |
|
| 187 |
result = goog.locale.getRegionSubTag('de-CH-xxx'); |
| 188 |
assertEquals('CH', result); |
| 189 |
|
| 190 |
result = goog.locale.getRegionSubTag('de-latn-CH-xxx'); |
| 191 |
assertEquals('CH', result); |
| 192 |
|
| 193 |
result = goog.locale.getRegionSubTag('es-latn-419-xxx'); |
| 194 |
assertEquals('419', result); |
| 195 |
|
| 196 |
result = goog.locale.getRegionSubTag('es_latn_419_xxx'); |
| 197 |
assertEquals('419', result); |
| 198 |
|
| 199 |
// No region sub tag present |
| 200 |
result = goog.locale.getRegionSubTag('de'); |
| 201 |
assertEquals('', result); |
| 202 |
} |
| 203 |
|
| 204 |
function testGetLanguageSubTag() { |
| 205 |
var result = goog.locale.getLanguageSubTag('de'); |
| 206 |
assertEquals('de', result); |
| 207 |
|
| 208 |
result = goog.locale.getLanguageSubTag('de-DE'); |
| 209 |
assertEquals('de', result); |
| 210 |
|
| 211 |
result = goog.locale.getLanguageSubTag('de-latn-DE-xxx'); |
| 212 |
assertEquals('de', result); |
| 213 |
|
| 214 |
result = goog.locale.getLanguageSubTag('nds'); |
| 215 |
assertEquals('nds', result); |
| 216 |
|
| 217 |
result = goog.locale.getLanguageSubTag('nds-DE'); |
| 218 |
assertEquals('nds', result); |
| 219 |
} |
| 220 |
|
| 221 |
function testGetScriptSubTag() { |
| 222 |
var result = goog.locale.getScriptSubTag('fr'); |
| 223 |
assertEquals('', result); |
| 224 |
|
| 225 |
result = goog.locale.getScriptSubTag('fr-Latn'); |
| 226 |
assertEquals('Latn', result); |
| 227 |
|
| 228 |
result = goog.locale.getScriptSubTag('fr-Arab-AA'); |
| 229 |
assertEquals('Arab', result); |
| 230 |
|
| 231 |
result = goog.locale.getScriptSubTag('de-Latin-DE'); |
| 232 |
assertEquals('', result); |
| 233 |
|
| 234 |
result = goog.locale.getScriptSubTag('srn-Ar-DE'); |
| 235 |
assertEquals('', result); |
| 236 |
} |