diff options
author | Vincent Petry <pvince81@owncloud.com> | 2014-11-18 12:13:44 +0100 |
---|---|---|
committer | Vincent Petry <pvince81@owncloud.com> | 2014-11-18 12:20:01 +0100 |
commit | 152da9796b0268069a10b73d65781301a307fcdd (patch) | |
tree | 07a5087ff6fac5ccecc4d6547194578e1a305009 /core/js/l10n.js | |
parent | af7688ec17c260d3e227393e8e81438fe88b956c (diff) | |
download | nextcloud-server-152da9796b0268069a10b73d65781301a307fcdd.tar.gz nextcloud-server-152da9796b0268069a10b73d65781301a307fcdd.zip |
Added function to load translations from JS
For apps that support async translation loading, a new function
OC.L10N.load() can be used to asynchronously load the translations
for a given app.
Diffstat (limited to 'core/js/l10n.js')
-rw-r--r-- | core/js/l10n.js | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/core/js/l10n.js b/core/js/l10n.js index e375b7eca80..d091acea049 100644 --- a/core/js/l10n.js +++ b/core/js/l10n.js @@ -27,6 +27,47 @@ 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') { + if (callback) { + callback(); + } + return; + } + + var self = this; + var deferred = $.Deferred(); + var url = OC.generateUrl( + 'apps/{app}/l10n/{locale}.json', + {app: appName, locale: OC.getLocale()} + ); + + var url = OC.filePath(appName, 'l10n', OC.getLocale() + '.json'); + + // load JSON translation bundle per AJAX + $.get(url, + function(result) { + if (result.translations) { + self.register(appName, result.translations, result.pluralForm); + } + if (callback) { + callback(); + deferred.resolve(); + } + } + ); + return deferred.promise(); + }, + + /** * Register an app's translation bundle. * * @param {String} appName name of the app |