HomeJavaModsLangUtils
LangUtils
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:
  1. Create your configurable message as json
  2. Register the file in LangUtils onEnable, or some other location beforehand
  3. Get the message and send it to your desired targets with optional variable replacements
Create your configurable message as json
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"
          }
        ]
      }
    }
  ]
}
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:
Code (Text):
{
  "en_us": [
    {
      "text": "english text",
      "color": "blue"
    }
  ],
  "de_de": [
    {
      "text": "german text",
      "color": "white",
      "bold": true
    }
  ]
}
Register the file in LangUtils onEnable, or some other location beforehand
Registering is as easy as
Code (Java):
LangUtils. registerLanguageFile ( this , file ) ;
And that's it! However, I've included a few other options for ease of use.

Code (Java):
LangUtils. registerLanguageFile ( this ) ;
This will go through and register all language files in your dataFolder/lang directory.
Additionally, you can even write a default with this method:
Code (Java):
LangUtils. writeDefault ( this , file, localeMessage ) ;
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
Code (Java):
NamespacedKey namespacedKey = new NamespacedKey ( plugin, "file name without extension or path" ) ;
LangUtils. getMessage ( namespacedKey ) ;
From there, use one of LocalMessage's various "send" methods. Here's an example with a common variable replacement:
Code (Java):
LangUtils. getMessage ( new NamespacedKey ( this , "test" ) ) . sendTo ( LocaleMessage. createArgumentBuilder ( )
                        . put ( "%player%" , ( ( Player ) sender ) . getDisplayName ( ) ) . asMap ( ) , ( Player ) sender ) ;
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!

Plugin details

Read from the plugin's own plugin.yml.

Quick facts

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.

Explore more