Localization
Once you add this module to your plugin, Vital automatically manages a locale for each player.
You can freely change the current player locale by using VitalLocalizationModule.Spigot.setVitalLocale(Player, Locale).
Note: You have to manually assign a locale to every player because Vital does not know how you store each player's locale settings.
Tip: Set your player's locale on join.
To set a player's locale, use VitalLocalizationModule.Spigot.setVitalLocale(Player, Locale).
Once a player has been assigned a locale, you can use VitalLocalizationModule.Spigot.t(Player, String, Object...) to get a translated version of your provided String resource key.
Here's how all of this works.
Your plugin must define a resource bundle that stores all of your translated messages for each language.
By default, Spring will always look for files named messages_*.properties in your src/main/resources folder.
E.g., if you want to have some translated messages for English, you would create a file named messages_en.properties.
If you need to also support German, you would create a file messages_de.properties.
These files will contain something called resource keys and values.
Sounds complicated but is straightforward.
A resource key is basically just a string like servername.pluginname.item.myitem, all of your message bundles MUST have the same resource keys, only the values will change depending on the language file.
E.g., this would be your English file messages_en.properties.
servername.pluginname.item.myitem=My item name
Then this would be your German file messages_de.properties.
servername.pluginname.item.myitem=Mein Item Name
Now whenever you need to use a translated version of your item name, you would use VitalLocalizationModule.Spigot.t(Player, String, Object...) to get the translated version of your resource key for that specific player.
Vital automatically finds the correct resource key values for the player you specified.
So when your player currently has chosen English as his language, the method above would return My item name.
If the player has chosen German the method above would return Mein Item Name.
Easy!
Parameters
Sometimes you also need to show specific data in a translated message, e.g., scores, points, etc.
For that you can use Spring's parameterized message source system.
Again, this sounds complex, but it is very simple, trust me.
Basically all this is, is that each message inside your resource bundles (message_*.properties) can also receive parameters and other values from outside.
E.g., if you need to display a certain dynamic value like a score, etc., your message bundle would look like this.
servername.pluginname.item.myitem=My item name {0}
That {0} above tells Vital and Spring to include parameter 1 of the Object... you provided while calling VitalLocalizationModule.Spigot.t(Player, String, Object...).
E.g., if you call this method like so VitalLocalizationModule.Spigot.t(myplayer, "servername.pluginname.item.myitem", "MY NAME"),
you would get a string like this in return My item name MY NAME.
If you need to provide more parameters, just increment the {0} to {1} and {2} and so on...
Sometimes you also need to manually get translated messages for a specific locale without having access to a player object.
For that you can use VitalLocalizationModule.t(Locale, String, Object...).