Skip to content

Internationalization (i18n)

Usage

Supported since 1.12.0+

  1. Add the @EruptI18n annotation to mark all strings in the class as translatable:
java
@EruptI18n
@Erupt(name = "i18n.title")
public class EruptTest {

    @EruptField(
            views = @View(title = "i18n.name"),
            edit = @Edit(title = "i18n.name")
    )
    private String name;
    
}
  1. Create an i18n directory under resources, then create a CSV file with any name inside it, e.g.: resources/i18n/demo.csv

  2. Define the CSV header. The first column must be "key", and the remaining columns are locale codes:

key,zh-CN,zh-TW,en-US,fr-FR,ja-JP,ko-KR,ru-RU,es-ES
i18n.name,姓名,姓名,Name,Le nom,名前です,이름,им,Los nombres
  1. Translation is complete — switch the language on the frontend to see the effect.

  2. Calling the translation API manually from the backend:

java
import xyz.erupt.core.i18n.I18nTranslate;

public void translate() {
    // Static call; the return value is the translated text based on the frontend user's locale selection
    String txt = I18nTranslate.$translate("erupt.exec_success");
}

Database Comment Multi-Language Translation

Database comments will be translated according to the default locale configured in erupt.default-locales.

Supported since 1.12.23+

Supported Locale Codes

LanguageSupported SinceLocale Code
Simplified Chinese1.12.0+zh-CN
Traditional Chinese1.12.0+zh-TW
English1.12.0+en-US
French1.12.0+fr-FR
Japanese1.12.0+ja-JP
Korean1.12.0+ko-KR
Russian1.12.0+ru-RU
Spanish1.12.0+es-ES
German1.12.0+de-DE
Portuguese1.12.0+pt-PT
Indonesian1.12.0+id-ID
Arabic1.12.0+ar-SA

Contributors

The avatar of contributor named as YuePeng YuePeng

Changelog

Released under the Apache-2.0 License.