ItemsLangAPI
This API will help you to translate almost every game object (items, enchantments, effects, ... see below) to any language you like.
This API is made mainly for plugin developers. If you are a server administrator (and not a developer), you should download this API only if it is required as a dependency (or a soft-dependency) by another plugin installed on your server.
Use cases
- You want to send player a message with an item name depending on their language;
- You want to show player a GUI with language-based namings (e.g., items translated to their own language);
- You want to get the vanilla name of an item (enchantment, etc.) knowing only an item id (with Bukkit API it is impossible to get a vanilla name of an item)
- You want to use localized item/enchantments/etc names anywhere else.
Features (Methods)
- translate - Translating a java object (ItemStack, Enchantment, Biome, ect., see full list at categories);
- translateExact - Translating an exact defined namespaced key (e.g., "item.minecraft.diamond", Lang.FR_FR will return "Diamant");
- translateAnything - Translating anything without knowing a namespace (e.g., "fox", Lang.ES_ES will return Zorro);
- TODO: Custom language files (can be added by user);
- TODO: Add more categories.
Categories
There are 8 categories of objects you can use now:
- ItemStack (returns an item name);
- Material (same as ItemStack);
- PotionEffectType (returns a potion effect name);
- EntityType (returns an entity name - Arrow, Zombie, Player);
- Biome (returns a biome name);
- Villager.Profession (returns a villager profession);
- Enchantment (returns an enchantment name);
- Statistic (returns a player-server statistic name).
Unsupported categories
Since we try to provide the ability to work on rather old game versions (1.8+), it is not possible to add some categories to the API. However, you can add them yourself by changing this API for your specific version.
- Villager.Type (added in MC 1.14)
- TropicalFish.Pattern (added in MC 1.13)
How to compile
Maven:
Please use the latest release version instead of 1.0.2 found
here
Code (Text):
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.github.Rubix327</groupId>
<artifactId>ItemsLangAPI</artifactId>
<version>1.0.2</version>
</dependency>
</dependencies>
Gradle:
Please use the latest release version instead of 1.0.2 found
here
Code (Text):
repositories {
maven { url 'https://jitpack.io' }
}
dependencies {
compileOnly "com.github.Rubix327:ItemsLangAPI:1.0.2"
}
Implementing & How To Use
Firstly, get the API and load your preferred languages.
Code (Java):
ItemsLangAPI api
= ItemsLangAPI.
getApi
(
)
;
@Override
public
void onEnable
(
)
{
api.
load
(Lang.
EN_US, Lang.
RU_RU, Lang.
CA_ES
)
;
}
You can also load all languages at once. But if you don't need them all, I'd recommend sticking with the method above for the sake of not littering your memory with the useless data.
Code (Java):
ItemsLangAPI.
getApi
(
).
loadAll
(
)
;
If you don't load a language and then try to use it, you will get null.
Using translate method
Specify the object you want to be translated and then the required language (Lang).
Code (Java):
ItemsLangAPI.
getApi
(
).
translate
(
new ItemStack
(Material.
BIRCH_LOG
), Lang.
CA_ES
)
;
You can also use
Player.getLocale() starting from MC version 1.12.
Code (Java):
ItemsLangAPI.
getApi
(
).
translate
(Material.
DIAMOND_BLOCK, event.
getPlayer
(
).
getLocale
(
)
)
;
You can use String as a language parameter. The API will try to automatically convert it to a Lang, but if this Lang does not exist, default will be used.
Code (Java):
ItemsLangAPI.
getApi
(
).
translate
(Enchantment.
ARROW_FIRE,
"fr_fr"
)
;
Additional features
You can disable the warning notification (it is displayed when something is trying to translate an object to a non-existent language) using the following:
Code (Java):
ItemsLangAPI.
getApi
(
).
hideWarnings
(
)
;
You can set the default language using the following:
Code (Java):
ItemsLangAPI.
getApi
(
).
setDefault
(Lang.
RU_RU
)
;
The default language is loaded regardless of using
api.load(). By default, it is
EN_US.
Using on legacy versions (below 1.13)
ItemsLangAPI will automatically try to convert your item's numerical id to the modern one. But if you still need to get the modern name from the item running your server on a legacy version, you can use:
Code (Java):
Comp.
getModernId
(ItemStack item
)
If your server version is 1.13+, this method will always return null because it is not intended to work on the modern versions. If you want to get a modern name from the legacy id, use:
Code (Java):
ItemsLangAPI.
getApi
(
).
getLegacyToModern
(
).
get
(
"35-1"
)
;
// -> orange_wool