Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/ultikits/ultikits-i18n

UltiTools-i18n allows developers to easily manage and use multilingual translations. By defining translation files, developers can quickly implement internationalization features.
https://github.com/ultikits/ultikits-i18n

bukkit bukkit-library i18n i18n-bukkit i18n-mc i18n-spigot spigot spigot-dev spigot-library

Last synced: about 1 month ago
JSON representation

UltiTools-i18n allows developers to easily manage and use multilingual translations. By defining translation files, developers can quickly implement internationalization features.

Awesome Lists containing this project

README

        

# UltiTools-i18n

## Introduction

UltiTools-i18n allows developers to easily manage and use multilingual translations. By defining translation files and using annotations, developers can quickly implement internationalization features.

## Installation

### Maven

Add the following dependency to your `pom.xml`:

```xml

com.ultikits.lib
ultikits-i18n
0.0.3

```

### Gradle

Add the following dependency to your `build.gradle`:

``` gradle
implementation 'com.ultikits.lib:ultikits-i18n:0.0.3'
```

## Quick Start

### Create I18nManager Implementation Class (Optional)

You can create a class that extends `I18nManager` and implements its abstract methods.

`JsonI18nManager` is included and will be used by default and as an example.

``` java
package com.ultikits.lib;

public class MyI18nManger extends I18nManager {

@Override
public String getTranslation(String langCode, String key) {
...
}
}
```

### Define Translation Files

To use `JsonI18nManager`, you must create your translation files in the `resources/lang` folder. For example, `en_US.json`:

``` json
{
"hello": "Hello",
"goodbye": "Goodbye"
}
```

### Retrieve Translations

Use the `i18n` method to get translations:

``` java
public class MyCommandExecuter implements CommandExecutor, I18n {

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (sender instanceof Player) {
Player player = (Player) sender;
// Send the player who executes this command an internationalized message based on their locale
i18n(player, "hello");
} else {
// Send the sender who executes this command an internationalized message based on the default locale
sender.sendMessage(i18n("hello"))
}
return false;
}
}
```

## More Details

### Custom Language Folder

You can specify a custom default locale or language folder for `JsonI18nManager`. Keep in mind that every time you get an instance with a different language folder from the last time, a new instance will be created. It is not recommended to use a different language folder for each class.

``` java
public class myClass implements I18n {
// other code in this class...

@Override
public I18nManager getI18nManager() {
// return JsonI18nManager.getInstance("zh_CN");
return JsonI18nManager.getInstance("zh_CN", "/path/to/lang");
}
}
```

### Retrieve Translations for Specific Language

``` java
String translatedMessage = myI18nClass.i18n("en_US", "hello");
```

## License

This project is licensed under the MIT License. See the LICENSE file for details.