Package limn.i18n
Interface StringBundle
- All Known Implementing Classes:
PropertyBundle
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
A source of translations. Registered with
I18n.addBundle(limn.i18n.StringBundle), asked for one
key at a time, and free to be backed by anything: a properties file
(PropertyBundle), a map, a downloaded table, a database.
A bundle answers only for what it owns: returning null passes the key
to the next bundle and, in the end, to the English the I18nString carries.
That is what lets an application register one bundle per screen without any of
them knowing about the others.
-
Method Summary
Modifier and TypeMethodDescriptionThe translation forkeyinlocale, ornullwhen this bundle does not have one.default voidLoads whatever answeringlocalewill need.default voidDrops whateverprepare(java.util.Locale)loaded forlocale: nothing reads it any more.
-
Method Details
-
lookup
The translation forkeyinlocale, ornullwhen this bundle does not have one. Called on the UI thread during measure and paint, so it must not block; seeprepare(java.util.Locale). -
prepare
Loads 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
release(java.util.Locale)says otherwise.Must not throw for a locale it cannot serve; a missing translation is
lookup(java.lang.String, java.util.Locale)returningnull, not a failure. -
release
Drops whateverprepare(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.
-