Skip to content

Developer API

Vitor Albert edited this page Mar 6, 2026 · 1 revision

🔌 For Developers (API)

Want to hook into IGLanguages? Here is how to use our API.

1. Add Repository & Dependency

Maven

<repositories>
    <repository>
        <id>jitpack.io</id>
        <url>https://jitpack.io</url>
    </repository>
</repositories>

<dependency>
    <groupId>com.github.IceGames23</groupId>
    <artifactId>IGLanguages</artifactId>
    <version>{LATEST_VERSION}</version>
    <scope>provided</scope>
</dependency>

Gradle

repositories {
    maven { url 'https://jitpack.io' }
}

dependencies {
    compileOnly 'com.github.IceGames23:IGLanguages:{LATEST_VERSION}'
}

2. Access variables via PlaceholderAPI

Use these placeholders in your own plugin or config:

  • %lang_player% - Returns the player's current language code (e.g., en_us).
  • %lang_keys_path% - Returns a translated string from the language file.
    • Example: %lang_messages.prefix% gets the prefix key from messages.yml.

3. Java API Usage

import me.icegames.iglanguages.IGLanguages;
import me.icegames.iglanguages.api.IGLanguagesAPI;

public void onEnable() {
    if (Bukkit.getPluginManager().isPluginEnabled("IGLanguages")) {
        IGLanguagesAPI api = IGLanguages.getInstance().getAPI();

        // Get a translation for a player
        String message = api.getPlayerTranslation(player, "messages.welcome");
        player.sendMessage(message);

        // Get a translation with arguments ({0}, {1}, ...)
        String lobby = api.getPlayerTranslation(player, "menus.lobby_server_name", "#01");
        String lore = api.getPlayerTranslation(player, "menus.lobby_server_lore", "42", "100");

        // Get translation by language code with arguments
        String msg = api.getLangTranslation("en_us", "menus.lobby_server_name", "Arena");

        // Get default language
        String defaultLang = api.getDefaultLang();

        // Check if language exists
        if(api.hasLanguage("pt_br")) {
             // ...
        }

        // Reload the plugin
        api.reload();
    }
}

Available API Methods

Method Description
getPlayerLang(Player) Gets the player's current language code.
setPlayerLang(Player, String) Sets and saves a player's language.
getPlayerTranslation(Player, String) Gets a translation using the player's language.
getPlayerTranslation(Player, String, String...) Gets a translation with parameterized arguments ({0}, {1}, ...).
getLangTranslation(String, String) Gets a translation for a specific language code.
getLangTranslation(String, String, String...) Gets a translation for a language with parameterized arguments.
getAvailableLangs() Returns a list of all loaded language codes.
getDefaultLang() Returns the server's default language.
hasLanguage(String) Checks if a language code is loaded.
reload() Reloads the plugin configuration and languages.

Clone this wiki locally