Merge pull request #2608 from emanuelschuetze/issue-2339

Load angular-gettext language files from plugin (Fixed #2339)
This commit is contained in:
Emanuel Schütze 2016-11-10 13:00:53 +01:00 committed by GitHub
commit 22ab7a15a3
1 changed files with 46 additions and 1 deletions

View File

@ -108,7 +108,8 @@ angular.module('OpenSlidesApp.core', [
.factory('Languages', [
'gettext',
'gettextCatalog',
function (gettext, gettextCatalog) {
'OpenSlidesPlugins',
function (gettext, gettextCatalog, OpenSlidesPlugins) {
return {
// get all available languages
getLanguages: function () {
@ -144,6 +145,7 @@ angular.module('OpenSlidesApp.core', [
// set current language and return updated languages object array
setCurrentLanguage: function (lang) {
var languages = this.getLanguages();
var plugins = OpenSlidesPlugins.getAll();
angular.forEach(languages, function (language) {
language.selected = false;
if (language.code == lang) {
@ -151,6 +153,12 @@ angular.module('OpenSlidesApp.core', [
gettextCatalog.setCurrentLanguage(lang);
if (lang != 'en') {
gettextCatalog.loadRemote("static/i18n/" + lang + ".json");
// load language files from plugins
angular.forEach(plugins, function (plugin) {
if (plugin.languages.indexOf(lang) != -1) {
gettextCatalog.loadRemote("static/i18n/" + plugin.name + '/' + lang + ".json");
}
});
}
}
});
@ -460,6 +468,43 @@ angular.module('OpenSlidesApp.core', [
}
])
/*
* Provides a function for plugins to register as new plugin.
*
* Get all registerd plugins via 'OpenSlidesPlugins.getAll()'.
*
* Example code for plugins:
*
* .config([
* 'OpenSlidesPluginsProvider',
* function(OpenSlidesPluginsProvider) {
* OpenSlidesPluginsProvider.registerPlugin({
* name: 'openslides_votecollector',
* display_name: 'VoteCollector',
* languages: ['de']
* });
* }
* ])
*/
.provider('OpenSlidesPlugins', [
function () {
var provider = this;
provider.plugins = [];
provider.registerPlugin = function (plugin) {
provider.plugins.push(plugin);
};
provider.$get = [
function () {
return {
getAll: function () {
return provider.plugins;
}
};
}
];
}
])
// Options for TinyMCE editor used in various create and edit views.
// Required in core/base.js because MotionComment factory which used this
// factory has to placed in motions/base.js.