Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
edulix committed Jan 26, 2024
1 parent debc4ac commit f2bb6da
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 40 deletions.
41 changes: 12 additions & 29 deletions avUi/i18n-override-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,6 @@ angular

return result;
}
function deepExtend(target, source) {
for (var prop in source) {
if (source.hasOwnProperty(prop)) {
if (target[prop] && typeof source[prop] === 'object') {
deepExtend(target[prop], source[prop]);
}
else {
target[prop] = source[prop];
}
}
}
return target;
}
return function (overrides, force, languagesConf)
{
force = angular.isDefined(force) ? force : false;
Expand All @@ -89,19 +76,24 @@ angular
{
// We use deep extend to have as an override for all available
// languages the original changed with the override
deepExtend(
angular.extend(
overrides,
_.object(_.map(
languagesConf.available_languages,
function(key) { return [key, {}]; }
))
);
}
$i18next.options.useLocalStorage = true;
$window.i18n.options.useLocalStorage = true;
overrides = _.mapObject(overrides, function(obj, langCode) {
var original = $window.i18n.getResourceBundle(langCode, "locales");
var original = {};
if ($window.i18nOriginal && $window.i18nOriginal[langCode]) {
original = $window.i18nOriginal[langCode];
}
var override = expandObject(obj);
deepExtend(original, override);
return original;
var merged = angular.merge({}, original, override);
return merged;
});
} else {
overrides = $window.i18nOverride;
Expand Down Expand Up @@ -138,19 +130,10 @@ angular
$window.i18nOverride,
function (i18nOverride, language)
{
$window.i18n.addResources(
$window.i18n.addResourceBundle(
/* lng = */ language,
/* ns = */ "locales",
/* resources = */ expandObject(i18nOverride)
);

// force-refresh cached translations to override
_.each(
_.keys(i18nOverride),
function (i18nString)
{
$i18next(i18nString, {});
}
/* ns = */ "translation",
/* resources = */ i18nOverride
);
}
);
Expand Down
19 changes: 8 additions & 11 deletions dist/appCommon-v10.1.0.js
Original file line number Diff line number Diff line change
Expand Up @@ -1129,25 +1129,22 @@ angular.module("avRegistration").config(function() {}), angular.module("avRegist
}(result, prop.split("."), obj[prop]);
return result;
}
function deepExtend(target, source) {
for (var prop in source) source.hasOwnProperty(prop) && (target[prop] && "object" == typeof source[prop] ? deepExtend(target[prop], source[prop]) : target[prop] = source[prop]);
return target;
}
return function(overrides, force, languagesConf) {
force = !!angular.isDefined(force) && force;
var performOverrides = !1;
(overrides = null !== overrides ? (languagesConf && languagesConf.available_languages && deepExtend(overrides, _.object(_.map(languagesConf.available_languages, function(key) {
(overrides = null !== overrides ? (languagesConf && languagesConf.available_languages && angular.extend(overrides, _.object(_.map(languagesConf.available_languages, function(key) {
return [ key, {} ];
}))), _.mapObject(overrides, function(obj, original) {
original = $window.i18n.getResourceBundle(original, "locales");
return deepExtend(original, expandObject(obj)), original;
}))), $i18next.options.useLocalStorage = !0, $window.i18n.options.useLocalStorage = !0,
_.mapObject(overrides, function(override, langCode) {
var original = {};
$window.i18nOriginal && $window.i18nOriginal[langCode] && (original = $window.i18nOriginal[langCode]);
override = expandObject(override);
return angular.merge({}, original, override);
})) : $window.i18nOverride) && (performOverrides = force || JSON.stringify(overrides) !== JSON.stringify($window.i18nOverride),
$window.i18nOverride = overrides), languagesConf && ($i18next.options.lng = languagesConf.force_default_language ? languagesConf.default_language : $window.i18n.lng(),
$i18next.options.lngWhitelist = languagesConf.available_languages, $i18next.options.fallbackLng = [ languagesConf.default_language, "en" ]),
performOverrides && _.map($window.i18nOverride, function(i18nOverride, language) {
$window.i18n.addResources(language, "locales", expandObject(i18nOverride)), _.each(_.keys(i18nOverride), function(i18nString) {
$i18next(i18nString, {});
});
$window.i18n.addResourceBundle(language, "translation", i18nOverride);
}), $i18next.reInit();
};
} ]), angular.module("avUi").directive("avChangeLang", [ "$i18next", "ipCookie", "angularLoad", "amMoment", "$rootScope", "ConfigService", "$window", "I18nOverride", "Authmethod", function($i18next, ipCookie, angularLoad, amMoment, $rootScope, ConfigService, $window, I18nOverride, Authmethod) {
Expand Down

0 comments on commit f2bb6da

Please sign in to comment.