cram
Version:
An AMD-compatible build tool.
1 lines • 3.82 kB
JSON
{"absId":"curl/plugin/locale","url":"/Users/jhann/Projects/cram/test/examples/i18n/../../../amd_modules/curl/src/curl/plugin/locale.js","source":"/** MIT License (c) copyright 2010-2013 B Cavalier & J Hann */\n\n/**\n * curl locale! plugin\n *\n * This is a very light localization plugin that gets inserted into AMD bundles\n * by cram.js. Its functionality is nearly identical to the i18n! plugin.\n * The only difference of significance is that the locale! plugin initially\n * assumes that the module for the i18n strings is already loaded. If the\n * module is not loaded (and config.locale != false), it invokes the i18n!\n * plugin to fetch it and assemble it.\n *\n * You probably don't want to use this plugin directly. You likely want the\n * i18n! plugin. Just sayin.\n *\n */\ndefine(/*=='curl/plugin/locale',==*/ function () {\n\n\tvar appendLocaleRx;\n\n\t// finds the end and an optional .js extension since some devs may have\n\t// added it, which is legal since plugins sometimes require an extension.\n\tappendLocaleRx = /(\\.js)?$/;\n\n\tgetLocale['toModuleId'] = toModuleId;\n\tgetLocale['load'] = load;\n\n\treturn getLocale;\n\n\t/**\n\t * Sniffs the current locale. In environments that don't have\n\t * a global `window` object, no sniffing happens and false is returned.\n\t * You may also skip the sniffing by supplying an options.locale value.\n\t * @param {Object} [options]\n\t * @param {String|Boolean|Function} [options.locale] If a string, it is\n\t * assumed to be a locale override and is returned. If a strict false,\n\t * locale sniffing is skipped and false is returned. If a function, it is\n\t * called with the same signature as this function and the result returned.\n\t * @param {String} [absId] the normalized id sent to the i18n plugin.\n\t * @returns {String|Boolean}\n\t */\n\tfunction getLocale (options, absId) {\n\t\tvar locale, ci, lang;\n\n\t\tif (options) {\n\t\t\tlocale = options['locale'];\n\t\t\t// if locale is a function, use it to get the locale\n\t\t\tif (typeof locale == 'function') locale = locale(options, absId);\n\t\t\t// just return any pre-configured locale.\n\t\t\tif (typeof locale == 'string') return locale;\n\t\t}\n\n\t\t// bail if we're server-side\n\t\tif (typeof window == 'undefined') return false;\n\n\t\t// closure doesn't seem to know about recent DOM standards\n\t\tci = window['clientInformation'] || window.navigator;\n\t\tlang = ci && (ci.language || ci['userLanguage']) || '';\n\t\treturn lang.toLowerCase();\n\t}\n\n\tfunction toModuleId (defaultId, locale) {\n\t\tvar suffix = locale ? '/' + locale : '';\n\t\treturn defaultId.replace(appendLocaleRx, suffix + '$&');\n\t}\n\n\tfunction load (absId, require, loaded, config) {\n\t\tvar locale, toId, bundleId, defaultId;\n\n\t\t// figure out the locale and bundle to use\n\t\tlocale = getLocale(config, absId);\n\t\ttoId = config['localeToModuleId'] || toModuleId;\n\t\tbundleId = locale ? toId(absId, locale) : absId;\n\n\t\ttry {\n\t\t\t// try to get a bundle that's already loaded (sync require)\n\t\t\tloaded(require(bundleId));\n\t\t}\n\t\tcatch (ex) {\n\t\t\t// try default bundle sync (unless we've already tried it)\n\t\t\tdefaultId = locale ? toId(absId, false) : absId;\n\t\t\tif (defaultId == bundleId) return fail();\n\n\t\t\ttry {\n\t\t\t\tloaded(require(defaultId));\n\t\t\t}\n\t\t\tcatch (ex) {\n\t\t\t\t// locale === true, try to use the i18n plugin\n\t\t\t\tif (locale !== true) return fail();\n\t\t\t\trequire(['i18n!' + absId], loaded, fail);\n\t\t\t}\n\t\t}\n\n\t\tfunction fail () {\n\t\t\tvar ex = new Error('Unable to find correct locale for ' + absId);\n\t\t\tif (loaded.error) loaded.error(ex);\n\t\t\telse throw ex;\n\t\t}\n\t}\n\n});\n","modules":[{"pos":631,"count":49,"factory":true,"id":"curl/plugin/locale"}],"compileTime":"2014-03-14T13:48:58.104Z"}