Class PropertyBundle
- All Implemented Interfaces:
StringBundle
StringBundle backed by UTF-8 .properties files on the classpath,
one family per domain:
I18n.addBundle(PropertyBundle.family("/i18n/common"));
I18n.addBundle(PropertyBundle.family("/i18n/settings")); // one per screen
I18n.addBundle(PropertyBundle.family("/i18n/editor")); // as many as it takes
A family is base.properties plus one file per language tag, and a
locale is served by merging them least-specific first (base, then
_pt, then _pt-BR), so a regional file carries only what it changes
and a language file carries the rest. Underscores are accepted in place of the
hyphen (_pt_BR), since that is how the JDK spells the same thing.
Files are read in prepare(java.util.Locale), which I18n calls before anything can
ask for a string; lookup(java.lang.String, java.util.Locale) is then a hash get. A missing file is not an
error; it is simply a language this domain does not translate, and the caller's
English stands.
UTF-8, not ISO-8859-1: these files are read through a Reader, so
Japanese and Cyrillic go in literally instead of as \\uXXXX escapes.
-
Method Summary
Modifier and TypeMethodDescriptionstatic PropertyBundleA family rooted atbaseResourcePath, resolved against the class loader that loaded this class.static PropertyBundlefamily(String baseResourcePath, ClassLoader loader) A family loaded through a specific class loader, for modular or plugin layouts.The translation forkeyinlocale, ornullwhen this bundle does not have one.static StringBundleA bundle holding one locale's strings directly, for translations that were downloaded, generated, or assembled in a test rather than shipped as a file.voidLoads whatever answeringlocalewill need.voidDrops whateverStringBundle.prepare(java.util.Locale)loaded forlocale: nothing reads it any more.toString()
-
Method Details
-
family
A family rooted atbaseResourcePath, resolved against the class loader that loaded this class.- Parameters:
baseResourcePath- an absolute classpath path without the.propertiessuffix;"/i18n/settings"finds/i18n/settings_pt-BR.properties
-
family
A family loaded through a specific class loader, for modular or plugin layouts. -
of
A bundle holding one locale's strings directly, for translations that were downloaded, generated, or assembled in a test rather than shipped as a file. -
prepare
Description copied from interface:StringBundleLoads whatever answeringlocalewill need. Called byI18n.setLocale(java.util.Locale),I18n.addBundle(limn.i18n.StringBundle)andI18n.retainLocale(java.util.Locale)before listeners are notified, which is the whole point of the method: without it a file-backed bundle would read from disk lazily, and the first read would land inside the measure pass of the frame that switches the language.More than one locale may be prepared at a time: the process locale, and every retained subtree locale. A bundle that keeps per-locale state keeps it for each until
StringBundle.release(java.util.Locale)says otherwise.Must not throw for a locale it cannot serve; a missing translation is
StringBundle.lookup(java.lang.String, java.util.Locale)returningnull, not a failure.- Specified by:
preparein interfaceStringBundle
-
release
Description copied from interface:StringBundleDrops whateverStringBundle.prepare(java.util.Locale)loaded forlocale: nothing reads it any more. Called byI18nwhen the process moves off a language no subtree retains, and when the last retain for a subtree language is released. A laterpreparefor the same locale must work again. Default: nothing, the right answer for a bundle that holds no per-locale state.- Specified by:
releasein interfaceStringBundle
-
lookup
Description copied from interface:StringBundleThe translation forkeyinlocale, ornullwhen this bundle does not have one. Called on the UI thread during measure and paint, so it must not block; seeStringBundle.prepare(java.util.Locale).- Specified by:
lookupin interfaceStringBundle
-
toString
-