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

fix(mess): add translation error messages #452

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
6 changes: 5 additions & 1 deletion src/app/core/common.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ angular
* define common Javascript methods
* @function commonService
* @param {Object} $translate translation service Angular object
* @param {object} $rootScope Angular Object
* @param {Object} events Angular object
* @param {Object} $timeout promise with timeout Angular object
* @param {Object} constants modules that contain all the constants
* @return {Object} service common service
*/
function commonService($translate, events, $timeout, constants) {
function commonService($translate, $rootScope, events, $timeout, constants) {

const service = {
parseJSON,
Expand Down Expand Up @@ -116,6 +117,9 @@ function commonService($translate, events, $timeout, constants) {
function setLang(value) {
// show splash with language switch event as parameter
$translate.use(value).then(() => events.$broadcast(events.avShowSplash, events.avSwitchLanguage));

// trigger validation
$timeout(() => $rootScope.$broadcast(events.avValidateForm), constants.delaySetVersion);
}

/**
Expand Down
38 changes: 30 additions & 8 deletions src/app/ui/forms/form.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -410,20 +410,42 @@ function formService($timeout, $rootScope, events, $mdDialog, $translate, keyNam
* @function setErrorMessage
* @param {Object} form form object to get value from
* @param {String} message message to get from translation.csv
* @param {Array} variables variables to replace
* @param {Array} variables variables to replace
* @return {String} mess the updated message
*/
function setErrorMessage(form, message, variables) {
function setErrorMessage(form, message, variables=undefined) {
const errCode = [
{ error: 'number', mess: 'form.map.wkidnuminvalid' },
{ error: 'max', mess: 'form.map.layeropacitymaxerr' },
{ error: 'min', mess: 'form.map.extentdefxminerr' },
{ error: '302', mess: 'form.map.requirederr' },
{ error: '101', mess: 'form.map.extentdefxminerr' },
{ error: '103', mess: 'form.map.layeropacitymaxerr' }]

let mess = $translate.instant(message);

for (let variable of variables) {
let errorcode = form.error;
if (message !== '') {
mess = $translate.instant(message);
}
else {
mess = $translate.instant(errCode.filter( ({error}) => error === errorcode ).map( item => item.mess ).toString() ) ;
}

if (typeof variables !== 'undefined') {
for (let variable of variables) {
// get the replacing value from form object
let replace = form;
variable.split('.').map(item => { replace = replace[item] });
let replace = form;
variable.split('.').map(item => { replace = replace[item] });

// replace value in the message
mess = mess.replace(`{${variable}}`, replace);
// replace value in the message
mess = mess.replace(`{${variable}}`, replace);
}
}
else if (typeof variables === 'undefined') {
// replace values in message string if no parameters passed to replace them with
mess = mess.replace(/{.+?}/, ' ').replace(/{.+?}/, ' ');
mess = mess.replace("( )", ' ');
}

return mess;
}
Expand Down
Loading