Jackson Localization Map Reader
LocalizationMapReader based on an ObjectMapper.
Usage
Declare a service factory returning an instance of this class, using the factory methods.
You may supply a LocalizationTemplateFunction to customize the templates being filled, if the default provider is not enough.
Example - YAML reader
You must add the jackson-dataformat-yaml dependency, make sure to match the version that JDA uses to avoid incompatibilities.
Note that the following example works the same for any data type, just replace YAMLFactory
by JSONFactory
or any other formats.
Kotlin
@BConfiguration
object LocalizationMapReaderProvider {
@BService // Creates a new LocalizationMapReader which finds its YAML files in the "doxxy" folder
fun doxxyLocalizationReader(context: BContext): LocalizationMapReader {
return JacksonLocalizationMapReader.createWithDefaultTemplate(
context,
ObjectMapper(YAMLFactory()),
folderName = "doxxy",
extensions = listOf("yaml", "yml")
)
}
}
Java
@BConfiguration
public class LocalizationMapReaderProvider {
@BService // Creates a new LocalizationMapReader which finds its YAML files in the "doxxy" folder
public static LocalizationMapReader doxxyLocalizationReader(BContext context) {
return JacksonLocalizationMapReader.createWithDefaultTemplate(
context,
new ObjectMapper(new YAMLFactory()),
/* folderName */"doxxy",
/* extensions */List.of("yaml", "yml")
);
}
}
Default implementation
A built-in instance is available, and reads JSON bundles in the bc_localization
folder, however, you are encouraged to register your own reader, to properly separate bundles and eliminate collisions.
Functions
Utility method to append a path component to an existing path, this is simply path + '.' + other
.
Retrieves the InputStream from the requested localization map, may return null
if none can be found.
Reads a LocalizationMap from the requested bundle, returns null
if no localization map exists.