Skip to content

Commit

Permalink
🌐 Make sure all error messages around the dynamic config are translated
Browse files Browse the repository at this point in the history
  • Loading branch information
shankari committed May 20, 2023
1 parent 1ebf648 commit 36a1aaf
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
12 changes: 12 additions & 0 deletions www/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -465,5 +465,17 @@
"dont-force-kill": "Do not force kill the app",
"background-restrictions": "On Samsung and Huwaei phones, make sure that background restrictions are turned off",
"close": "Close"
},
"config": {
"unable-read-saved-config": "Unable to read saved config",
"unable-to-store-config": "Unable to store downladed config",
"not-enough-parts-old-style": "OPcode {{token}} does not have at least two '_' characters",
"no-nrelop-start": "OPcode {{token}} does not start with 'nrelop'",
"not-enough-parts": "OPcode {{token}} does not have at least three '_' characters",
"invalid-subgroup": "Invalid OPcode {{token}}, subgroup {{subgroup}} not found in list {{config_subgroups}}",
"invalid-subgroup-no-default": "Invalid OPcode {{token}}, no subgroups, expected 'default' subgroup",
"unable-download-config": "Unable to download study config",
"invalid-opcode-format": "Invalid OPcode format",
"error-loading-config-app-start": "Error loading config on app start"
}
}
24 changes: 12 additions & 12 deletions www/js/config/dynamic_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

angular.module('emission.config.dynamic', ['emission.plugin.logger'])
.factory('DynamicConfig', function($http, $ionicPlatform,
$window, $state, $rootScope, $timeout, Logger) {
$window, $state, $rootScope, $timeout, Logger, $translate) {
// also used in the startprefs class
// but without importing this
const CONFIG_PHONE_UI="config/app_ui_config";
Expand Down Expand Up @@ -72,7 +72,7 @@ angular.module('emission.config.dynamic', ['emission.plugin.logger'])
return savedConfig;
}
})
.catch((err) => Logger.displayError("Unable to read saved config", err));
.catch((err) => Logger.displayError($translate.instant('config.unable-read-saved-config'), err));
}

/**
Expand Down Expand Up @@ -106,7 +106,7 @@ angular.module('emission.config.dynamic', ['emission.plugin.logger'])
if (thenGoToIntro) $state.go("root.intro")
})
.then(() => true)
.catch((storeError) => Logger.displayError("Error storing downloaded study configuration", storeError));
.catch((storeError) => Logger.displayError($translate.instant('config.unable-to-store-config'), storeError));
});
}

Expand Down Expand Up @@ -180,10 +180,10 @@ angular.module('emission.config.dynamic', ['emission.plugin.logger'])
const tokenParts = token.split("_");
if (tokenParts.length < 3) {
// all tokens must have at least nrelop_[study name]_...
throw new Error("token "+token+" does not have at least two '_' characters");
throw new Error($translate.instant('config.not-enough-parts-old-style', {"token": token}));
}
if (tokenParts[0] != "nrelop") {
throw new Error("token "+token+" does not start with 'nrelop', please re-check");
throw new Error($translate.instant('config.no-nrelop-start', {token: token}));
}
return tokenParts[1];
}
Expand All @@ -193,20 +193,20 @@ angular.module('emission.config.dynamic', ['emission.plugin.logger'])
// new style study, expects token with sub-group
const tokenParts = token.split("_");
if (tokenParts.length <= 3) { // no subpart defined
throw new Error("Invalid opcode format, expected 'nrelop_study_subgroup_[random string]");
throw new Error($translate.instant('config.not-enough-parts', {token: token}));
}
if (config.opcode.subgroups) {
if (config.opcode.subgroups.indexOf(tokenParts[2]) == -1) {
// subpart not in config list
throw new Error("Invalid opcode, subgroup '"+tokenParts[2]+"' not found in list '"+config.opcode.subgroups+"'");
throw new Error($translate.instant('config.invalid-subgroup', {token: token, subgroup: tokenParts[2], config_subgroups: config.opcode.subgroups}));
} else {
console.log("subgroup "+tokenParts[2]+" found in list");
console.log("subgroup "+tokenParts[2]+" found in list "+config.opcode.subgroups);
return tokenParts[2];
}
} else {
if (tokenParts[2] != "default") {
// subpart not in config list
throw new Error("Invalid opcode, no subgroups, expected 'default' subgroup");
throw new Error($translate.instant('config.invalid-subgroup', {token: token}));
} else {
console.log("no subgroups in config, 'default' subgroup found in token ");
return tokenParts[2];
Expand Down Expand Up @@ -245,10 +245,10 @@ angular.module('emission.config.dynamic', ['emission.plugin.logger'])
// on successful download, cache the token in the rootScope
.then((wasUpdated) => {$rootScope.scannedToken = dc.scannedToken})
.catch((fetchErr) => {
Logger.displayError("Unable to download study config", fetchErr);
Logger.displayError($translate.instant('config.unable-download-config'), fetchErr);
});
} catch (error) {
Logger.displayError("Invalid token format", error);
Logger.displayError($translate.instant('config.invalid-opcode-format'), error);
return Promise.reject(error);
}
});
Expand Down Expand Up @@ -276,7 +276,7 @@ angular.module('emission.config.dynamic', ['emission.plugin.logger'])
$rootScope.$apply(() => dc.saveAndNotifyConfigReady(existingConfig));
}
}).catch((err) => {
Logger.displayError("Error loading config on app start", err)
Logger.displayError($translate('config.error-loading-config-app-start'), err)
});
};
$ionicPlatform.ready().then(function() {
Expand Down

0 comments on commit 36a1aaf

Please sign in to comment.