Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Point out correct config. Fetch specific locale bundles instead of the d... #210

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/curl/cram/i18n.js
Expand Up @@ -28,20 +28,25 @@ define(['../plugin/i18n', '../plugin/locale'], function (i18n, getLocale) {

bundleToString.compile = function (pluginId, resId, req, io, config) {
var i18nId, localeId, locales, output, count, toId;

i18nId = pluginId + '!' + resId;
localeId = 'locale!' + resId;
locales = config.locales || [];
locales.push(''); // default bundle
// Only add defaule bundle once;
if (locales.indexOf('') === -1 ) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Watch out for this too!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

o i c! If your locales is ['', 'fr', 'fr-fr'] then you don't want to add '' twice?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was actually if you have multiple i18n modules. The plugin would be run multiple times and append '' to locales each time so you'd get:

locale: ['en', 'en-us', '']
locale: ['en', 'en-us', '', '']
locale: ['en', 'en-us', '', '', '']
...

locales.push(''); // default bundle
}
output = [];
count = locales.length;
toId = config['localeToModuleId'] || getLocale.toModuleId;

// use the load method of the run-time plugin, capturing bundles.
locales.forEach(function (locale, i) {

var i18nIdLocale = i18nId;
if (locale) i18nIdLocale += '/' + locale;

loaded.error = stop;
i18n.load(i18nId, req, loaded, config);
i18n.load(i18nIdLocale, req, loaded, config);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try this instead: i18n.load(toId(i18nId, locale), req, loaded, config);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I made this change locally.


function loaded (bundle) {
// each bundle captured is output as a locale!id module, e.g.:
Expand Down