Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐞 default translation appears when switching language for the first time (#377) #378

Merged
merged 1 commit into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion avRegistration/login-controller/login-controller-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ describe("Login Controler tests", function () {
$scope: $scope,
$stateParams: { id: 1, code: 'qwerty', email: 'test@sequentech.io', isOpenId: false },
$filter: undefined,
$i18next: undefined,
$cookies: undefined,
$window: window,
ConfigService: {},
Expand Down
1 change: 0 additions & 1 deletion avRegistration/login-directive/login-directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ angular.module('avRegistration')
$state,
$location,
$cookies,
$i18next,
$window,
$timeout,
ConfigService,
Expand Down
2 changes: 1 addition & 1 deletion avRegistration/logout-controller/logout-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
**/

angular.module('avRegistration').controller('LogoutController',
function($scope, $stateParams, $filter, ConfigService, $i18next, $state, $cookies, Authmethod) {
function($scope, $stateParams, $filter, ConfigService, $state, $cookies, Authmethod) {
var adminId = ConfigService.freeAuthId;
var authevent = Authmethod.getAuthevent();
var postfix = "_authevent_" + authevent;
Expand Down
2 changes: 1 addition & 1 deletion avRegistration/register-controller/register-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
**/

angular.module('avRegistration').controller('RegisterController',
function($scope, $stateParams, $filter, ConfigService, $i18next) {
function($scope, $stateParams, $filter, ConfigService) {
$scope.event_id = $stateParams.id;
$scope.email = $stateParams.email;
}
Expand Down
10 changes: 5 additions & 5 deletions avRegistration/register-directive/register-directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
**/

angular.module('avRegistration')
.directive('avRegister', function(Authmethod, StateDataService, $parse, $state, ConfigService, $cookies, $i18next, $sce) {
.directive('avRegister', function(Authmethod, StateDataService, $parse, $state, ConfigService, $cookies, $window, $sce) {
// we use it as something similar to a controller here
function link(scope, element, attrs) {
var autheventid = attrs.eventId;
Expand Down Expand Up @@ -76,13 +76,13 @@ angular.module('avRegistration')
scope.user = response.data.user;
data.successfulRegistration = true;
StateDataService.go(details.path, details.data, data);
scope.error = response.data.msg || $sce.trustAsHtml($i18next('avRegistration.invalidRegisterData', {
scope.error = response.data.msg || $sce.trustAsHtml($window.i18next.t('avRegistration.invalidRegisterData', {
url: $state.href(details.path, details.data)
}));
} else {
scope.sendingData = false;
scope.status = 'Not found';
scope.error = response.data.msg || $sce.trustAsHtml($i18next('avRegistration.invalidRegisterData', {
scope.error = response.data.msg || $sce.trustAsHtml($window.i18next.t('avRegistration.invalidRegisterData', {
url: $state.href(details.path, details.data)
}));
}
Expand All @@ -93,9 +93,9 @@ angular.module('avRegistration')
scope.status = 'Registration error: ' + response.data.message;

if (!!response.data.error_codename && response.data.error_codename === 'invalid-dni') {
scope.error = $sce.trustAsHtml($i18next('avRegistration.invalidRegisterDNI'));
scope.error = $sce.trustAsHtml($window.i18next.t('avRegistration.invalidRegisterDNI'));
} else {
scope.error = response.data.msg || $sce.trustAsHtml($i18next('avRegistration.invalidRegisterData', {
scope.error = response.data.msg || $sce.trustAsHtml($window.i18next.t('avRegistration.invalidRegisterData', {
url: $state.href(details.path, details.data)
}));
if (response.data.msg === 'Invalid captcha') {
Expand Down
8 changes: 1 addition & 7 deletions avUi/i18n-override-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,15 @@ angular

if (languagesConf)
{
// For some reason it seems that `$i18next.options.lng` gets desynced
// from `$window.i18next.resolvedLanguage`. This might result in an unexpected
// language change when the init() function from $i18next gets called
// later in this code. For this reason, we set the correct language in
// `$i18next.options.lng` to ensure that doesn't happen.
$i18next.options.lng = (languagesConf.force_default_language) ?
languagesConf.default_language : $window.i18next.resolvedLanguage;

$i18next.options.lngWhitelist = languagesConf.available_languages;
$i18next.options.preload = languagesConf.available_languages;
$i18next.options.fallbackLng = [languagesConf.default_language, 'en'];
}
console.log("calling $window.i18next.reloadResources()..");
$window.i18next
.reloadResources($i18next.options.preload)
.reloadResources($i18next.options.preload, ['override'])
.then(function () {
if (
languagesConf &&
Expand Down
15 changes: 8 additions & 7 deletions avUi/show-versions-modal-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ angular
.module('avUi')
.service(
'ShowVersionsModalService',
function(ConfigService, $modal, $i18next) {
function(ConfigService, $modal, $sce, $window) {
return function () {
$modal
.open({
Expand All @@ -28,7 +28,7 @@ angular
size: 'lg',
resolve: {
data: function () {
var mainVersion = $i18next('avCommon.showVersionModal.mainVersion');
var mainVersion = $window.i18next.t('avCommon.showVersionModal.mainVersion');
var versionList = (
"<li><strong>" + mainVersion + " (deployment-tool):</strong> " +
ConfigService.mainVersion +
Expand All @@ -46,17 +46,18 @@ angular
);
}
);
var body = $i18next(
var body = $sce.trustAsHtml($window.i18next.t(
'avCommon.showVersionModal.body',
{
versionList: versionList
versionList: versionList,
interpolation: { escapeValue: false }
}
);
));
return {
i18n: {
header: $i18next('avCommon.showVersionModal.header'),
header: $window.i18next.t('avCommon.showVersionModal.header'),
body: body,
confirmButton: $i18next('avCommon.showVersionModal.confirmButton'),
confirmButton: $window.i18next.t('avCommon.showVersionModal.confirmButton'),
},
hideCancelButton: true
};
Expand Down
34 changes: 18 additions & 16 deletions dist/appCommon-vmaster.js
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ angular.module("avRegistration").config(function() {}), angular.module("avRegist
$scope.withCode = $stateParams.withCode, $scope.withAltMethod = $stateParams.withAltMethod,
$scope.selectedAltMethod = $stateParams.altmethod, $scope.isOtl = $stateParams.isOtl,
$scope.otlSecret = $stateParams.otlSecret;
} ]), angular.module("avRegistration").directive("avLogin", [ "Authmethod", "StateDataService", "$state", "$location", "$cookies", "$i18next", "$window", "$timeout", "ConfigService", "Patterns", function(Authmethod, StateDataService, $state, $location, $cookies, $i18next, $window, $timeout, ConfigService, Patterns) {
} ]), angular.module("avRegistration").directive("avLogin", [ "Authmethod", "StateDataService", "$state", "$location", "$cookies", "$window", "$timeout", "ConfigService", "Patterns", function(Authmethod, StateDataService, $state, $location, $cookies, $window, $timeout, ConfigService, Patterns) {
return {
restrict: "AE",
scope: !0,
Expand Down Expand Up @@ -731,16 +731,16 @@ angular.module("avRegistration").config(function() {}), angular.module("avRegist
},
templateUrl: "avRegistration/login-directive/login-directive.html"
};
} ]), angular.module("avRegistration").controller("LogoutController", [ "$scope", "$stateParams", "$filter", "ConfigService", "$i18next", "$state", "$cookies", "Authmethod", function($scope, $stateParams, $filter, ConfigService, $i18next, $state, $cookies, postfix) {
} ]), angular.module("avRegistration").controller("LogoutController", [ "$scope", "$stateParams", "$filter", "ConfigService", "$state", "$cookies", "Authmethod", function($scope, $stateParams, $filter, ConfigService, $state, $cookies, postfix) {
ConfigService.freeAuthId;
var authevent = postfix.getAuthevent(), postfix = "_authevent_" + authevent;
$cookies.put("user" + postfix, ""), $cookies.put("auth" + postfix, ""), $cookies.put("authevent_" + authevent, ""),
$cookies.put("userid" + postfix, ""), $cookies.put("isAdmin" + postfix, !1), authevent !== ConfigService.freeAuthId + "" && authevent ? $state.go("registration.login", {
id: $cookies.get("authevent_" + authevent)
}) : $state.go("admin.login");
} ]), angular.module("avRegistration").controller("RegisterController", [ "$scope", "$stateParams", "$filter", "ConfigService", "$i18next", function($scope, $stateParams, $filter, ConfigService, $i18next) {
} ]), angular.module("avRegistration").controller("RegisterController", [ "$scope", "$stateParams", "$filter", "ConfigService", function($scope, $stateParams, $filter, ConfigService) {
$scope.event_id = $stateParams.id, $scope.email = $stateParams.email;
} ]), angular.module("avRegistration").directive("avRegister", [ "Authmethod", "StateDataService", "$parse", "$state", "ConfigService", "$cookies", "$i18next", "$sce", function(Authmethod, StateDataService, $parse, $state, ConfigService, $cookies, $i18next, $sce) {
} ]), angular.module("avRegistration").directive("avRegister", [ "Authmethod", "StateDataService", "$parse", "$state", "ConfigService", "$cookies", "$window", "$sce", function(Authmethod, StateDataService, $parse, $state, ConfigService, $cookies, $window, $sce) {
return {
restrict: "AE",
scope: !0,
Expand Down Expand Up @@ -771,12 +771,12 @@ angular.module("avRegistration").config(function() {}), angular.module("avRegist
}), Authmethod.signup(data, autheventid).then(function(response) {
details = scope.getLoginDetails(autheventid), "ok" === response.data.status ? (scope.user = response.data.user,
data.successfulRegistration = !0, StateDataService.go(details.path, details.data, data)) : (scope.sendingData = !1,
scope.status = "Not found"), scope.error = response.data.msg || $sce.trustAsHtml($i18next("avRegistration.invalidRegisterData", {
scope.status = "Not found"), scope.error = response.data.msg || $sce.trustAsHtml($window.i18next.t("avRegistration.invalidRegisterData", {
url: $state.href(details.path, details.data)
}));
}, function(response) {
details = scope.getLoginDetails(autheventid), scope.sendingData = !1, scope.status = "Registration error: " + response.data.message,
response.data.error_codename && "invalid-dni" === response.data.error_codename ? scope.error = $sce.trustAsHtml($i18next("avRegistration.invalidRegisterDNI")) : (scope.error = response.data.msg || $sce.trustAsHtml($i18next("avRegistration.invalidRegisterData", {
response.data.error_codename && "invalid-dni" === response.data.error_codename ? scope.error = $sce.trustAsHtml($window.i18next.t("avRegistration.invalidRegisterDNI")) : (scope.error = response.data.msg || $sce.trustAsHtml($window.i18next.t("avRegistration.invalidRegisterData", {
url: $state.href(details.path, details.data)
})), "Invalid captcha" === response.data.msg && Authmethod.newCaptcha());
}));
Expand Down Expand Up @@ -1093,26 +1093,29 @@ angular.module("avRegistration").config(function() {}), angular.module("avRegist
}, $scope.cancel = function() {
$modalInstance.dismiss("cancel");
};
} ]), angular.module("avUi").service("ShowVersionsModalService", [ "ConfigService", "$modal", "$i18next", function(ConfigService, $modal, $i18next) {
} ]), angular.module("avUi").service("ShowVersionsModalService", [ "ConfigService", "$modal", "$sce", "$window", function(ConfigService, $modal, $sce, $window) {
return function() {
$modal.open({
templateUrl: "avUi/confirm-modal-controller/confirm-modal-controller.html",
controller: "ConfirmModal",
size: "lg",
resolve: {
data: function() {
var versionList = "<li><strong>" + $i18next("avCommon.showVersionModal.mainVersion") + " (deployment-tool):</strong> " + ConfigService.mainVersion + "<br><br></li>";
var versionList = "<li><strong>" + $window.i18next.t("avCommon.showVersionModal.mainVersion") + " (deployment-tool):</strong> " + ConfigService.mainVersion + "<br><br></li>";
_.each(ConfigService.repoVersions, function(repo) {
versionList += "<li><strong>" + repo.repoName + ":</strong> " + repo.repoVersion + "</li>";
});
var body = $i18next("avCommon.showVersionModal.body", {
versionList: versionList
});
var body = $sce.trustAsHtml($window.i18next.t("avCommon.showVersionModal.body", {
versionList: versionList,
interpolation: {
escapeValue: !1
}
}));
return {
i18n: {
header: $i18next("avCommon.showVersionModal.header"),
header: $window.i18next.t("avCommon.showVersionModal.header"),
body: body,
confirmButton: $i18next("avCommon.showVersionModal.confirmButton")
confirmButton: $window.i18next.t("avCommon.showVersionModal.confirmButton")
},
hideCancelButton: !0
};
Expand All @@ -1125,9 +1128,8 @@ angular.module("avRegistration").config(function() {}), angular.module("avRegist
force = !!angular.isDefined(force) && force;
null === overrides || !force && JSON.stringify(overrides) === JSON.stringify($window.i18nOverride) || ($window.i18nOverride = overrides),
languagesConf && ($i18next.options.lng = languagesConf.force_default_language ? languagesConf.default_language : $window.i18next.resolvedLanguage,
$i18next.options.lngWhitelist = languagesConf.available_languages, $i18next.options.preload = languagesConf.available_languages,
$i18next.options.fallbackLng = [ languagesConf.default_language, "en" ]), console.log("calling $window.i18next.reloadResources().."),
$window.i18next.reloadResources($i18next.options.preload).then(function() {
$i18next.options.lngWhitelist = languagesConf.available_languages, $i18next.options.preload = languagesConf.available_languages),
console.log("calling $window.i18next.reloadResources().."), $window.i18next.reloadResources($i18next.options.preload, [ "override" ]).then(function() {
languagesConf && languagesConf.force_default_language && $window.i18next.changeAppLang ? (console.log("reloadResources: successful. force-changing default lang to=" + languagesConf.default_language),
$window.i18next.changeAppLang(languagesConf.default_language)) : (console.log("reloadResources: successful. broadcast i18nextLanguageChange signal"),
$rootScope.$broadcast("i18nextLanguageChange", $i18next.options.lng));
Expand Down
Loading