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

View File

@ -108,7 +108,8 @@ angular.module('OpenSlidesApp.core', [
.factory('Languages', [ .factory('Languages', [
'gettext', 'gettext',
'gettextCatalog', 'gettextCatalog',
function (gettext, gettextCatalog) { 'OpenSlidesPlugins',
function (gettext, gettextCatalog, OpenSlidesPlugins) {
return { return {
// get all available languages // get all available languages
getLanguages: function () { getLanguages: function () {
@ -144,6 +145,7 @@ angular.module('OpenSlidesApp.core', [
// set current language and return updated languages object array // set current language and return updated languages object array
setCurrentLanguage: function (lang) { setCurrentLanguage: function (lang) {
var languages = this.getLanguages(); var languages = this.getLanguages();
var plugins = OpenSlidesPlugins.getAll();
angular.forEach(languages, function (language) { angular.forEach(languages, function (language) {
language.selected = false; language.selected = false;
if (language.code == lang) { if (language.code == lang) {
@ -151,6 +153,12 @@ angular.module('OpenSlidesApp.core', [
gettextCatalog.setCurrentLanguage(lang); gettextCatalog.setCurrentLanguage(lang);
if (lang != 'en') { if (lang != 'en') {
gettextCatalog.loadRemote("static/i18n/" + lang + ".json"); 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. // Options for TinyMCE editor used in various create and edit views.
// Required in core/base.js because MotionComment factory which used this // Required in core/base.js because MotionComment factory which used this
// factory has to placed in motions/base.js. // factory has to placed in motions/base.js.