Java ResourceBundle for YAML format.
- Accesses YAML-formatted resources via ResourceBundle.
- Supports locale-specific resources according to the ResourceBundle specification.
- Supports YAML values nested in a map or list.
- Supports YAML anchors and aliases indicated by
&
and*
. - Supports multiple YAML documents separated by
---
.
Depends on:
- Java 8, 11 or 17
- Kotlin 1.7
- SnakeYAML 1.29
The artifact is published on Maven Central Repository. If you are using Maven, add the following dependency.
<dependency>
<groupId>dev.akkinoc.util</groupId>
<artifactId>yaml-resource-bundle</artifactId>
<version>${yaml-resource-bundle.version}</version>
</dependency>
Create a YAML-formatted resource file on the classpath. Also, create locale-specific resource files as needed.
For example (resource.yml, resource_en.yml, resource_fr.yml, etc):
fruits:
apple: Apple
orange: Orange
grape: Grape
colors:
- Red
- Orange
- Purple
Access the resource via YamlResourceBundle.
For example in Java:
import dev.akkinoc.util.YamlResourceBundle;
// Gets the resource bundle
// YamlResourceBundle.Control is specified for ResourceBundle.Control
ResourceBundle bundle = ResourceBundle.getBundle(
"resource", YamlResourceBundle.Control.INSTANCE);
// Gets the map values
System.out.println(bundle.getString("fruits.apple")); // => "Apple" or localized value
System.out.println(bundle.getString("fruits.orange")); // => "Orange" or localized value
System.out.println(bundle.getString("fruits.grape")); // => "Grape" or localized value
// Gets the list values
System.out.println(bundle.getString("colors[0]")); // => "Red" or localized value
System.out.println(bundle.getString("colors[1]")); // => "Orange" or localized value
System.out.println(bundle.getString("colors[2]")); // => "Purple" or localized value
// Gets the list values as an array
System.out.println(Arrays.toString(bundle.getStringArray("colors")));
// => "[Red, Orange, Purple]" or localized values
// Gets the all keys
System.out.println(bundle.keySet());
// => "[fruits.apple, fruits.orange, fruits.grape,
// colors, colors[0], colors[1], colors[2]]" (not sorted)
Please refer to the Javadoc.
Please refer to the Releases page.
Licensed under the Apache License, Version 2.0.
If this project is useful to you, I appreciate giving a ⭐ star to this repository. I would also appreciate if you would consider 💖 sponsoring as well. Your support is my biggest motive force. Thanks ✨