This plugin is dependent on ProtocolLib
Having seen and worked with the various plugins available on the spigot platform, I've been dissatisfied with the support for custom messages, message variables, and most importantly seamless multi-language support.
So with a bit of research and elbow grease, I made this plugin.
Most plugins use yaml for their message configurations, but the system I designed with json out of personal preference and relative ease to parse.
But the design doesn't matter, as long as it's easy to understand.
LangUtils has three easily identifiable steps:
The json structure for the message is:
where "language_locale" is a combination of two strings, normally in two characters long. For example, the language setting in-game "English (US)" is represented as "en_us," so the language of English and the locale of the united states. However, you do not need a new entry for every single locale of each language. If you have one English entry, it will apply it to all English locales, unless specifically overridden. Here's an example of a functional configurable message:
Register the file in LangUtils onEnable, or some other location beforehand
Registering is as easy as
And that's it! However, I've included a few other options for ease of use.
This will go through and register all language files in your dataFolder/lang directory.
Additionally, you can even write a default with this method:
which also registers the localeMessage, so no need to call the register method afterward!
Get the message and send it to your desired targets with optional variable replacements
To send a message, its as easy as getting the LocaleMessage object with
From there, use one of LocalMessage's various "send" methods. Here's an example with a common variable replacement:
Using the LocaleMessage send methods is ideal when possible, as it will send the message to each player in their native language like magic!
Thanks for giving this a try!
Having seen and worked with the various plugins available on the spigot platform, I've been dissatisfied with the support for custom messages, message variables, and most importantly seamless multi-language support.
So with a bit of research and elbow grease, I made this plugin.
Most plugins use yaml for their message configurations, but the system I designed with json out of personal preference and relative ease to parse.
But the design doesn't matter, as long as it's easy to understand.
LangUtils has three easily identifiable steps:
- Create your configurable message as json
- Register the file in LangUtils onEnable, or some other location beforehand
- Get the message and send it to your desired targets with optional variable replacements
The json structure for the message is:
Code (Text):
{
"language_locale": [
"An array full of text ",
"which are concatenated before ",
"being sent to the player. "
{
"text": "It can also be expressed as an object ",
"color": "red"
},
{
"text": "with even more options.",
"color": "yellow",
"bold": true,
"hover event": {
"action": "SHOW_TEXT",
"value": [
"Such as ",
{
"text": "hover events",
"color": "blue"
}
]
}
}
]
}
"language_locale": [
"An array full of text ",
"which are concatenated before ",
"being sent to the player. "
{
"text": "It can also be expressed as an object ",
"color": "red"
},
{
"text": "with even more options.",
"color": "yellow",
"bold": true,
"hover event": {
"action": "SHOW_TEXT",
"value": [
"Such as ",
{
"text": "hover events",
"color": "blue"
}
]
}
}
]
}
Code (Text):
{
"en_us": [
{
"text": "english text",
"color": "blue"
}
],
"de_de": [
{
"text": "german text",
"color": "white",
"bold": true
}
]
}
"en_us": [
{
"text": "english text",
"color": "blue"
}
],
"de_de": [
{
"text": "german text",
"color": "white",
"bold": true
}
]
}
Registering is as easy as
Code (Java):
LangUtils.
registerLanguageFile
(
this , file
)
;
Code (Java):
LangUtils.
registerLanguageFile
(
this
)
;
Additionally, you can even write a default with this method:
Code (Java):
LangUtils.
writeDefault
(
this , file, localeMessage
)
;
Get the message and send it to your desired targets with optional variable replacements
To send a message, its as easy as getting the LocaleMessage object with
Code (Java):
NamespacedKey namespacedKey
=
new NamespacedKey
( plugin,
"file name without extension or path"
)
;
LangUtils. getMessage ( namespacedKey ) ;
LangUtils. getMessage ( namespacedKey ) ;
Code (Java):
LangUtils.
getMessage
(
new NamespacedKey
(
this ,
"test"
)
) .
sendTo
( LocaleMessage.
createArgumentBuilder
(
)
. put ( "%player%" , ( ( Player ) sender ) . getDisplayName ( ) ) . asMap ( ) , ( Player ) sender ) ;
. put ( "%player%" , ( ( Player ) sender ) . getDisplayName ( ) ) . asMap ( ) , ( Player ) sender ) ;
Thanks for giving this a try!
Quick facts
- Edition: Minecraft Java
- File type: .jar
- Minecraft version listed: 1.13
- How to install: Install the matching mod loader (Forge, Fabric or NeoForge) for your Minecraft version. → Download the .jar. → Put it in the .minecraft/mods folder and launch that loader profile.
- Where to get it: Opens on Spigot — not every file is mirrored on our own servers.
Install steps are the general flow for this file type — How to install Minecraft Java mods & modpacks walks through it step by step.
LangUtils is a free Minecraft Java mod. Compatible with Minecraft 1.13. Downloaded 1,044 times (via Spigot). Download it and open it directly in the game.