Output Code
The translations class generator will output code as follows:
- A base
objectwith your configuredclassName, or namedTranslationsby default.- A
bundleproperty containing theBundleobject representing your translation bundle. - If you have any top-level translation keys, a set of
Keyproperties representing those keys, pre-populated with theBundleobject. - If you have any nested translation keys, a set of
objects named after the key's prefixes, containingKeyproperties and other nestedobjects.
- A
All Key objects also include a KDoc comment containing the default translation for the corresponding key.
See below for a specific example.
Bundle Definition
For example, src/main/resources/translations/template/strings.yml:
commands:
button:
action: 'You pushed the button!'
description: 'A simple example command sending a button'
label: 'Button!'
name: 'button'
slap:
action: 'slaps {0} with their {1}'
description: 'Ask the bot to slap another user'
name: 'slap'
args:
target:
description: 'Person you want to slap'
name: 'target'
weapon:
description: 'What you want to slap with'
name: 'weapon'
Gradle Configuration
This is the corresponding Gradle plugin configuration for the output code below:
i18n {
bundle("template.strings", "template.i18n") {
className = "PublicTranslations"
}
}
Output Code
bundle = "template.strings"className = "PublicTranslations"classPackage = "template.i18n"
package template.i18n
import dev.kordex.i18n.Bundle
import dev.kordex.i18n.Key
public object PublicTranslations {
public val bundle: Bundle =
Bundle(
name = "template.strings",
fileFormat = "yaml",
messageFormat = "icu-v1",
)
public object Commands {
public object Button {
/**
* You pushed the button!
*/
public val action: Key =
Key("commands.button.action")
.withBundle(PublicTranslations.bundle)
/**
* A simple example command sending a button
*/
public val description: Key =
Key("commands.button.description")
.withBundle(PublicTranslations.bundle)
/**
* Button!
*/
public val label: Key =
Key("commands.button.label")
.withBundle(PublicTranslations.bundle)
/**
* button
*/
public val name: Key =
Key("commands.button.name")
.withBundle(PublicTranslations.bundle)
}
public object Slap {
/**
* slaps {0} with their {1}
*/
public val action: Key =
Key("commands.slap.action")
.withBundle(PublicTranslations.bundle)
/**
* Ask the bot to slap another user
*/
public val description: Key =
Key("commands.slap.description")
.withBundle(PublicTranslations.bundle)
/**
* slap
*/
public val name: Key =
Key("commands.slap.name")
.withBundle(PublicTranslations.bundle)
public object Args {
public object Target {
/**
* Person you want to slap
*/
public val description: Key =
Key("commands.slap.args.target.description")
.withBundle(PublicTranslations.bundle)
/**
* target
*/
public val name: Key =
Key("commands.slap.args.target.name")
.withBundle(PublicTranslations.bundle)
}
public object Weapon {
/**
* What you want to slap with
*/
public val description: Key =
Key("commands.slap.args.weapon.description")
.withBundle(PublicTranslations.bundle)
/**
* weapon
*/
public val name: Key =
Key("commands.slap.args.weapon.name")
.withBundle(PublicTranslations.bundle)
}
}
}
}
}