com.softicar.platform.common.core.i18n.InternalI18nTranslator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of platform-common Show documentation
Show all versions of platform-common Show documentation
The SoftiCAR Platform is a lightweight, Java-based library to create interactive business web applications.
package com.softicar.platform.common.core.i18n;
import com.softicar.platform.common.core.locale.CurrentLocale;
import java.util.IllegalFormatException;
class InternalI18nTranslator {
public static String translate(String text, Object...args) {
return translate(CurrentLocale.get().getLanguage(), text, args);
}
public static String translate(LanguageEnum language, String text, Object...args) {
if (isNullOrEmpty(text)) {
return text;
}
String translation = getTranslation(language, text);
return getExpanded(translation, args);
}
private static boolean isNullOrEmpty(String text) {
return text == null || text.trim().isEmpty();
}
private static String getTranslation(LanguageEnum language, String text) {
if (language != null) {
return CurrentLanguageTranslator.get().translate(language, text);
} else {
return text;
}
}
private static String getExpanded(String translation, Object...args) {
try {
return String.format(translation, args);
} catch (IllegalFormatException exception) {
if (args.length == 0) {
return translation;
} else {
throw exception;
}
}
}
}