Introduction
It was always a problem to get the localized name of an item(afaik), so Language Utils came out to solve this issue. This API only provides names for vanilla strings.
In the following updates, I also add the support for entities, enchantments, and enchantment levels.
The major version is for Spigot/Bukkit 1.12. If you are using Spigot/Bukkit 1.7.10, 1.8.9, 1.9.4, 1.10.x, or 1.11.x, use this, this, this, this, or this instead.
Update: You can use the latest 1.7.10 version of this API on Cauldron/KCauldron servers now. You can download the latest 1.7.10 version here. Again, the API only supports vanilla items/entities(Though it will return the material name if the item is not vanilla).
Status:
Resources
- Github(Licensed under MIT):
- https://github.com/MascusJeoraly/LanguageUtils
- Example Plugin:
- https://github.com/MascusJeoraly/LangUtilsExample
- Maven Repo(I don't have a server):
- https://raw.github.com/MascusJeoraly/LanguageUtils/mvn-repo/
- Latest build: https://drone.io/github.com/MeowInnovation/LanguageUtils/files
Installation
If you are a server owner, just drop the plugin into your plugins/ folder. This plugin itself does not have any functions and it may take 100-250 ms to load all the language files. If you want to customize the language entries, please read the README.txt inside plugins/LangUtils/lang/.
If you are a developer, add the API to your build path. Additionally, if you are using Gradle or Maven:
Gradle: add the following to your build.gradle
repositories {
maven {
url 'https://raw.github.com/MascusJeoraly/LanguageUtils/mvn-repo/'
}
}
dependencies {
compile group: 'com.meowj', name: 'LangUtils', version: '1.9' // Please check the latest version
}
Maven: add the following to your pom.xml
<repositories>
<repository>
<id>lang-utils-repo</id>
<url>https://raw.github.com/MascusJeoraly/LanguageUtils/mvn-repo/</url>
</repository>
</repository>
<dependencies>
<dependency>
<groupId>com.meowj</groupId>
<artifactId>LangUtils</artifactId>
<!--Please check the latest version -->
<version>1.9</version>
</dependency>
</dependencies>
Usage
Items
1. Get the display name of an item(including customized name):
LanguageHelper.getItemDisplayName(itemStack, locale);
LanguageHelper.getItemDisplayName(itemStack, player);For example, if you want to get the English name of an item:
LanguageHelper.getItemDisplayName(itemStack, "en_us");2. Get the localized name of an item:
LanguageHelper.getItemName(itemStack, locale);
LanguageHelper.getItemName(itemStack, player);3. Get the unlocalized name of an item
LanguageHelper.getItemUnlocalizedName(itemStack);Entities
1. Get the unlocalized name of an entity
LanguageHelper.getEntityUnlocalizedName(entity);
LanguageHelper.getEntityUnlocalizedName(entityType);2. Get the localized name of an entity
LanguageHelper.getEntityName(entity, locale);
LanguageHelper.getEntityName(entity, player);
LanguageHelper.getEntityName(entityType, locale);
LanguageHelper.getEntityName(entityType, player);3. Get the display name of an entity(including customized name)
LanguageHelper.getEntityDisplayName(entity, locale);
LanguageHelper.getEntityDisplayName(entity, player);Ofc, if you only want the English name of an entity, you can just use
entity.getName();Enchantments
1. Get the unlocalized name of an enchantment
LanguageHelper.getEnchantmentUnlocalizedName(enchantment);2. Get the name of an enchantment
LanguageHelper.getEnchantmentName(enchantment, player);
LanguageHelper.getEnchantmentName(enchantment, locale);3. Get the full name of an enchantment(including its level)
LanguageHelper.getEnchantmentDisplayName(enchantment, level, player);
LanguageHelper.getEnchantmentDisplayName(enchantment, level, locale);
LanguageHelper.getEnchantmentDisplayName(entry, level, player);
LanguageHelper.getEnchantmentDisplayName(entry, level, locale);where entry is Map.Entry<Enchantment, Integer>.
Enchantment levels
1. Get the unlocalized name of an enchantment level
LanguageHelper.getEnchantmentLevelUnlocalizedName(level);2. Get the name of an enchantment level
LanguageHelper.getEnchantmentLevelName(level, player);
LanguageHelper.getEnchantmentLevelName(level, locale);Misc
1. Translate an unlocalized name
LanguageHelper.translateToLocal(unlocalizedName, locale);2. Get the language a player is using
LocaleHelper.getPlayerLanguage(player); 3. Add/Replace a language entry
LanguageRegistry.INSTANCE.registerEntry(lang, unlocalizedName, localizedName);
You can see this demo plugin for more details.
Build
This API uses Gradle to manage the source code. If you want to build the project your self, simply run
gradle build
or
gradlew build
if you don't have Gradle installed.
Configuration
# When a name in the language requested does not exist, the name will be retrieved in this language. The default fall back language is English.
FallbackLanguage=en_us
# If you want to enable the loading of a language, add it to the following list
LoadLanguage= [en_us, zh_cn, zh_tw]
# Or
LoadLanguage:
- en_us
- zh_cn
- zh_tw
# If you want to load all the languages, add "all" to the list:
LoadLanguage:
- all
Known Issues
- Currently I'm using HashMap and Enum to organize languages(& items). And it may take 50-1000 μs to retrieve one item name.(may be longer) If you have more efficient ways to load or to lookup names, please let me know.
- Support for items in mods(seems unneccessary in 1.8 and 1.9)
Similar projects
Plugin →Let Me Despawn
Improves performance by tweaking mob despawn rules. Say bye to pesky unintentional persistent mobs.
26.2MSueta
JourneyMap
Real-time map used for mapping in-game or your browser as you explore.
14.7MSueta
Emotecraft
Create your own emotes in Minecraft.
7.9MSueta
Simple Tpa
A simple tpa plugin which sends requests
5.4MSueta
Common Network
Forge and Fabric Unified Networking Solution
4.7MSueta
Set Home
A lightweight plugin for players to set their homes.
3.8MSueta