Online translation interface integrated into Developer panel

This commit is contained in:
Georgy Litvinov 2021-07-05 18:50:03 +02:00
parent 52ed9b117b
commit 0fc2218b88
5 changed files with 118 additions and 66 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.
@ -23,7 +26,6 @@ public class I18nBundle {
private static final String startSep = "\u25a4";
private static final String endSep = "\u25a5";
private static final String intSep = "\u25a6";
private static boolean exportInfo = true;
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}''";
@ -84,7 +86,7 @@ public class I18nBundle {
if (i18nLogger != null) {
i18nLogger.log(bundleName, key, parameters, textString, message);
}
if (exportInfo) {
if (isNeedExportInfo()) {
String separatedArgs = "";
for (int i = 0; i < parameters.length; i++) {
separatedArgs += parameters[i] + intSep;
@ -95,6 +97,10 @@ public class I18nBundle {
}
}
private static boolean isNeedExportInfo() {
return DeveloperSettings.getInstance().getBoolean(Key.I18N_ONLINE_TRANSLATION);
}
private static String formatString(String textString, Object... parameters) {
if (parameters.length == 0) {

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.
*/