What does this library ?
This library allow you to externalize all of your messages without annoying code to link them to the code. The goal is to avoid repetitive codes. The link is transparent, nice to use, almost no repetitive-code, and logged if translations are missing.
What does NOT this library :
This library will not translate alone your plugin. You must provide your translations or let your users to translate it.
This library allow you to localize your plugin to any language by setting the config value of your config.yml, under reserve of the corresponding YAML file exists. You can also don't translate your plugin, but this library would allow your users to translate it and/or provide their own custom messages, and externalize your messages, not re-invent the wheel and keep your code clean. So only good.
Because an example is worth a thousand words, an example plugin is available here .
Features
- Positional arguments with syntax ${1} , ${2} , etc.
- Named arguments with syntax ${pluginName} , etc
- Compile-time invalid arguments detection
- Translate automatically Players to their username.
Notes
- It's not a plugin but a standalone library, so no need to add it to the plugin folder.
Step-by-step
For any precision, refer to the example plugin.
- Add a new entry to your config.yml as lang: en .
- Create the resource file lang/en.yml you fill with
welcome : Hello, message from the plugin $ { 1 } - Add this class to your plugin.
package org.author.mypluginname public interface Example { String welcome ( String pluginName ) ; } - Instanciate your messaging system with
Example i18n = PluginLocalization. create ( this , Example . class ) ; getLogger ( ) . info ( i18n. welcome ( "MySuperPlugin" ) ) ; - Already done. When calling any of the method of the interface, the corresponding message will be translated.
To change the language without changing any code, you can do the following
# config/lang_zh.yml
welcome : 您好,来自$ { 1 } 插件的消息
# config.yml
# It's the config file of your plugin.
# It won't have to be empty,
# but you just need to add this entry,
# defaulted to "en" if it does not exists.
lang : zh
Done!
Bonus
Define named arguments:
package org.author.mypluginname ;
import fr.rafoudiablol.internationalization.core.Arg ;
public interface Example {
String welcome ( @Arg ( "pluginName" ) String pluginName ) ;
}
Add this annotation to each of your arguments you want to name. It's probably a good idea to give the same name as the code argument.
Why need to do this? Because java can't get arguments named, they are hidden once compiled.
Similar projects
Plugin →Let Me Despawn
Improves performance by tweaking mob despawn rules. Say bye to pesky unintentional persistent mobs.
25MSueta
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.5MSueta
Simple Tpa
A simple tpa plugin which sends requests
5.4MSueta
Common Network
Forge and Fabric Unified Networking Solution
3.9MSueta
Set Home
A lightweight plugin for players to set their homes.
3.8MSueta