mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-08 06:01:22 +00:00
GUACAMOLE-926: Always use translation system for errors.
This commit is contained in:
@@ -155,6 +155,10 @@ angular.module('import').directive('connectionImportErrors', [
|
||||
if (!patchFailure || !parseResult)
|
||||
return;
|
||||
|
||||
// All promises from all translation requests. The scope will not be
|
||||
// updated until all translations are ready.
|
||||
const translationPromises = [];
|
||||
|
||||
// Set up the list of connection errors based on the existing parse
|
||||
// result, with error messages fetched from the patch failure
|
||||
$scope.connectionErrors = parseResult.patches.map(
|
||||
@@ -166,10 +170,24 @@ angular.module('import').directive('connectionImportErrors', [
|
||||
// Set the error from the PATCH request, if there is one
|
||||
const error = _.get(patchFailure, ['patches', index, 'error']);
|
||||
if (error)
|
||||
connectionError.errors = new DisplayErrorList([error]);
|
||||
|
||||
// Fetch the translation and update it when it's ready
|
||||
translationPromises.push($translate(
|
||||
error.key, error.variables)
|
||||
.then(translatedError =>
|
||||
connectionError.errors.getArray().push(translatedError)
|
||||
));
|
||||
|
||||
return connectionError;
|
||||
|
||||
});
|
||||
|
||||
// Once all the translations have been completed, update the
|
||||
// connectionErrors all in one go, to ensure no excessive reloading
|
||||
$q.all(translationPromises).then(() => {
|
||||
$scope.connectionErrors = connectionErrors;
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
// If a new parse result with errors is seen, update the display list
|
||||
|
@@ -61,6 +61,13 @@ angular.module('import').factory('ParseError', [function defineParseError() {
|
||||
*/
|
||||
this.variables = template.variables;
|
||||
|
||||
// If no translation key is available, fall back to the untranslated
|
||||
// key, passing the raw message directly through the translation system
|
||||
if (!this.key) {
|
||||
this.key = 'APP.TEXT_UNTRANSLATED';
|
||||
this.variables = { MESSAGE: this.message };
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
return ParseError;
|
||||
|
@@ -68,7 +68,7 @@ angular.module('rest').factory('DirectoryPatchOutcome', [
|
||||
* The error message associated with the failure, if the patch failed to
|
||||
* apply.
|
||||
*
|
||||
* @type {String}
|
||||
* @type {TranslatableMessage}
|
||||
*/
|
||||
this.error = template.error;
|
||||
|
||||
|
Reference in New Issue
Block a user