| OLD | NEW |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 | 248 |
| 249 return resolved; | 249 return resolved; |
| 250 } | 250 } |
| 251 | 251 |
| 252 | 252 |
| 253 /** | 253 /** |
| 254 * Returns best matched supported locale and extension info using basic | 254 * Returns best matched supported locale and extension info using basic |
| 255 * lookup algorithm. | 255 * lookup algorithm. |
| 256 */ | 256 */ |
| 257 function lookupMatcher(service, requestedLocales) { | 257 function lookupMatcher(service, requestedLocales) { |
| 258 native function NativeJSGetDefaultICULocale(); |
| 259 |
| 258 if (service.match(SERVICE_RE) === null) { | 260 if (service.match(SERVICE_RE) === null) { |
| 259 throw new Error('Internal error, wrong service type: ' + service); | 261 throw new Error('Internal error, wrong service type: ' + service); |
| 260 } | 262 } |
| 261 | 263 |
| 262 // Cache these, they don't ever change per service. | 264 // Cache these, they don't ever change per service. |
| 263 if (AVAILABLE_LOCALES[service] === undefined) { | 265 if (AVAILABLE_LOCALES[service] === undefined) { |
| 264 AVAILABLE_LOCALES[service] = getAvailableLocalesOf(service); | 266 AVAILABLE_LOCALES[service] = getAvailableLocalesOf(service); |
| 265 } | 267 } |
| 266 | 268 |
| 267 for (var i = 0; i < requestedLocales.length; ++i) { | 269 for (var i = 0; i < requestedLocales.length; ++i) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 278 var pos = locale.lastIndexOf('-'); | 280 var pos = locale.lastIndexOf('-'); |
| 279 if (pos === -1) { | 281 if (pos === -1) { |
| 280 break; | 282 break; |
| 281 } | 283 } |
| 282 locale = locale.substring(0, pos); | 284 locale = locale.substring(0, pos); |
| 283 } while (true); | 285 } while (true); |
| 284 } | 286 } |
| 285 | 287 |
| 286 // Didn't find a match, return default. | 288 // Didn't find a match, return default. |
| 287 if (DEFAULT_ICU_LOCALE === undefined) { | 289 if (DEFAULT_ICU_LOCALE === undefined) { |
| 288 DEFAULT_ICU_LOCALE = %GetDefaultICULocale(); | 290 DEFAULT_ICU_LOCALE = NativeJSGetDefaultICULocale(); |
| 289 } | 291 } |
| 290 | 292 |
| 291 return {'locale': DEFAULT_ICU_LOCALE, 'extension': '', 'position': -1}; | 293 return {'locale': DEFAULT_ICU_LOCALE, 'extension': '', 'position': -1}; |
| 292 } | 294 } |
| 293 | 295 |
| 294 | 296 |
| 295 /** | 297 /** |
| 296 * Returns best matched supported locale and extension info using | 298 * Returns best matched supported locale and extension info using |
| 297 * implementation dependend algorithm. | 299 * implementation dependend algorithm. |
| 298 */ | 300 */ |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 437 * It's sometimes desireable to leave user requested locale instead of ICU | 439 * It's sometimes desireable to leave user requested locale instead of ICU |
| 438 * supported one (zh-TW is equivalent to zh-Hant-TW, so we should keep shorter | 440 * supported one (zh-TW is equivalent to zh-Hant-TW, so we should keep shorter |
| 439 * one, if that was what user requested). | 441 * one, if that was what user requested). |
| 440 * This function returns user specified tag if its maximized form matches ICU | 442 * This function returns user specified tag if its maximized form matches ICU |
| 441 * resolved locale. If not we return ICU result. | 443 * resolved locale. If not we return ICU result. |
| 442 */ | 444 */ |
| 443 function getOptimalLanguageTag(original, resolved) { | 445 function getOptimalLanguageTag(original, resolved) { |
| 444 // Returns Array<Object>, where each object has maximized and base properties. | 446 // Returns Array<Object>, where each object has maximized and base properties. |
| 445 // Maximized: zh -> zh-Hans-CN | 447 // Maximized: zh -> zh-Hans-CN |
| 446 // Base: zh-CN-u-ca-gregory -> zh-CN | 448 // Base: zh-CN-u-ca-gregory -> zh-CN |
| 449 native function NativeJSGetLanguageTagVariants(); |
| 450 |
| 447 // Take care of grandfathered or simple cases. | 451 // Take care of grandfathered or simple cases. |
| 448 if (original === resolved) { | 452 if (original === resolved) { |
| 449 return original; | 453 return original; |
| 450 } | 454 } |
| 451 | 455 |
| 452 var locales = %GetLanguageTagVariants([original, resolved]); | 456 var locales = NativeJSGetLanguageTagVariants([original, resolved]); |
| 453 if (locales[0].maximized !== locales[1].maximized) { | 457 if (locales[0].maximized !== locales[1].maximized) { |
| 454 return resolved; | 458 return resolved; |
| 455 } | 459 } |
| 456 | 460 |
| 457 // Preserve extensions of resolved locale, but swap base tags with original. | 461 // Preserve extensions of resolved locale, but swap base tags with original. |
| 458 var resolvedBase = new RegExp('^' + locales[1].base); | 462 var resolvedBase = new RegExp('^' + locales[1].base); |
| 459 return resolved.replace(resolvedBase, locales[0].base); | 463 return resolved.replace(resolvedBase, locales[0].base); |
| 460 } | 464 } |
| 461 | 465 |
| 462 | 466 |
| 463 /** | 467 /** |
| 464 * Returns an Object that contains all of supported locales for a given | 468 * Returns an Object that contains all of supported locales for a given |
| 465 * service. | 469 * service. |
| 466 * In addition to the supported locales we add xx-ZZ locale for each xx-Yyyy-ZZ | 470 * In addition to the supported locales we add xx-ZZ locale for each xx-Yyyy-ZZ |
| 467 * that is supported. This is required by the spec. | 471 * that is supported. This is required by the spec. |
| 468 */ | 472 */ |
| 469 function getAvailableLocalesOf(service) { | 473 function getAvailableLocalesOf(service) { |
| 470 var available = %AvailableLocalesOf(service); | 474 native function NativeJSAvailableLocalesOf(); |
| 475 var available = NativeJSAvailableLocalesOf(service); |
| 471 | 476 |
| 472 for (var i in available) { | 477 for (var i in available) { |
| 473 if (available.hasOwnProperty(i)) { | 478 if (available.hasOwnProperty(i)) { |
| 474 var parts = i.match(/^([a-z]{2,3})-([A-Z][a-z]{3})-([A-Z]{2})$/); | 479 var parts = i.match(/^([a-z]{2,3})-([A-Z][a-z]{3})-([A-Z]{2})$/); |
| 475 if (parts !== null) { | 480 if (parts !== null) { |
| 476 // Build xx-ZZ. We don't care about the actual value, | 481 // Build xx-ZZ. We don't care about the actual value, |
| 477 // as long it's not undefined. | 482 // as long it's not undefined. |
| 478 available[parts[1] + '-' + parts[3]] = null; | 483 available[parts[1] + '-' + parts[3]] = null; |
| 479 } | 484 } |
| 480 } | 485 } |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 527 } | 532 } |
| 528 } | 533 } |
| 529 | 534 |
| 530 | 535 |
| 531 /** | 536 /** |
| 532 * Returns titlecased word, aMeRricA -> America. | 537 * Returns titlecased word, aMeRricA -> America. |
| 533 */ | 538 */ |
| 534 function toTitleCaseWord(word) { | 539 function toTitleCaseWord(word) { |
| 535 return word.substr(0, 1).toUpperCase() + word.substr(1).toLowerCase(); | 540 return word.substr(0, 1).toUpperCase() + word.substr(1).toLowerCase(); |
| 536 } | 541 } |
| OLD | NEW |