Default Json Localization Map Reader
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"
}
}
Content copied to clipboard
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
Content copied to clipboard
object LocalizationProviders {
@BService
Content copied to clipboard // Creates a new LocalizationMapReader which finds its JSON files in the "locales" folder
fun localesLocalizationReader(context: BContext): LocalizationMapReader {
return DefaultJsonLocalizationMapReader(context, "locales")
}
}
Content copied to clipboard
@BConfiguration
Content copied to clipboard
public class LocalizationProviders {
@BService
Content copied to clipboard // Creates a new LocalizationMapReader which finds its JSON files in the "locales" folder
public LocalizationMapReader localesLocalizationReader(BContext context) {
return new DefaultJsonLocalizationMapReader(context, "locales");
}
}
Content copied to clipboard
See also
Constructors
Link copied to clipboard
Constructs a new DefaultJsonLocalizationMapReader.
Functions
Link copied to clipboard
Utility method to append a path component to an existing path, this is simply
path + '.' + other
.Link copied to clipboard
open fun readLocalizationMap(@NotNull request: @NotNull LocalizationMapRequest): @Nullable LocalizationMap
Reads a LocalizationMap from the requested bundle, returns
null
if no localization map exists.