IntlLoad.js revision 628b3b052ecff4d1843c7e919951413fbc03e79f
10139N/A
10139N/A /* Loader/MetaData Touch Points
13740N/A
10139N/A a) _explodeLang()
10139N/A
10139N/A 1) Explode static meta-data "lang" property into first class modules
10139N/A
10139N/A var langModuleName = loader._formatLang(lang, module);
10139N/A
10139N/A b) _useLang(lang)
10139N/A
10139N/A Support for Y.use("lang:fr-CA"); or Y.use("lang:fr-CA;module");
10139N/A
10139N/A 1) Y.Intl.lookupBestLang(module, lang)
10139N/A
10139N/A 2) loader._formatLang(module, lang)
10139N/A 3) loader.insert(module_lang)
10139N/A
10139N/A 4) Y._attach(module_lang)
10139N/A
10139N/A c) getAvailableLangs(module)
10139N/A
10139N/A 1) Loop through meta-data for the module, to get available langs
10139N/A
10139N/A getAvailableLangs() support feasible?
10139N/A
10139N/A Loop through meta-data for all "loaded" modules, to get the common
10139N/A subset (could be presented as an app level dropdown for example).
10139N/A
10139N/A d) Register custom langs
10139N/A
10139N/A 1). Same as any module?
10139N/A
10139N/A */
10139N/A
11904N/A/**
10139N/A * The Intl utility provides a central location for managing language specific sets of strings and formatting patterns.
10139N/A * @module intl
10139N/A */
10139N/A
10139N/A/**
10139N/A * The intl-load sub-module provides utilities for loader language support
10139N/A *
10139N/A * @module intl
10139N/A * @submodule intl-load
10139N/A */
10139N/A
10139N/A/**
10139N/A * The Intl utility provides a central location for managing language specific sets of strings and formatting patterns.
11904N/A *
10139N/A * @class Intl
10139N/A * @static
10139N/A */
10139N/A
10139N/Avar SPLIT_REGEX = /[, ]/;
10139N/A
10139N/AY.mix(Y.namespace("Intl"), {
10139N/A
10139N/A /**
10139N/A * Finds the best language match, from the list of available languages based on BCP 47 lookup.
10139N/A *
10139N/A * @method lookupBestLang
10139N/A * @param {String} lang The BCP 47 language tag to find the best match for
10139N/A * @param {Array} supportedLangs An array of supported langauge codes
10139N/A *
10139N/A * @return {String} The BCP 47 language tag
10139N/A */
10139N/A lookupBestLang : function (preferredLanguages, availableLanguages) {
10139N/A
10139N/A var i, language, result, index;
10139N/A
10139N/A // check whether the list of available languages contains language; if so return it
10139N/A function scan(language) {
10139N/A var i;
10139N/A for (i = 0; i < availableLanguages.length; i += 1) {
10139N/A if (language.toLowerCase() === availableLanguages[i].toLowerCase()) {
11904N/A return availableLanguages[i];
11904N/A }
11904N/A }
11904N/A }
11904N/A
11904N/A if (Y.Lang.isString(preferredLanguages)) {
10139N/A preferredLanguages = preferredLanguages.split(SPLIT_REGEX);
10139N/A }
10139N/A
10139N/A for (i = 0; i < preferredLanguages.length; i += 1) {
10139N/A language = preferredLanguages[i];
10139N/A if (!language || language === "*") {
10139N/A continue;
10139N/A }
10139N/A // check the fallback sequence for one language
10139N/A while (language.length > 0) {
10139N/A result = scan(language);
10139N/A if (result) {
10139N/A return result;
10139N/A } else {
10139N/A index = language.lastIndexOf("-");
10139N/A if (index >= 0) {
10139N/A language = language.substring(0, index);
10139N/A // one-character subtags get cut along with the following subtag
10139N/A if (index >= 2 && language.charAt(index - 2) === "-") {
10139N/A language = language.substring(0, index - 2);
10139N/A }
10139N/A } else {
10139N/A // nothing available for this language
10139N/A break;
10139N/A }
10139N/A }
10139N/A }
10139N/A }
10139N/A
10139N/A return "";
10139N/A },
10139N/A
10139N/A _explodeLang : function() {
10139N/A // LOADER STUB
10139N/A },
10139N/A
18745N/A _useLang : function(module, lang) {
10139N/A // LOADER STUB
10139N/A },
11925N/A
10139N/A getAvailableLangs : function(module) {
10139N/A // META-DATA STUB
10139N/A }
10139N/A});