Skip to content

Using localization

This will focus on how bundles are defined using the default configuration.

Bundle paths

By default, bundles have a .json extension and are located in a bc_localization folder of your app's resources.

Root bundle

The first bundle we create is the called the "root" bundle (Locale.ROOT), it does not have a specific language.

This is the last fallback if a locale is not available for a given bundle name.

Tip

Even if you don't provide translations, using a root bundle is still useful to separate text content from your code.

Example

The path to a root bundle would be src/main/resources/bc_localization/MyBundle.json.

Localized bundles

Additional bundles can be added for translation purposes, they merge in parent bundles. (parent locales and root locale)

Localized bundles are not required to override all templates, also, if a bundle with a locale cannot be found, it will try to get the nearest parent locale.

Example

The path to a localized bundle would be src/main/resources/bc_localization/MyBundle_fr_FR.json.

Default bundles

For a given bundle name and locale, the DefaultLocalizationMapProvider will look up bundles for that locale using both the provided name, but also a bundle with a -default suffix before the locale.

The "non-default" bundle will be merged into the -default suffixed bundle.

Example

The path to a localized default bundle would be src/main/resources/bc_localization/MyBundle-default_fr_FR.json.

Templates

By default, templates are based on MessageFormat. (except we use named arguments, not 0-based indexes)

Example

{
    "path.to.my.template": "Hello world!"
}
{
    "path.to": {
        "my.template": "Hello world!"            
    }
}
{
    "path.to.my.template": "Hello {name}!"
}

Tip

You can find more details about MessageFormat in section 4.1 and 4.2 on Baeldung.

Locale providers

A few interfaces define methods which, for a given context, returns a locale.

You can override those providers with your own implementations, for example, if you wish to have your own per-user or per-guild locale settings.

For interactions

For text commands