diff options
author | Vincent Petry <pvince81@owncloud.com> | 2014-11-19 19:02:17 +0300 |
---|---|---|
committer | Vincent Petry <pvince81@owncloud.com> | 2014-11-19 19:02:17 +0300 |
commit | ffe57d89e425771a5c027a3484d772319919d15d (patch) | |
tree | 5448803790f3ef015120cd6a3566ecaceddee2c3 /core | |
parent | 1c5933c96cd68f353165a02a76dd47760e8d493e (diff) |
Fix l10n promises
Diffstat (limited to 'core')
-rw-r--r-- | core/js/l10n.js | 9 | ||||
-rw-r--r-- | core/js/tests/specs/l10nSpec.js | 8 |
2 files changed, 11 insertions, 6 deletions
diff --git a/core/js/l10n.js b/core/js/l10n.js index 3e37da01369..0c660584322 100644 --- a/core/js/l10n.js +++ b/core/js/l10n.js @@ -37,10 +37,11 @@ OC.L10N = { load: function(appName, callback) { // already available ? if (this._bundles[appName] || OC.getLocale() === 'en') { - if (callback) { - callback(); - } - return; + var deferred = $.Deferred(); + var promise = deferred.promise(); + promise.then(callback); + deferred.resolve(); + return promise; } var self = this; diff --git a/core/js/tests/specs/l10nSpec.js b/core/js/tests/specs/l10nSpec.js index dc021a0baaf..cf7c8b11b1c 100644 --- a/core/js/tests/specs/l10nSpec.js +++ b/core/js/tests/specs/l10nSpec.js @@ -130,19 +130,23 @@ describe('OC.L10N tests', function() { localeStub.restore(); }); it('calls callback if translation already available', function() { + var promiseStub = sinon.stub(); var callbackStub = sinon.stub(); OC.L10N.register(TEST_APP, { 'Hello world!': 'Hallo Welt!' }); - OC.L10N.load(TEST_APP, callbackStub); + OC.L10N.load(TEST_APP, callbackStub).then(promiseStub); expect(callbackStub.calledOnce).toEqual(true); + expect(promiseStub.calledOnce).toEqual(true); expect(fakeServer.requests.length).toEqual(0); }); it('calls callback if locale is en', function() { var localeStub = sinon.stub(OC, 'getLocale').returns('en'); + var promiseStub = sinon.stub(); var callbackStub = sinon.stub(); - OC.L10N.load(TEST_APP, callbackStub); + OC.L10N.load(TEST_APP, callbackStub).then(promiseStub); expect(callbackStub.calledOnce).toEqual(true); + expect(promiseStub.calledOnce).toEqual(true); expect(fakeServer.requests.length).toEqual(0); }); }); |