-
Notifications
You must be signed in to change notification settings - Fork 1
Properties Storage
Properties files are the Java standard for key value dictionary serializations and therefore also localizations. It makes sense to use this format as a Message storage and is one of the suggested choices for this framework.
To create a pre-implemented MessageStorage, you can use the class de.cubbossa.translations.persistent.PropertiesMessageStorage
.
// parameter is a directory that contains all message files. Message files are of format [locale-tag].properties.
translations.setMessageStorage(new PropertiesStorage(new File(plugin.getDataFolder(), "/lang/")));
Set a file prefix and suffix can be specified to have files follow the name [prefix][locale-tag][suffix].properties
.
IMPORTANT
Common practice would be to create different default localizations in your resources directory and save then when your plugin starts and they don't exist.
This can cause issues under certain conditions. .properties
files are ISO-8859-1
encoded, which does not allow any special characters other than latin.
This is pretty bad for locale files, which of course will contain many special characters like éêäöüß or for example chinese symbols. I therefore decided to load .properties
files UTF-8
encoded. This will only work, if you create your premade locale files also UTF-8
encoded.
Intellij must be explicitly configured to use UTF-8
.
Go to: Settings > File Encodings > Default encoding for properties files
and set it to UTF-8
Similar to the PropertiesMessageStorage, you can create an instance of the de.cubbossa.translations.persistent.PropertiesStyleStorage
.
// specify a file this time. It must not exist
translations.setStyleStorage(new PropertiesStyleStorage(new File(plugin.getDataFolder(), "/test/styles.properties")));