Guides · Engineering
How to translate your Minecraft plugin's messages
Message files per language, a language option server owners can set, each player's own client language, and how to decide which translations are worth adding.
A large share of Minecraft servers don't run in English. Their owners will install a plugin with English messages, but they'll translate every line by hand first, or pick the plugin that already speaks their players' language. Translations are one of the cheapest ways to make a plugin easier to choose.
This guide covers how to structure messages so translating is easy, how to let servers and players pick a language, and how to decide which languages are worth the work.
Step 1: get every message out of the code
Before any translation, every text a player or admin can see needs a key. Hard-coded strings are what make translating painful:
// Hard to translate
player.sendMessage("§cYou don't have enough coins.");
// Easy to translate
messages.send(player, "shop.not-enough-coins");
Keep the texts in one file per language, inside your jar:
# messages_en.yml
shop:
not-enough-coins: "&cYou don't have enough coins."
bought: "&aYou bought {item} for {price} coins."
Use named placeholders ({item}, {price}) instead of string concatenation. Word order changes between languages, and a translator can move {price} but can't fix code that glues sentences together.
Step 2: load files as UTF-8 and fall back to English
Accents, Cyrillic and Chinese characters break when a file is read with the wrong charset. Read message files with an explicit charset rather than relying on the server's default:
YamlConfiguration load(String lang) {
File file = new File(getDataFolder(), "messages_" + lang + ".yml");
if (!file.exists()) {
saveResource("messages_" + lang + ".yml", false);
}
try (Reader reader = new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8)) {
YamlConfiguration config = YamlConfiguration.loadConfiguration(reader);
// Keys missing from the server's copy come from the jar's English file
try (Reader defaults = new InputStreamReader(getResource("messages_en.yml"), StandardCharsets.UTF_8)) {
config.setDefaults(YamlConfiguration.loadConfiguration(defaults));
}
return config;
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
The English fallback matters more than it looks. Every update adds new messages, and the translated files are always a step behind. With English defaults, a missing key shows the English text instead of the key name or an exception. Adding new keys to files server owners already edited is the same problem as with config.yml: updating config.yml without resetting it.
Step 3: let the server owner choose
The simplest model, and the one most server owners expect, is one language per server:
# config.yml
language: en
Read it on enable and on reload, and load messages_<language>.yml. Ship every translation you have in the jar and copy them all to the plugin folder, so owners can see which languages exist and fix a line they don't like.
Step 4: or follow each player's client language
On servers with players from several countries, the better answer is each player's own language. The client sends it to the server:
String locale = player.getLocale(); // "en_us", "es_es", "pt_br", "zh_cn"...
Player#getLocale() is available on Spigot since 1.12; on Paper, player.locale() returns it as a java.util.Locale. Map the client's code to the files you have, so es_mx and es_ar can use messages_es.yml when there's no file for them:
String pick(String locale) {
if (available.contains(locale)) return locale;
String language = locale.split("_")[0];
return available.contains(language) ? language : "en";
}
One catch: the client sends its language shortly after joining, so in PlayerJoinEvent the locale may still be the default. Read it each time you send a message instead of caching it at join, and listen to PlayerLocaleChangeEvent if you keep anything per player, so you follow players who switch language mid-game.
A good setup supports both: language: auto to follow each player, or a fixed language for servers that want everything in one. Console and log messages stay in the server's language either way.
Step 5: make translating easy for others
You'll rarely write the translations yourself. Server owners and players contribute them, if it's easy:
- Keep
messages_en.ymlas the reference, with every key, in a public repository. - Accept translations as a pull request or a file in a ticket, and credit translators in the changelog and on your resource page.
- When you add keys, list them in the changelog so translators know what to update. Writing changelogs server owners read
- Keep color codes and placeholders out of the middle of words, so a translator doesn't have to understand your formatting to translate a sentence.
Which languages to add first
A translation is a file you'll keep updating with every release, so start with the ones that reach the most servers. Two kinds of data help.
Where the servers are. With PluginAnalytics, the Servers page shows the countries of the servers running your plugin, on the Free plan. Countries aren't languages, but a large share of servers in Brazil, Spain or Germany is a strong hint. What's collected automatically
What servers choose. On Pro and Premium, Config usage reads plain choices from config.yml, so a language option shows up by itself with the share of servers on each value, next to the default you ship. If many servers set a language you don't ship yet, someone already translated your plugin by hand. Config usage
To see players' own languages, track the locale as an event a few seconds after each join, once the client has sent it:
@EventHandler
public void onJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
getServer().getScheduler().runTaskLater(this, () -> {
if (player.isOnline()) {
analytics.track("locale_reported", player, "locale", player.getLocale());
}
}, 60L);
}
Open the event to see its count by locale; on Pro and Premium, its reach shows the share of players who sent it. Players are sent as an anonymous hash, and the locale is a short code with few possible values, which is what event properties are for. Events
Checklist
- Every visible text has a key; nothing is concatenated.
- Message files read as UTF-8, with English as the fallback for missing keys.
- A
languageoption, withautofor per-player languages if your players are mixed. - The locale read when sending, not cached at join.
- A public reference file and a simple way to send translations.
- New keys listed in the changelog.
More guides
How to update your plugin's config.yml without wiping server owners' settings
New options, renamed keys, changed defaults. How to migrate a Bukkit plugin's config.yml on update without losing what server owners set.
5 min readProductWhich config options do server owners actually change?
Your config.yml has dozens of options. Find out which ones server owners actually change, fix the defaults everyone changes, and read nothing private.
4 min read