intl-debug.js revision 628b3b052ecff4d1843c7e919951413fbc03e79f
d894ed8f7003b6c2ec19d5fb3969b6c45f0d7147Satyen Desai /* Loader/MetaData Touch Points
d894ed8f7003b6c2ec19d5fb3969b6c45f0d7147Satyen Desai a) _explodeLang()
d894ed8f7003b6c2ec19d5fb3969b6c45f0d7147Satyen Desai 1) Explode static meta-data "lang" property into first class modules
d894ed8f7003b6c2ec19d5fb3969b6c45f0d7147Satyen Desai var langModuleName = loader._formatLang(lang, module);
d894ed8f7003b6c2ec19d5fb3969b6c45f0d7147Satyen Desai b) _useLang(lang)
d894ed8f7003b6c2ec19d5fb3969b6c45f0d7147Satyen Desai Support for Y.use("lang:fr-CA"); or Y.use("lang:fr-CA;module");
d894ed8f7003b6c2ec19d5fb3969b6c45f0d7147Satyen Desai 1) Y.Intl.lookupBestLang(module, lang)
d894ed8f7003b6c2ec19d5fb3969b6c45f0d7147Satyen Desai 2) loader._formatLang(module, lang)
d894ed8f7003b6c2ec19d5fb3969b6c45f0d7147Satyen Desai 3) loader.insert(module_lang)
d894ed8f7003b6c2ec19d5fb3969b6c45f0d7147Satyen Desai 4) Y._attach(module_lang)
d894ed8f7003b6c2ec19d5fb3969b6c45f0d7147Satyen Desai c) getAvailableLangs(module)
d894ed8f7003b6c2ec19d5fb3969b6c45f0d7147Satyen Desai 1) Loop through meta-data for the module, to get available langs
d894ed8f7003b6c2ec19d5fb3969b6c45f0d7147Satyen Desai getAvailableLangs() support feasible?
d894ed8f7003b6c2ec19d5fb3969b6c45f0d7147Satyen Desai Loop through meta-data for all "loaded" modules, to get the common
d894ed8f7003b6c2ec19d5fb3969b6c45f0d7147Satyen Desai subset (could be presented as an app level dropdown for example).
d894ed8f7003b6c2ec19d5fb3969b6c45f0d7147Satyen Desai d) Register custom langs
d894ed8f7003b6c2ec19d5fb3969b6c45f0d7147Satyen Desai 1). Same as any module?
628b3b052ecff4d1843c7e919951413fbc03e79fSatyen Desai * The Intl utility provides a central location for managing language specific sets of strings and formatting patterns.
628b3b052ecff4d1843c7e919951413fbc03e79fSatyen Desai * @module intl
628b3b052ecff4d1843c7e919951413fbc03e79fSatyen Desai * The intl-load sub-module provides utilities for loader language support
628b3b052ecff4d1843c7e919951413fbc03e79fSatyen Desai * @module intl
628b3b052ecff4d1843c7e919951413fbc03e79fSatyen Desai * @submodule intl-load
628b3b052ecff4d1843c7e919951413fbc03e79fSatyen Desai * The Intl utility provides a central location for managing language specific sets of strings and formatting patterns.
628b3b052ecff4d1843c7e919951413fbc03e79fSatyen Desai * @class Intl
628b3b052ecff4d1843c7e919951413fbc03e79fSatyen Desai * Finds the best language match, from the list of available languages based on BCP 47 lookup.
d894ed8f7003b6c2ec19d5fb3969b6c45f0d7147Satyen Desai * @method lookupBestLang
628b3b052ecff4d1843c7e919951413fbc03e79fSatyen Desai * @param {String} lang The BCP 47 language tag to find the best match for
d894ed8f7003b6c2ec19d5fb3969b6c45f0d7147Satyen Desai * @param {Array} supportedLangs An array of supported langauge codes
628b3b052ecff4d1843c7e919951413fbc03e79fSatyen Desai * @return {String} The BCP 47 language tag
d894ed8f7003b6c2ec19d5fb3969b6c45f0d7147Satyen Desai lookupBestLang : function (preferredLanguages, availableLanguages) {
d894ed8f7003b6c2ec19d5fb3969b6c45f0d7147Satyen Desai // check whether the list of available languages contains language; if so return it
d894ed8f7003b6c2ec19d5fb3969b6c45f0d7147Satyen Desai for (i = 0; i < availableLanguages.length; i += 1) {
d894ed8f7003b6c2ec19d5fb3969b6c45f0d7147Satyen Desai if (language.toLowerCase() === availableLanguages[i].toLowerCase()) {
628b3b052ecff4d1843c7e919951413fbc03e79fSatyen Desai preferredLanguages = preferredLanguages.split(SPLIT_REGEX);
d894ed8f7003b6c2ec19d5fb3969b6c45f0d7147Satyen Desai for (i = 0; i < preferredLanguages.length; i += 1) {
d894ed8f7003b6c2ec19d5fb3969b6c45f0d7147Satyen Desai // check the fallback sequence for one language
d894ed8f7003b6c2ec19d5fb3969b6c45f0d7147Satyen Desai // one-character subtags get cut along with the following subtag
d894ed8f7003b6c2ec19d5fb3969b6c45f0d7147Satyen Desai if (index >= 2 && language.charAt(index - 2) === "-") {
d894ed8f7003b6c2ec19d5fb3969b6c45f0d7147Satyen Desai // nothing available for this language
628b3b052ecff4d1843c7e919951413fbc03e79fSatyen Desai _explodeLang : function() {
628b3b052ecff4d1843c7e919951413fbc03e79fSatyen Desai // LOADER STUB
628b3b052ecff4d1843c7e919951413fbc03e79fSatyen Desai // LOADER STUB
628b3b052ecff4d1843c7e919951413fbc03e79fSatyen Desai // META-DATA STUB
628b3b052ecff4d1843c7e919951413fbc03e79fSatyen Desai}, '@VERSION@' );
628b3b052ecff4d1843c7e919951413fbc03e79fSatyen Desai * The intl-lang sub-module adds the ability to store and retrieve multiple sets of language strings on the client.
628b3b052ecff4d1843c7e919951413fbc03e79fSatyen Desai * @module intl
628b3b052ecff4d1843c7e919951413fbc03e79fSatyen Desai * @submodule intl-lang
628b3b052ecff4d1843c7e919951413fbc03e79fSatyen Desai * The Intl utility provides a central location for managing language specific sets of strings and formatting patterns.
628b3b052ecff4d1843c7e919951413fbc03e79fSatyen Desai * @class Intl
628b3b052ecff4d1843c7e919951413fbc03e79fSatyen Desai * @method _mod
628b3b052ecff4d1843c7e919951413fbc03e79fSatyen Desai * @param {String} module The name of the module
628b3b052ecff4d1843c7e919951413fbc03e79fSatyen Desai * @return {Object} The hash of localized strings for the module, keyed by BCP language tag
628b3b052ecff4d1843c7e919951413fbc03e79fSatyen Desai * Sets the active language for the given module.
628b3b052ecff4d1843c7e919951413fbc03e79fSatyen Desai * Returns false on failure, which would happen if the language had not been registered through the <a href="#method_add">add()</a> method.
d894ed8f7003b6c2ec19d5fb3969b6c45f0d7147Satyen Desai * @method setLang
d894ed8f7003b6c2ec19d5fb3969b6c45f0d7147Satyen Desai * @param {String} module The module name.
628b3b052ecff4d1843c7e919951413fbc03e79fSatyen Desai * @param {String} lang The BCP 47 language tag.
628b3b052ecff4d1843c7e919951413fbc03e79fSatyen Desai this.fire("intl:langChange", {module: module, prevVal: currLang, newVal: lang});
d894ed8f7003b6c2ec19d5fb3969b6c45f0d7147Satyen Desai * Get the active language for the given module.
628b3b052ecff4d1843c7e919951413fbc03e79fSatyen Desai * @method getLang
d894ed8f7003b6c2ec19d5fb3969b6c45f0d7147Satyen Desai * @param {String} module The module name.
628b3b052ecff4d1843c7e919951413fbc03e79fSatyen Desai * @param {String} lang The BCP 47 language tag.
628b3b052ecff4d1843c7e919951413fbc03e79fSatyen Desai * @return {String} The current BCP 47 language tag.
d894ed8f7003b6c2ec19d5fb3969b6c45f0d7147Satyen Desai * Register a set of strings for the given module and language
d894ed8f7003b6c2ec19d5fb3969b6c45f0d7147Satyen Desai * @method add
d894ed8f7003b6c2ec19d5fb3969b6c45f0d7147Satyen Desai * @param {String} module The module name.
628b3b052ecff4d1843c7e919951413fbc03e79fSatyen Desai * @param {String} lang The BCP 47 language tag.
d894ed8f7003b6c2ec19d5fb3969b6c45f0d7147Satyen Desai * @param {Object} strings The hash of strings.
628b3b052ecff4d1843c7e919951413fbc03e79fSatyen Desai * Get the module strings for the given BCP language tag.
d894ed8f7003b6c2ec19d5fb3969b6c45f0d7147Satyen Desai * @method get
d894ed8f7003b6c2ec19d5fb3969b6c45f0d7147Satyen Desai * @param {String} module The module name.
d894ed8f7003b6c2ec19d5fb3969b6c45f0d7147Satyen Desai * @param {String} key Optional. If not provided, returns all strings, using merge to protect the originals.
628b3b052ecff4d1843c7e919951413fbc03e79fSatyen Desai * @param {String} lang Optional. The BCP 47 langauge tag.
d894ed8f7003b6c2ec19d5fb3969b6c45f0d7147Satyen Desai * @return String | Object
d894ed8f7003b6c2ec19d5fb3969b6c45f0d7147Satyen DesaiY.Intl.publish("intl:langChange", {emitFacade:true});
628b3b052ecff4d1843c7e919951413fbc03e79fSatyen DesaiYUI.add('intl', function(Y){}, '@VERSION@' ,{use:['intl-load', 'intl-lang']});