Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

better handling of shared/global language bundles

  • Loading branch information...
commit a97a69d2a949dd7c4f880ac37182021ab903c61c 1 parent 86ce91d
@drewfish authored
Showing with 41 additions and 21 deletions.
  1. +41 −21 lib/app/addons/rs/yui.server.js
View
62 lib/app/addons/rs/yui.server.js
@@ -192,12 +192,27 @@ YUI.add('addon-rs-yui', function(Y, NAME) {
}
if (fs.basename === mojitType) {
res.yui.lang = '';
+ res.yui.langFor = mojitType;
} else if (mojitType === fs.basename.substr(0, mojitType.length)) {
res.yui.lang = fs.basename.substr(mojitType.length + 1);
+ res.yui.langFor = mojitType;
+ } else if ('shared' === mojitType) {
+ // Supporting global (AKA shared) language bundles isn't
+ // really supported, since it's tricky to determine the
+ // language name from the filename. The hack below is a
+ // quick but restrictive way to do that.
+ var parts = fs.basename.split('_');
+ res.yui.lang = '';
+ res.yui.langFor = fs.basename;
+ if (parts.length > 1) {
+ res.yui.lang = parts.pop();
+ res.yui.langFor = parts.join('_');
+ }
} else {
Y.log('invalid YUI lang file format. skipping ' + fs.fullPath, 'error', NAME);
}
- res.name = res.yui.lang;
+ this._captureYUIModuleDetails(res);
+ res.name = res.yui.name;
res.id = [res.type, res.subtype, res.name].join('-');
return new Y.Do.Halt(null, res);
}
@@ -332,12 +347,10 @@ YUI.add('addon-rs-yui', function(Y, NAME) {
ress = evt.ress,
r,
res,
- langs = {},
+ langRess = {}, // YUI module name: language: resource
l,
- ll,
- lang,
langName,
- langNames,
+ langNames = {},
langSorted,
viewEngineRequired = {},
modules = {},
@@ -369,7 +382,11 @@ YUI.add('addon-rs-yui', function(Y, NAME) {
viewEngineRequired[res.yui.name] = true;
}
if ('yui-lang' === res.type) {
- langs[res.name] = res;
+ langNames[res.yui.lang] = true;
+ if (!langRess[res.yui.langFor]) {
+ langRess[res.yui.langFor] = {};
+ }
+ langRess[res.yui.langFor][res.yui.lang] = res;
}
if (res.yui && res.yui.name) {
modules[res.yui.name] = this._makeYUIModuleConfig(env, res);
@@ -394,10 +411,8 @@ YUI.add('addon-rs-yui', function(Y, NAME) {
this.modules[env][poslKey][mojit] = Y.mojito.util.copy(modules);
// we always want to do calculations for no-lang
- if (!langs['']) {
- langs[''] = undefined;
- }
- langNames = Object.keys(langs);
+ langNames[''] = true;
+ langNames = Object.keys(langNames);
if (controller) {
required = { 'mojito-dispatcher': true };
@@ -409,12 +424,10 @@ YUI.add('addon-rs-yui', function(Y, NAME) {
for (l = 0; l < langNames.length; l += 1) {
langName = langNames[l];
- lang = langs[langName];
langSorted = Y.mojito.util.copy(sorted);
- this._addLangToSorted(env, langSorted, lang);
+ this._addLangsToSorted(env, langSorted, langName, langRess);
this._setYUIDependencies(env, poslKey, langName, controller.yui.name, langSorted);
}
-
}
if ('client' === env) {
for (binderName in binders) {
@@ -428,9 +441,8 @@ YUI.add('addon-rs-yui', function(Y, NAME) {
sorted = this._precomputeYUIDependencies(langName, env, mojit, modules, required);
for (l = 0; l < langNames.length; l += 1) {
langName = langNames[l];
- lang = langs[langName];
langSorted = Y.mojito.util.copy(sorted);
- this._addLangToSorted(env, langSorted, lang);
+ this._addLangsToSorted(env, langSorted, langName, langRess);
this._setYUIDependencies(env, poslKey, langName, binder.yui.name, langSorted);
}
}
@@ -643,16 +655,24 @@ YUI.add('addon-rs-yui', function(Y, NAME) {
* about the language.
*
* @private
- * @method _addLangToSorted
+ * @method _addLangsToSorted
* @param {string} env runtime environment (either `client`, or `server`)
* @param {object} sorted results of _precomputeYUIDependencies()
- * @param {object} langRes resource representing the language bundle
+ * @param {string} langName which language to add
+ * @param {object} langRess resources representing the language bundle
* @return {nothing} results are added to the `sorted` parameter
*/
- _addLangToSorted: function(env, sorted, langRes) {
- if (langRes) {
- sorted.sorted.push(langRes.yui.name);
- sorted.paths[langRes.yui.name] = ('client' === env) ? langRes.url : langRes.source.fs.fullPath;
+ _addLangsToSorted: function(env, sorted, langName, langRess) {
+ var modName,
+ langRes;
+ for (modName in langRess) {
+ if (langRess.hasOwnProperty(modName)) {
+ langRes = langRess[modName][langName] || langRess[modName][''];
+ if (langRes) {
+ sorted.sorted.push(langRes.yui.name);
+ sorted.paths[langRes.yui.name] = ('client' === env) ? langRes.url : langRes.source.fs.fullPath;
+ }
+ }
}
if (!sorted.paths.intl) {
sorted.sorted.unshift('intl');
Please sign in to comment.
Something went wrong with that request. Please try again.