From c951f23ed66ff889845d9f6cdd91b51d0d3a2436 Mon Sep 17 00:00:00 2001 From: Eduardo Robles Elvira Date: Tue, 14 Nov 2023 15:54:19 +0100 Subject: [PATCH] WIP --- .../change-lang-directive/change-lang-directive.js | 14 +++++++++++++- avUi/i18n-override-service.js | 13 ++++++++++++- dist/appCommon-v10.0.2.js | 10 +++++++--- 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/avUi/change-lang-directive/change-lang-directive.js b/avUi/change-lang-directive/change-lang-directive.js index ca7ac143..78b959fe 100644 --- a/avUi/change-lang-directive/change-lang-directive.js +++ b/avUi/change-lang-directive/change-lang-directive.js @@ -26,6 +26,7 @@ angular.module('avUi') ipCookie, angularLoad, amMoment, + $rootScope, ConfigService, $window, I18nOverride, @@ -79,7 +80,8 @@ angular.module('avUi') ipCookie( "lang", lang, - _.extend(cookieConf, ConfigService.i18nextCookieOptions)); + _.extend(cookieConf, ConfigService.i18nextCookieOptions) + ); scope.deflang = lang; angular.element('#ng-app').attr('lang', scope.deflang); @@ -91,6 +93,16 @@ angular.module('avUi') amMoment.changeLocale(lang); }); } + + // detect language changes + $rootScope.$on( + 'i18nextLanguageChange', + function () + { + scope.deflang = $i18next.options.lng; + scope.langs = $i18next.options.lngWhitelist; + } + ); }; } diff --git a/avUi/i18n-override-service.js b/avUi/i18n-override-service.js index 79f36f5a..a1087bde 100644 --- a/avUi/i18n-override-service.js +++ b/avUi/i18n-override-service.js @@ -38,7 +38,7 @@ angular 'I18nOverride', function($i18next, $rootScope, $window) { - return function (overrides, force) + return function (overrides, force, languagesConf) { force = angular.isDefined(force) ? force : false; overrides = overrides === null ? $window.i18nOverride : overrides; @@ -53,6 +53,16 @@ angular $window.i18nOverride = overrides; } + if (languagesConf) + { + $i18next.options.lngWhitelist = languagesConf.available_languages; + $i18next.options.fallbackLng = languagesConf.default_language; + if (languagesConf.force_default_language) + { + $i18next.options.lng = languagesConf.default_language; + } + } + // load i18n_overrides if any if (performOverrides) { @@ -76,6 +86,7 @@ angular ); } ); + $rootScope.$broadcast( 'i18nextLanguageChange', $window.i18n.lng() diff --git a/dist/appCommon-v10.0.2.js b/dist/appCommon-v10.0.2.js index cd28ceb7..5c8cbbd1 100644 --- a/dist/appCommon-v10.0.2.js +++ b/dist/appCommon-v10.0.2.js @@ -1121,17 +1121,19 @@ angular.module("avRegistration").config(function() {}), angular.module("avRegist }); }; } ]), angular.module("avUi").service("I18nOverride", [ "$i18next", "$rootScope", "$window", function($i18next, $rootScope, $window) { - return function(overrides, force) { + return function(overrides, force, languagesConf) { force = !!angular.isDefined(force) && force; var performOverrides = !1; (overrides = null === overrides ? $window.i18nOverride : overrides) && (performOverrides = force || JSON.stringify(overrides) !== JSON.stringify($window.i18nOverride), - $window.i18nOverride = overrides), performOverrides && (_.map($window.i18nOverride, function(i18nOverride, language) { + $window.i18nOverride = overrides), languagesConf && ($i18next.options.lngWhitelist = languagesConf.available_languages, + $i18next.options.fallbackLng = languagesConf.default_language, languagesConf.force_default_language && ($i18next.options.lng = languagesConf.default_language)), + performOverrides && (_.map($window.i18nOverride, function(i18nOverride, language) { $window.i18n.addResources(language, "translation", i18nOverride), _.each(_.keys(i18nOverride), function(i18nString) { $i18next(i18nString, {}); }); }), $rootScope.$broadcast("i18nextLanguageChange", $window.i18n.lng())); }; -} ]), angular.module("avUi").directive("avChangeLang", [ "$i18next", "ipCookie", "angularLoad", "amMoment", "ConfigService", "$window", "I18nOverride", "Authmethod", function($i18next, ipCookie, angularLoad, amMoment, ConfigService, $window, I18nOverride, Authmethod) { +} ]), angular.module("avUi").directive("avChangeLang", [ "$i18next", "ipCookie", "angularLoad", "amMoment", "$rootScope", "ConfigService", "$window", "I18nOverride", "Authmethod", function($i18next, ipCookie, angularLoad, amMoment, $rootScope, ConfigService, $window, I18nOverride, Authmethod) { return { restrict: "AE", scope: {}, @@ -1154,6 +1156,8 @@ angular.module("avRegistration").config(function() {}), angular.module("avRegist }, ConfigService.i18nextCookieOptions)), scope.deflang = lang, angular.element("#ng-app").attr("lang", scope.deflang), isAdmin && angularLoad.loadScript(ConfigService.base + "/locales/moment/" + lang + ".js").then(function() { amMoment.changeLocale(lang); + }), $rootScope.$on("i18nextLanguageChange", function() { + scope.deflang = $i18next.options.lng, scope.langs = $i18next.options.lngWhitelist; }); }; },