Skip to content

Commit 1b5e274

Browse files
committed
Merge branch 'v2' of github.com:gadicohen/meteor-messageformat into v2
2 parents 880942b + d638c18 commit 1b5e274

File tree

3 files changed

+39
-6
lines changed

3 files changed

+39
-6
lines changed

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,21 @@ msgfmt.init('en', {
9090
});
9191
```
9292

93+
## Cordova
94+
95+
There's an issue with the inject-initial package under Cordova which causes information to not be properly hooked to the client. To counter this, you may define the locales of the application in the settings file, under the public element.
96+
```json
97+
{
98+
"public": {
99+
...,
100+
"msgfmt": {
101+
"native": "en",
102+
"locales": ["en", "fr"]
103+
}
104+
}
105+
}
106+
```
107+
93108
### Debug logging
94109

95110
`Logger.setLevel('msgfmt', 'trace');`

msgfmt:core/lib/mfPkg/messageformat-client.js

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ function fetchLocale(locale) {
181181
locale = 'all';
182182

183183
unique = locale + '/' + (mfPkg.lastSync[locale] || 0);
184-
url = '/msgfmt/locale/' + unique;
184+
url = Meteor.absoluteUrl('msgfmt/locale/' + unique);
185185
log.debug('fetchLocale request for "' + locale + '", url: ' + url);
186186
times.fetches[unique] = Date.now();
187187

@@ -395,9 +395,26 @@ mfPkg.resetStorage = function() {
395395
/* code below involves loading the actual module at long time */
396396

397397
var injected = Injected.obj('msgfmt');
398-
mfPkg.timestamps = injected && injected.locales;
399-
mfPkg.native = injected.native;
400-
mfPkg.sendPolicy = injected.sendPolicy;
398+
if (injected) {
399+
mfPkg.native = injected.native;
400+
mfPkg.sendPolicy = injected.sendPolicy;
401+
mfPkg.timestamps = injected.locales;
402+
} else {
403+
log.debug('Injected object was undefined, this is most likely a Cordova session');
404+
mfPkg.timestamps = {};
405+
var time = (new Date()).getTime();
406+
if (Meteor.settings && Meteor.settings.public && Meteor.settings.public.msgfmt) {
407+
var msgfmtSettings = Meteor.settings.public.msgfmt;
408+
mfPkg.native = msgfmtSettings.native;
409+
_.each(msgfmtSettings.locales, function(locale) {
410+
mfPkg.timestamps[locale] = time;
411+
});
412+
} else {
413+
log.warn('Cordova builds have issues with the inject-initial package, make sure to define settings keys public.localization.native && public.localization.locales');
414+
mfPkg.native = injected.native;
415+
mfPkg.timestamps[mfPkg.native] = time;
416+
}
417+
}
401418

402419
if (mfPkg.timestamps) {
403420
(function() {
@@ -437,7 +454,8 @@ if (locale) {
437454
} else if (locale = Session.get('locale')) {
438455
log.debug('Found session locale "' + locale + '"');
439456
mfPkg.setLocale(locale);
440-
} else if (locale = injected.headerLocale) {
457+
} else if (injected && injected.headerLocale) {
458+
locale = injected.headerLocale
441459
log.debug('Setting locale from header: ' + locale);
442460
mfPkg.setLocale(locale);
443461
} else {

msgfmt:core/package.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Package.onUse(function (api) {
2222
'underscore',
2323
'ddp',
2424
'mongo@1.0.4',
25-
'meteorhacks:inject-initial@1.0.2',
25+
'meteorhacks:inject-initial@1.0.3',
2626
'jag:pince@0.0.6',
2727
'raix:eventemitter@0.1.2'
2828
], both);

0 commit comments

Comments
 (0)