Add multi-language support to your plugin with SimpleLocalization and auto-updating message files
Foundation provides a complete localization system that allows your plugin to support multiple languages. The SimpleLocalization class manages language files with automatic updates and static access.
The SimpleLocalization class is designed for managing localization/messages_LOCALE.yml files. It provides the same auto-update functionality as SimpleSettings but for translation files.
Version: 1# Player messagesWelcome_Message: '&aWelcome to the server, {player}!'Goodbye_Message: '&7See you later, {player}!'# Error messagesError_No_Permission: '&cYou do not have permission to do that.'
4
Load in your plugin
Load the localization in your main plugin class:
@Overrideprotected void onPluginStart() { // Load settings first (contains locale preference) Settings.load(Settings.class); // Then load localization Lang.load(Lang.class);}
Commands: No_Console: '&cYou may only use this command as a player' Invalid_Argument: '&cInvalid argument. Run &6/{label} ? &cfor help.' Cooldown_Wait: '&cWait {duration} second(s) before using this command again.' Reload_Success: '&6{plugin_name} {plugin_version} has been reloaded.'
Foundation automatically validates that the requested locale file exists. If not found, it prevents the plugin from loading with a clear error message.
Use nested classes to organize messages by category:
public class Lang extends SimpleLocalization { public static class Join { public static String FIRST_TIME; public static String WELCOME_BACK; public static String BROADCAST; private static void init() { setPathPrefix("Join"); FIRST_TIME = getString("First_Time"); WELCOME_BACK = getString("Welcome_Back"); BROADCAST = getString("Broadcast"); } } public static class Leave { public static String GOODBYE; public static String BROADCAST; private static void init() { setPathPrefix("Leave"); GOODBYE = getString("Goodbye"); BROADCAST = getString("Broadcast"); } } public static class Errors { public static String GENERIC; public static String NOT_FOUND; public static String NO_PERMISSION; private static void init() { setPathPrefix("Errors"); GENERIC = getString("Generic"); NOT_FOUND = getString("Not_Found"); NO_PERMISSION = getString("No_Permission"); } } @Override protected int getConfigVersion() { return 1; }}
Corresponding YAML structure:
Version: 1Join: First_Time: '&e{player} &7joined the server for the first time!' Welcome_Back: '&aWelcome back, {player}!' Broadcast: '&7[&a+&7] &f{player}'Leave: Goodbye: '&7Thanks for playing, {player}!' Broadcast: '&7[&c-&7] &f{player}'Errors: Generic: '&cAn error occurred. Please contact an administrator.' Not_Found: '&cCould not find {item}.' No_Permission: '&cYou do not have permission: &7{permission}'
public class Lang extends SimpleLocalization { // General messages public static String PREFIX; public static String NO_PERMISSION; // Player messages public static class Player { public static String JOIN_FIRST_TIME; public static String JOIN_WELCOME_BACK; public static String LEAVE; private static void init() { setPathPrefix("Player"); JOIN_FIRST_TIME = getString("Join_First_Time"); JOIN_WELCOME_BACK = getString("Join_Welcome_Back"); LEAVE = getString("Leave"); } } // Command messages public static class Commands { public static String RELOAD_SUCCESS; public static String RELOAD_FAILED; public static List<String> HELP; private static void init() { setPathPrefix("Commands"); RELOAD_SUCCESS = getString("Reload_Success"); RELOAD_FAILED = getString("Reload_Failed"); HELP = getStringList("Help"); } } private static void init() { PREFIX = getString("Prefix"); NO_PERMISSION = getString("No_Permission"); } @Override protected int getConfigVersion() { return 1; }}
Version: 1# Plugin prefix used in messagesPrefix: '&8[&6MyPlugin&8]&7'# General permission errorNo_Permission: '{prefix} &cYou do not have permission.'Player: Join_First_Time: '{prefix} &eWelcome &6{player}&e to the server!' Join_Welcome_Back: '{prefix} &7Welcome back, &f{player}&7!' Leave: '{prefix} &7{player} left the server.'Commands: Reload_Success: '{prefix} &aPlugin reloaded successfully!' Reload_Failed: '{prefix} &cFailed to reload! Check console.' Help: - '&8&m-------------------' - '&6&lMY PLUGIN HELP' - '&e/myplugin reload &7- Reload plugin' - '&e/myplugin help &7- Show this help' - '&8&m-------------------'