HomeJavaModsAO18n
AO18n
ModsJava

AO18n

Localization System (API) One YAML File, endless Languages

⬇ Download on HangarOpen in MCModsHubGet it on Google Play →
Add the following dependency to your project's pom.xml file: ``` de.alphaomega-it.ao18n AO18n 2.1 ``` **Step 2: Initialize AO18n in Your JavaPlugin class** Add the following method 'onLoad' to your class ```java import com.alphaomegait.ao18n.AO18n; public class Plugin extends JavaPlugin { //Called when the plugin is being loaded. @Override public void onLoad() { // argument 1: class which does extend the JavaPlugin // argument 2: if the language file should be replaced in the plugin folder new AO18n(this, false); } } ``` **Step 2.1: Use it for Internationalization** Since we initialized the Dependency you can use the classes as long the .yml format of the i18n.yml file is correct. ```java import de.alphaomegait.ao18n.I18n; import org.bukkit.entity.Player; // can be whatever class you want public class Example { //Send the player a message based on the message-key in your i18n.yml file //It takes if available the player client language, if the language does not //exist. It will take the fallback/default language key. //.build().sendMessage() will send a message as string. //.build().sendMessageAsComponent() will send a message using the https://docs.advntr.dev/minimessage/index.html dependency as a Text Component public void sendHelloWorldMessage( final Player player ) { new I18n.Builder( "message-key", player ).hasPrefix(true) .build() .sendMessageAsComponent(); } } ``` **Step 3: Configure Translations** Create a translation file in the appropriate directory. By default, AO18n looks for the translation file in the src/main/resources/translations directory. Here's an example structure: src └── main └── resources └── translations ├── i18n.yml **Step 3.1: Fill the Translation File** Now you have to fill in the missing Language keys and Locales in the right format like below: ```yaml # This file contains the configuration settings for internationalization (i18n). # Please make sure to update the following values according to your requirements. # See https://wiki.atwoo.eu for more information. defaultLocale: 'en' translations: #Prefix has to be a key to make the function #showPrefix work prefix: de: - 'Dies ist eine Nachricht' en: - 'This is a message' message_key_2: de: - 'Dies ist eine Nachricht 2' - 'Dies ist eine Nachricht 3' en: - 'This is a message 2' - 'This is a message 3' message_key_3: de: - 'Dies ist eine Nachricht 4' - 'Dies ist eine Nachricht mit einem Platzhalter {0}' en: - 'This is a message 4' - 'This is a message with a placeholder {0}' message_key_4: de: - '{0}, {1}, {2} etc. Platzhalter...' en: - '{0}, {1}, {2} etc. Placeholder...' ```

AO18n is a free Minecraft Java mod. Compatible with Minecraft 1.16, 1.16.1, 1.16.2, 1.16.3 and newer. Downloaded 2 times (via Hangar). Download it and open it directly in the game.

Explore more