public class ResourceBundleTranslation extends Object implements Translation
A translation class designed to be used for ResourceBundles. For convenience, most users will want to wrap this in a class that keeps track of resource bundles. A simple implementation would look like:
public class TranslationHelper {
private
static final Function<Locale, ResourceBundle> LOOKUP_FUNC = new
Function<Locale, ResourceBundle>() {
@Nullable @Override
public
ResourceBundle apply(Locale input) {
return ResourceBundle.getBundle("com.mydomain.myplugin.Translations",
input);
}
};
private TranslationHelper() {} // Prevent instance creation
public static Text t(String key, Object... args) {
return Texts.of(new
ResourceBundleTranslation(key, LOOKUP_FUNC), args);
}
}
Constructor and Description |
---|
ResourceBundleTranslation(String key,
Function<Locale,ResourceBundle> bundleFunction)
Create a ResourceBundle-backed translation for the given key and bundle
factory.
|
Modifier and Type | Method and Description |
---|---|
String |
get(Locale locale)
Gets the translation without any parameters replaced.
|
String |
get(Locale locale,
Object... args)
Gets the translation format with the specified parameters.
|
String |
getId()
Gets the identifier for this
Translation . |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
get, get
public ResourceBundleTranslation(String key, Function<Locale,ResourceBundle> bundleFunction)
key
- The key to usebundleFunction
- The bundle function to get a bundle frompublic String getId()
Translation
Translation
.getId
in interface Translation
public String get(Locale locale)
Translation
get
in interface Translation
locale
- The language to get the translated format string forpublic String get(Locale locale, Object... args)
Translation
get
in interface Translation
locale
- The language to get the translated string forargs
- The parameters for this translation