GUACAMOLE-955: Provide default translation string for all untranslated messages.

This commit is contained in:
Michael Jumper
2020-02-10 22:03:35 -08:00
parent b51d2a88b8
commit ea8e181e2c
2 changed files with 20 additions and 2 deletions

View File

@@ -20,6 +20,7 @@
package org.apache.guacamole.rest; package org.apache.guacamole.rest;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import org.apache.guacamole.GuacamoleClientException; import org.apache.guacamole.GuacamoleClientException;
import org.apache.guacamole.GuacamoleException; import org.apache.guacamole.GuacamoleException;
import org.apache.guacamole.GuacamoleResourceNotFoundException; import org.apache.guacamole.GuacamoleResourceNotFoundException;
@@ -37,6 +38,19 @@ import org.apache.guacamole.tunnel.GuacamoleStreamException;
*/ */
public class APIError { public class APIError {
/**
* The translation key of the generic translation string which should be
* used to display arbitrary messages which otherwise have no translation
* string.
*/
private static final String UNTRANSLATED_MESSAGE_KEY = "APP.TEXT_UNTRANSLATED";
/**
* The name of the placeholder within the translation string associated with
* UNTRANSLATED_MESSAGE_KEY that should receive the raw, untranslated text.
*/
private static final String UNTRANSLATED_MESSAGE_VARIABLE_NAME = "MESSAGE";
/** /**
* The human-readable error message. * The human-readable error message.
*/ */
@@ -187,8 +201,11 @@ public class APIError {
Translatable translatable = (Translatable) exception; Translatable translatable = (Translatable) exception;
this.translatableMessage = translatable.getTranslatableMessage(); this.translatableMessage = translatable.getTranslatableMessage();
} }
// Use generic translation string if message is not translated
else else
this.translatableMessage = new TranslatableMessage(this.message); this.translatableMessage = new TranslatableMessage(UNTRANSLATED_MESSAGE_KEY,
Collections.singletonMap(UNTRANSLATED_MESSAGE_VARIABLE_NAME, this.message));
} }

View File

@@ -46,7 +46,8 @@
"INFO_ACTIVE_USER_COUNT" : "Currently in use by {USERS} {USERS, plural, one{user} other{users}}.", "INFO_ACTIVE_USER_COUNT" : "Currently in use by {USERS} {USERS, plural, one{user} other{users}}.",
"TEXT_ANONYMOUS_USER" : "Anonymous", "TEXT_ANONYMOUS_USER" : "Anonymous",
"TEXT_HISTORY_DURATION" : "{VALUE} {UNIT, select, second{{VALUE, plural, one{second} other{seconds}}} minute{{VALUE, plural, one{minute} other{minutes}}} hour{{VALUE, plural, one{hour} other{hours}}} day{{VALUE, plural, one{day} other{days}}} other{}}" "TEXT_HISTORY_DURATION" : "{VALUE} {UNIT, select, second{{VALUE, plural, one{second} other{seconds}}} minute{{VALUE, plural, one{minute} other{minutes}}} hour{{VALUE, plural, one{hour} other{hours}}} day{{VALUE, plural, one{day} other{days}}} other{}}",
"TEXT_UNTRANSLATED" : "{MESSAGE}"
}, },