public class ResourceBundleTranslation extends Object implements Translation
public class TranslationHelper { private static final Function<Locale, ResourceBundle> LOOKUP_FUNC = new Function<Locale, ResourceBundle>() { &at;Nullable &at;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,
java.util.function.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 default translation without any parameters replaced.
|
String |
get(Locale locale,
Object... args)
Gets the default translation format with the specified parameters.
|
String |
getId()
Returns identifier for this
Translation . |
public ResourceBundleTranslation(String key, java.util.function.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