Augmented.js Next Core - Resource Bundle
Resource bundles contain locale-specific objects. When your program needs a locale-specific resource, a String for example, your program can load it from the resource bundle that is appropriate for the current user's locale. In this way, you can write program code that is largely independent of the user's locale isolating most, if not all, of the locale-specific information in resource bundles.
This allows you to write programs that can:
- be easily localized, or translated, into different languages
- handle multiple locales at once
- be easily modified later to support even more locales
ResourceBundle
options
(optional, default{}
)
fallback
boolean Is fallback support enabled
bundle
object The bundle used
delimiter
string The key delimiter (if fallback is enabled)
Get a string from the bundle by key
key
string The key to find in the bundle
Returns string Message from bundle, [key] if not found, or null if missing the key
locale
string The locale
language
string The language
country
string The country
MessageKeyFormatter
Concatenate the pieces of the message together if a portion of the key is missing, the rest of the key is ignored. ex. if the "rule" attribute is missing, then the key will return with the message.level + message.kind only
options
(optional, default{}
)
Key Delimiter
delimiter
string The delimter used to seperate each key
Format a key for a message
message
object The message to format (optional, default{}
)
Returns any The key to lookup in a bundle
MapFormatter - Maps a JSON object of keys to new text
Replaces a string with replacement text from a JSON object.
Will replace all instances marked with the key name
const message = MapFormatter.format("This is a test of {ebs}.", { "ebs": "the Emergency Broadcast System" });
Returns string Returns the string with replaced text