diff options
Diffstat (limited to 'core/js/l10n.js')
-rw-r--r-- | core/js/l10n.js | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/core/js/l10n.js b/core/js/l10n.js index e375b7eca80..0c660584322 100644 --- a/core/js/l10n.js +++ b/core/js/l10n.js @@ -27,6 +27,38 @@ OC.L10N = { _pluralFunctions: {}, /** + * Load an app's translation bundle if not loaded already. + * + * @param {String} appName name of the app + * @param {Function} callback callback to be called when + * the translations are loaded + * @return {Promise} promise + */ + load: function(appName, callback) { + // already available ? + if (this._bundles[appName] || OC.getLocale() === 'en') { + var deferred = $.Deferred(); + var promise = deferred.promise(); + promise.then(callback); + deferred.resolve(); + return promise; + } + + var self = this; + var url = OC.filePath(appName, 'l10n', OC.getLocale() + '.json'); + + // load JSON translation bundle per AJAX + return $.get(url) + .then( + function(result) { + if (result.translations) { + self.register(appName, result.translations, result.pluralForm); + } + }) + .then(callback); + }, + + /** * Register an app's translation bundle. * * @param {String} appName name of the app |