Skip to content

I18n How to Use

Marcin Grzywacz edited this page May 27, 2022 · 2 revisions

Short description of API

The I18n API was designed to be pretty easy to use and this part of the framework is heavily developed and is heavily integrated with LCF you can use it practically everywhere you want to.
It supports:

  • Returning keys from any command.
  • Descriptions
  • Syntax

Initialization

First of all you need to initialize I18n you can do it by scanning normally using scanner that is scanning whole package Scanner.scan() by placing this code snippet in onEnable BEFORE initializing any of the commands
Use if you don't use scan

Scanner.initPluginI18n(plugin)

Basic file structure

Below you have an image representing on how you need to place your files in order for I18n to automatically load them
File names are important if you want for example Italian translation you just use proper code at the end for example: messages-ita.properties
You can have multiple translations of various languages in one plugin
By default I18n tries to read default english file if it encounters problems with finding key
image

Usage in basic command

import org.bukkit.entity.Player

class SomeCommand {
    fun run(player: Player): String {
        return "<run-message>"
    }
}

For given messages-{locale}.properties

run-message=Yay you ran command!

Will output to player the following: "Yay you ran command!"

Usage in other parts of the code

val messsageKeyPath = "something"
val valueMessage = "lol"

val tagResolverBuilder = TagResolver.builder()
// Resolve <something> to lol
tagResolverBuilder.resolver(PlaceHolder(messageKeyPath, valueMessage))

val message = I18nMessage(myPlugin, messageKeyPath, tagResolverBuilder.build())
message.send(playerISendTo)
// or if you want to get component
val componentMsg = message.getI18nResponse()
Clone this wiki locally