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.

@FunctionalInterface public interface StringBundle
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 Type
    Method
    Description
    lookup(String key, Locale locale)
    The translation for key in locale, or null when this bundle does not have one.
    default void
    prepare(Locale locale)
    Loads whatever answering locale will need.
    default void
    release(Locale locale)
    Drops whatever prepare(java.util.Locale) loaded for locale: nothing reads it any more.
  • Method Details

    • lookup

      String lookup(String key, Locale locale)
      The translation for key in locale, or null when this bundle does not have one. Called on the UI thread during measure and paint, so it must not block; see prepare(java.util.Locale).
    • prepare

      default void prepare(Locale locale)
      Loads whatever answering locale will need. Called by I18n.setLocale(java.util.Locale), I18n.addBundle(limn.i18n.StringBundle) and I18n.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) returning null, not a failure.

    • release

      default void release(Locale locale)
      Drops whatever prepare(java.util.Locale) loaded for locale: nothing reads it any more. Called by I18n when the process moves off a language no subtree retains, and when the last retain for a subtree language is released. A later prepare for the same locale must work again. Default: nothing, the right answer for a bundle that holds no per-locale state.