DefaultJsonLocalizationMapReader

Implementation for LocalizationTemplate mappings readers.

Default behavior

Localization templates are loaded from the /bc_localization folder (i.e., the bc_localization in your jar's root) Your localization bundle must be a valid JSON file and use the .json extension. The localization bundle can use any name, but must be suffixed with the same locale formatting as ResourceBundle would use, such as _fr or _en_US.

The JSON content root must be an object, where the keys must either be delimited by dots, or by using nested objects.

Example


    {
        "myCommand": {
            "name": "my_command_in_en_US",
            "description": "My command description in US english"
        }
    }

This reader uses the default localization templates, see DefaultLocalizationTemplate for more details.

Customization

You can create more DefaultJsonLocalizationMapReader instances with different folder names, by creating a service factory, with a different folder name given in the constructor. Example - Kotlin
@BConfiguration
object LocalizationProviders {
@BService
// Creates a new LocalizationMapReader which finds its JSON files in the "locales" folder fun localesLocalizationReader(context: BContext): LocalizationMapReader { return DefaultJsonLocalizationMapReader(context, "locales") } }
Example - Java
@BConfiguration
public class LocalizationProviders {
@BService
// Creates a new LocalizationMapReader which finds its JSON files in the "locales" folder public LocalizationMapReader localesLocalizationReader(BContext context) { return new DefaultJsonLocalizationMapReader(context, "locales"); } }

See also

Constructors

Link copied to clipboard
constructor(context: BContext, folderName: String)

Functions

Link copied to clipboard
open fun appendPath(path: String, other: String): String
Utility method to append a path component to an existing path, this is simply path + '.' + other.
Link copied to clipboard
Reads a LocalizationMap from the requested bundle, returns null if no localization map exists.