Skip to content

Commit

Permalink
🐞 default translation appears when switching language for the first t…
Browse files Browse the repository at this point in the history
…ime (#411)

Parent issue: sequentech/meta#315
  • Loading branch information
edulix authored Feb 13, 2024
1 parent fc91fb7 commit 54aa997
Show file tree
Hide file tree
Showing 17 changed files with 93 additions and 73 deletions.
1 change: 0 additions & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,6 @@ module.exports = function (grunt) {
main: {
files: {
'temp/app.js':['temp/app.js'],
'temp/lib.js': ['temp/lib.js'],
'temp/libnocompat.js': ['temp/libnocompat.js'],
'temp/libcompat.js': ['temp/libcompat.js']
}
Expand Down
57 changes: 42 additions & 15 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,46 @@ angular
// supported by the web browser
$("#no-js").hide();

$i18nextProvider.options = _.extend(
{
useCookie: true,
useLocalStorage: false,
fallbackLng: 'en',
cookieName: 'lang',
detectLngQS: 'lang',
lngWhitelist: ['en', 'es', 'gl', 'ca'],
resGetPath: '/admin/locales/__lng__.json',
defaultLoadingValue: '' // ng-i18next option, *NOT* directly supported by i18next
},
ConfigServiceProvider.i18nextInitOptions
);
// note that we do not send the language: by default, it will try the language
// supported by the web browser
$("#no-js").hide();
window.i18next
.use(window.i18nextChainedBackend)
.init(_.extend(
{
debug: true,
load: 'languageOnly',
useCookie: true,
// Preload is needed because the language selector shows an item for
// each element in lngWhitelist, and the translation for each language
// is contained at each language i18n file, so we either preload it
// or it wouldn't work.
preload: ConfigServiceProvider.i18nextInitOptions.lngWhitelist || [],
useLocalStorage: false,
fallbackLng: 'en',
cookieName: 'lang',
detectLngQS: 'lang',
lngWhitelist: ['en', 'es'],
interpolation: {
prefix: '__',
suffix: '__',
},
// Define the backends to use in the chain
backend: {
backends: [
window.i18nextHttpBackend, // Primary backend
],
backendOptions: [
// Configuration for http backend
{
loadPath: '/admin/locales/__lng__.json',
},
]
},
defaultLoadingValue: '' // ng-i18next option, *NOT* directly supported by i18next
},
ConfigServiceProvider.i18nextInitOptions
));

// Prevent site translation if configured
if (ConfigServiceProvider.preventSiteTranslation) {
Expand Down Expand Up @@ -329,7 +356,7 @@ angular
$rootScope,
ConfigService,
amMoment,
$i18next,
$window,
angularLoad,
$location
) {
Expand All @@ -350,7 +377,7 @@ angular
};

// async load moment i18n
var lang = $i18next.options.lng;
var lang = $window.i18next.resolvedLanguage;
angularLoad
.loadScript(ConfigService.base + '/locales/moment/' + lang + '.js')
.then(function () {
Expand Down
1 change: 0 additions & 1 deletion avAdmin/admin-controller/admin-controller-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ describe("Admin Controler tests", function () {
$scope: $scope,
$stateParams: { id: 1 },
$filter: undefined,
$i18next: undefined,
$cookies: undefined,
ConfigService: { helpUrl: 'http://sequentech.io', showSuccessAction: true },
AutomaticIds: undefined,
Expand Down
4 changes: 1 addition & 3 deletions avAdmin/admin-directives/admin-field/admin-field.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
angular.module('avAdmin')
.directive(
'avAdminField',
function(
$i18next,
ElectionsApi)
function(ElectionsApi)
{
function link(scope, element, attrs) {
scope.editable = function () {
Expand Down
1 change: 0 additions & 1 deletion avAdmin/admin-directives/admin-fields/admin-fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ angular.module('admin-console')
.directive(
'avAdminFields',
function(
$i18next,
NextButtonService,
ElectionsApi)
{
Expand Down
10 changes: 5 additions & 5 deletions avAdmin/admin-directives/ballot-box/ballot-box.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ angular.module('avAdmin')
ConfigService,
NextButtonService,
$timeout,
$i18next,
$window,
$modal,
$location,
ElectionsApi
Expand Down Expand Up @@ -184,7 +184,7 @@ angular.module('avAdmin')
// list of row commands
scope.row_commands = [
{
text: $i18next("avAdmin.ballotBox.viewTallySheetAction"),
text: $window.i18next.t("avAdmin.ballotBox.viewTallySheetAction"),
iconClass: 'fa fa-file',
actionFunc: function(ballotBox)
{
Expand Down Expand Up @@ -234,7 +234,7 @@ angular.module('avAdmin')
}
},
{
text: $i18next("avAdmin.ballotBox.writeTallySheetAction"),
text: $window.i18next.t("avAdmin.ballotBox.writeTallySheetAction"),
iconClass: 'fa fa-edit',
actionFunc: function(ballotBox)
{
Expand Down Expand Up @@ -322,7 +322,7 @@ angular.module('avAdmin')
}
},
{
text: $i18next("avAdmin.ballotBox.deleteTallySheetAction"),
text: $window.i18next.t("avAdmin.ballotBox.deleteTallySheetAction"),
iconClass: 'fa fa-minus-square',
actionFunc: function(ballotBox)
{
Expand Down Expand Up @@ -363,7 +363,7 @@ angular.module('avAdmin')
}
},
{
text: $i18next("avAdmin.ballotBox.deleteBallotBoxAction"),
text: $window.i18next.t("avAdmin.ballotBox.deleteBallotBoxAction"),
iconClass: 'fa fa-times',
actionFunc: function(ballotBox)
{
Expand Down
15 changes: 8 additions & 7 deletions avAdmin/admin-directives/create/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ angular.module('avAdmin')
$state,
$stateParams,
$sanitize,
$window,
$i18next,
$filter,
$modal,
Expand Down Expand Up @@ -1047,7 +1048,7 @@ angular.module('avAdmin')
console.log("creating auth event for election " + el.title);
var deferred = $q.defer();
// Creating the authentication
logInfo($i18next('avAdmin.create.creating', {title: el.title}));
logInfo($i18next.t('avAdmin.create.creating', {title: el.title}));

var d = ElectionCreation.generateAuthapiRequest(el);

Expand All @@ -1067,14 +1068,14 @@ angular.module('avAdmin')
var deferred = $q.defer();

// Adding the census
logInfo($i18next('avAdmin.create.census', {title: el.title, id: el.id}));
logInfo($i18next.t('avAdmin.create.census', {title: el.title, id: el.id}));

var data = {
election: el,
verifyCensus: scope.verifyCensusBool,
error: function (errorMsg) {
var message = (errorMsg === "invalid_credentials") ?
$i18next("avAdmin.dashboard.modals.addCensus.errorInvalidCensusData") :
$i18next.t("avAdmin.dashboard.modals.addCensus.errorInvalidCensusData") :
$sanitize(errorMsg);
scope.errors.push({
data: {message: message},
Expand All @@ -1101,7 +1102,7 @@ angular.module('avAdmin')
var deferred = $q.defer();

logInfo(
$i18next(
$i18next.t(
'avAdmin.create.setChildrenElectionInfo',
{title: el.title, id: el.id}
)
Expand Down Expand Up @@ -1136,7 +1137,7 @@ angular.module('avAdmin')
console.log("adding ballot boxes for election " + el.title);

logInfo(
$i18next(
$i18next.t(
'avAdmin.create.addBallotBoxes',
{title: el.title, id: el.id}
)
Expand Down Expand Up @@ -1174,7 +1175,7 @@ angular.module('avAdmin')

var deferred = $q.defer();
// Registering the election
logInfo($i18next('avAdmin.create.reg', {title: d.title, id: d.id}));
logInfo($i18next.t('avAdmin.create.reg', {title: d.title, id: d.id}));
ElectionsApi.command(d, '', 'POST', d)
.then(function(data) { deferred.resolve(d); })
.catch(deferred.reject);
Expand All @@ -1190,7 +1191,7 @@ angular.module('avAdmin')
el.extra_data = JSON.stringify(el.extra_data);
}
// Creating the election
logInfo($i18next('avAdmin.create.creatingEl', {title: el.title, id: el.id}));
logInfo($i18next.t('avAdmin.create.creatingEl', {title: el.title, id: el.id}));
ElectionsApi.command(el, 'create', 'POST', {})
.then(function(data) { deferred.resolve(el); })
.catch(deferred.reject);
Expand Down
4 changes: 2 additions & 2 deletions avAdmin/admin-directives/dashboard/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ angular.module('avAdmin')
'avAdminDashboard',
function(
$q,
$i18next,
$window,
$state,
Authmethod,
Plugins,
Expand Down Expand Up @@ -641,7 +641,7 @@ angular.module('avAdmin')
scope.msg = "avAdmin.dashboard.modals.configureScheduledEvents.success";
},
function onError() {
scope.error = $i18next("avAdmin.dashboard.modals.configureScheduledEvents.error");
scope.error = $window.i18next.t("avAdmin.dashboard.modals.configureScheduledEvents.error");
}

);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ angular.module('avAdmin')
$timeout,
$scope,
$modalInstance,
$i18next,
$window,
SendMsg,
Plugins,
election,
Expand Down Expand Up @@ -100,7 +100,7 @@ angular.module('avAdmin')
email: $scope.contact.email
};

return $i18next(
return $window.i18next.t(
"avAdmin.dashboard.modals.sendAuthCodes.confirmStep.unknownError",
data);
};
Expand Down
19 changes: 9 additions & 10 deletions avAdmin/admin-directives/elcensus/elcensus.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ angular.module('avAdmin')
.directive(
'avAdminElcensus',
function(
$i18next,
$window,
$http,
ElectionsApi,
Expand Down Expand Up @@ -224,13 +223,13 @@ angular.module('avAdmin')
]
},
{
text: $i18next('avAdmin.census.generatePDFAuthCodes.header'),
text: $window.i18next.t('avAdmin.census.generatePDFAuthCodes.header'),
style: 'h3'
},
{
columns: [
{
text: $i18next('avAdmin.census.generatePDFAuthCodes.username'),
text: $window.i18next.t('avAdmin.census.generatePDFAuthCodes.username'),
style: 'cell',
width: '40%'
},
Expand All @@ -244,7 +243,7 @@ angular.module('avAdmin')
{
columns: [
{
text: $i18next('avAdmin.census.generatePDFAuthCodes.userId'),
text: $window.i18next.t('avAdmin.census.generatePDFAuthCodes.userId'),
style: 'cell',
width: '40%'
},
Expand All @@ -258,7 +257,7 @@ angular.module('avAdmin')
{
columns: [
{
text: $i18next('avAdmin.census.generatePDFAuthCodes.authCode'),
text: $window.i18next.t('avAdmin.census.generatePDFAuthCodes.authCode'),
style: 'cell',
width: '40%'
},
Expand All @@ -272,7 +271,7 @@ angular.module('avAdmin')
{
columns: [
{
text: $i18next('avAdmin.census.generatePDFAuthCodes.codeCreated'),
text: $window.i18next.t('avAdmin.census.generatePDFAuthCodes.codeCreated'),
style: 'cell',
width: '40%'
},
Expand All @@ -287,7 +286,7 @@ angular.module('avAdmin')
{
columns: [
{
text: $i18next('avAdmin.census.generatePDFAuthCodes.authLink'),
text: $window.i18next.t('avAdmin.census.generatePDFAuthCodes.authLink'),
width: '40%',
style: 'cell'
},
Expand All @@ -306,7 +305,7 @@ angular.module('avAdmin')
width: '*'
},
{
text: $i18next('avAdmin.census.generatePDFAuthCodes.qrCode'),
text: $window.i18next.t('avAdmin.census.generatePDFAuthCodes.qrCode'),
style: 'p',
width: 'auto'
},
Expand Down Expand Up @@ -860,7 +859,7 @@ angular.module('avAdmin')
response.data &&
response.data.error_codename === "invalid_credentials"
) {
scope.error = $i18next(
scope.error = $window.i18next.t(
"avAdmin.dashboard.modals.addCensus.errorInvalidCensusData"
);
} else {
Expand Down Expand Up @@ -1073,7 +1072,7 @@ angular.module('avAdmin')
function errorFunction(data) {
if (angular.isString(data)) {
if (data === "invalid_credentials") {
scope.error = $i18next("avAdmin.dashboard.modals.addCensus.errorInvalidCensusData");
scope.error = $window.i18next.t("avAdmin.dashboard.modals.addCensus.errorInvalidCensusData");
} else {
scope.error = data;
}
Expand Down
4 changes: 2 additions & 2 deletions avAdmin/admin-directives/elquestions/elquestions.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
angular.module('avAdmin')
.directive(
'avAdminElquestions',
function($i18next, $state, ElectionsApi, ElectionLimits,NextButtonService, ConfigService)
function($window, $state, ElectionsApi, ElectionLimits,NextButtonService, ConfigService)
{
// we use it as something similar to a controller here
function link(scope, element, attrs) {
Expand All @@ -45,7 +45,7 @@ angular.module('avAdmin')
el.questions = [];
}
// New question
var q = ElectionsApi.templateQ($i18next("avAdmin.questions.new") + " " + el.questions.length);
var q = ElectionsApi.templateQ($window.i18next.t("avAdmin.questions.new") + " " + el.questions.length);
el.questions.push(q);
expandQuestion(el.questions.length - 1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ angular.module('avAdmin')
social_message: '',
active: false
};
//ElectionsApi.templateQ($i18next("avAdmin.questions.new") + " " + el.questions.length);
scope.socialConfig.push(q);
expandItem(scope.socialConfig.length - 1);
};
Expand Down
2 changes: 1 addition & 1 deletion avAdmin/admin-login-controller/admin-login-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
**/

angular.module('avAdmin').controller('AdminLoginController',
function($scope, $stateParams, $filter, ConfigService, $i18next) {
function($scope, $stateParams, $filter, ConfigService) {
$scope.authId = ConfigService.freeAuthId;
$scope.code = $stateParams.code;
$scope.email = $stateParams.email;
Expand Down
1 change: 0 additions & 1 deletion avAdmin/admin-profile-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ angular.module('avAdmin')
Plugins,
Authmethod,
ConfigService,
$i18next,
$http,
$modal,
$cookies,
Expand Down
Loading

0 comments on commit 54aa997

Please sign in to comment.