added online Translations

This commit is contained in:
Georgy Litvinov 2021-10-14 18:35:58 +02:00
parent 2519c4a6a7
commit b6f0ed229c
9 changed files with 714 additions and 8 deletions

View file

@ -10,6 +10,9 @@ import java.util.ResourceBundle;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import edu.cornell.mannlib.vitro.webapp.utils.developer.DeveloperSettings;
import edu.cornell.mannlib.vitro.webapp.utils.developer.Key;
/**
* A wrapper for a ResourceBundle that will not throw an exception, no matter
* what string you request.
@ -20,7 +23,9 @@ import org.apache.commons.logging.LogFactory;
*/
public class I18nBundle {
private static final Log log = LogFactory.getLog(I18nBundle.class);
private static final String startSep = "\u25a4";
private static final String endSep = "\u25a5";
private static final String intSep = "\u25a6";
private static final String MESSAGE_BUNDLE_NOT_FOUND = "Text bundle ''{0}'' not found.";
private static final String MESSAGE_KEY_NOT_FOUND = "Text bundle ''{0}'' has no text for ''{1}''";
@ -75,13 +80,26 @@ public class I18nBundle {
key);
log.warn(message);
textString = "ERROR: " + message;
}
String result = formatString(textString, parameters);
}
String message = formatString(textString, parameters);
if (i18nLogger != null) {
i18nLogger.log(bundleName, key, parameters, textString, result);
i18nLogger.log(bundleName, key, parameters, textString, message);
}
return result;
if (isNeedExportInfo()) {
String separatedArgs = "";
for (int i = 0; i < parameters.length; i++) {
separatedArgs += parameters[i] + intSep;
}
return startSep + key + intSep + textString + intSep + separatedArgs + message + endSep;
} else {
return message;
}
}
private static boolean isNeedExportInfo() {
return DeveloperSettings.getInstance().getBoolean(Key.I18N_ONLINE_TRANSLATION);
}
private static String formatString(String textString, Object... parameters) {

View file

@ -43,7 +43,10 @@ public enum Key {
* Load language property files every time they are requested.
*/
I18N_DEFEAT_CACHE("developer.i18n.defeatCache", true),
/**
* Enable online translations.
*/
I18N_ONLINE_TRANSLATION("developer.i18n.onlineTranslation", true),
/**
* Enable the I18nLogger to log each string request.
*/