Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
edulix committed Nov 14, 2023
1 parent fc4e84a commit c951f23
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
14 changes: 13 additions & 1 deletion avUi/change-lang-directive/change-lang-directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ angular.module('avUi')
ipCookie,
angularLoad,
amMoment,
$rootScope,
ConfigService,
$window,
I18nOverride,
Expand Down Expand Up @@ -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);

Expand All @@ -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;
}
);
};
}

Expand Down
13 changes: 12 additions & 1 deletion avUi/i18n-override-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
{
Expand All @@ -76,6 +86,7 @@ angular
);
}
);

$rootScope.$broadcast(
'i18nextLanguageChange',
$window.i18n.lng()
Expand Down
10 changes: 7 additions & 3 deletions dist/appCommon-v10.0.2.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {},
Expand All @@ -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;
});
};
},
Expand Down

0 comments on commit c951f23

Please sign in to comment.