Repository navigation
Localization
Elib 1.5.1+26.3 provides one language preference for Elib and registered mods. Players choose it in Elib Config → Language. It changes registered mods' translated text while leaving Minecraft's own language unchanged.
The default is Automatic: use the Minecraft client's locale when it is in Elib's supported list; otherwise use English (en_us). Players can also choose a supported language explicitly. The same preference is used on Fabric, NeoForge, and Quilt.
If you already use ElibConfigRegistry.register(...), its namespace is registered for localization automatically. See Config Menu Integration.
To use the language preference without adding a config-screen entry, register during client initialization:
import dev.elpu7.elib.client.ElibLanguage;
ElibLanguage.register("examplemod", ExampleClient.class);Replace ExampleClient.class with a class from your own mod's JAR. Elib uses it to locate your language resources. The namespace must match your resource directory and use lowercase letters, digits, underscores, dots, or hyphens.
Always include an English fallback in your mod at:
src/main/resources/assets/examplemod/lang/en_us.json
In a project with shared resources, put the same assets/... structure under that module's resource directory. It must appear at assets/examplemod/lang/en_us.json inside the built JAR.
{
"screen.examplemod.title": "Example Mod Settings",
"option.examplemod.enabled": "Enabled",
"option.examplemod.speed": "Speed: %s"
}Use translatable components in your UI:
import net.minecraft.network.chat.Component;
Component title = Component.translatable("screen.examplemod.title");
Component speed = Component.translatable("option.examplemod.speed", "1.0");Keep your namespace in each translation key. Elib accepts keys that start with examplemod., contain .examplemod., or end with .examplemod. For example, screen.examplemod.title is accepted; a generic key such as screen.title is not.
There are two ways to supply translations:
| Location | Resource path inside the JAR | Distribution |
|---|---|---|
| Your mod | assets/examplemod/lang/fi_fi.json |
Ships with your mod |
| Elib | assets/elib/translations/examplemod/fi_fi.json |
Ships with an Elib release |
Both use the same flat JSON format as en_us.json. For example, Finnish text could be:
{
"screen.examplemod.title": "Example Modin asetukset",
"option.examplemod.enabled": "Käytössä",
"option.examplemod.speed": "Nopeus: %s"
}Keep placeholders such as %s consistent with the English text.
Elib already bundles the non-English translations for Freecam and PieChart. Their own JARs contain only their English fallback files.
To centralize another mod's translations, contribute its non-English files to the Elib project under:
common/src/main/resources/assets/elib/translations/examplemod/<locale>.json
Those files become available when an Elib release containing them is installed. Keep en_us.json in your own mod. Set your minimum Elib dependency to a release containing any central translations your mod relies on.
Registration enables the shared language preference; it does not generate translations. A newly registered mod with only an English file will display English until translations are supplied.
For each registered namespace, Elib:
- Loads your mod's
en_us.jsonas the fallback. - For a non-English selection, looks for the selected locale in Elib's central translation directory.
- If no central file exists for that locale, looks for the locale in your mod's own
assets/<namespace>/langdirectory. - Uses English for keys missing from the selected translation.
When a central file exists, it is the selected locale's source; Elib does not also merge your mod's file for that locale. Keys absent from both the selected translation and English retain Minecraft's normal translation lookup behavior.
The picker currently supports these 20 locales. Adding a translation file alone does not add a new locale to the picker.
| Language | Locale |
|---|---|
| English | en_us |
| Spanish | es_es |
| French | fr_fr |
| German | de_de |
| Chinese, Simplified | zh_cn |
| Chinese, Traditional | zh_tw |
| Japanese | ja_jp |
| Portuguese, Brazil | pt_br |
| Russian | ru_ru |
| Korean | ko_kr |
| Italian | it_it |
| Dutch | nl_nl |
| Polish | pl_pl |
| Turkish | tr_tr |
| Swedish | sv_se |
| Finnish | fi_fi |
| Arabic | ar_sa |
| Hindi | hi_in |
| Indonesian | id_id |
| Ukrainian | uk_ua |
Elib refreshes its language overlay when the player changes its language setting and when Minecraft reloads its language. Call ElibLanguage.refresh() on the client thread if your own code needs to reapply the current preference. Use Component.translatable(...) rather than caching already translated strings.
For API details, see ElibLanguage Javadoc.