Class TomlResourceBundle

java.lang.Object
java.util.ResourceBundle
be.imgn.toml.i18n.TomlResourceBundle

public final class TomlResourceBundle extends ResourceBundle

A resource bundle whose resources are the values of a TOML table.

Tables are flattened into dotted keys: the document

title = "Inventory"

[errors]
not-found = "No item {0}"
retries = 3

has the keys title, errors.not-found and errors.retries. Two values whose keys flatten to the same one, such as "a.b" = 1 and a.b = 2, are an error.

The values keep their TOML type: ResourceBundle.getObject(String) returns a String, a Long, a Double, a Boolean, an OffsetDateTime, a LocalDateTime, a LocalDate or a LocalTime, and an array of strings is a String[], which ResourceBundle.getStringArray(String) returns. Any other array is an error. The typed getters, such as getLong(String), look the value up as ResourceBundle.getObject(String) does, through the parents of the bundle, and check its type.

ResourceBundle.getBundle(String, Locale, ResourceBundle.Control) loads bundles from .toml resources, such as Messages_fr_BE.toml, with the control control() returns:

ResourceBundle messages = ResourceBundle.getBundle("com.example.Messages", locale, TomlResourceBundle.control());

A named module cannot pass a control to getBundle: it loads its bundles through a TomlResourceBundleProvider instead.

Since:
0.1.0