|
1 | 1 | # Kotonoha (言の葉) |
2 | | - |
3 | | -A localization framework for projects using [Adventure](https://github.com/KyoriPowered/adventure). |
4 | | - |
5 | | -Kotonoha allows defining multilingual messages as methods in Java interfaces. |
6 | | - |
7 | | -## Modules |
8 | | - |
9 | | -| Module | Description | |
10 | | -|-------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------| |
11 | | -| **kotonoha-annotations** | Common annotations shared across modules. | |
12 | | -| **kotonoha-resourcebundle-generator-processor** | An annotation processor that generates `.properties` resource bundles from annotated interfaces and includes them in the resulting artifact. | |
13 | | -| **kotonoha-message** | Core module providing reflection-based proxies that create `TranslatableComponent` instances from interface method calls. | |
14 | | -| **kotonoha-message-extra-miniplaceholders** | Extension module providing [MiniPlaceholders](https://github.com/MiniPlaceholders) integration. | |
15 | | -| **kotonoha-translator** | A `Translator` module that registers translations from annotated methods. | |
16 | | - |
17 | | -### Quick Start (MessageFormat) |
18 | | - |
19 | | -Depends on `kotonoha-message` and `kotonoha-translator`. |
20 | | - |
21 | | -Define a message interface: |
22 | | - |
| 2 | + |
| 3 | +A localization framework for Java projects built on [Adventure](https://github.com/KyoriPowered/adventure). |
| 4 | +Define multilingual messages as methods on a plain Java interface. |
| 5 | + |
23 | 6 | ```java |
24 | 7 | public interface ExampleMessages { |
25 | | - |
26 | | - // {0} will be replaced by the value of the 'playerName' argument. |
27 | | - @Key("your_plugin.welcome.message") |
| 8 | + |
| 9 | + @Key("example.welcome") |
28 | 10 | @Message(locale = Locales.EN_US, content = "Welcome, {0}!") |
29 | 11 | @Message(locale = Locales.JA_JP, content = "ようこそ、{0}!") |
30 | 12 | Component welcomeMessage(Component playerName); |
31 | | - |
32 | | - /* |
33 | | - For MiniMessage: |
34 | | - <player_name> will be replaced by the value of the 'playerName' argument. |
35 | | - @Key("your_plugin.welcome.message") |
36 | | - @Message(locale = Locales.EN_US, content = "Welcome, <player_name>!") |
37 | | - @Message(locale = Locales.EN_US, content = "ようこそ、<player_name>!") |
38 | | - Component welcomeMessage(@Name("player_name") Component playerName); |
39 | | - */ |
40 | 13 | } |
41 | 14 | ``` |
42 | | - |
43 | | -Register the translator and create a proxy instance: |
44 | | - |
| 15 | + |
45 | 16 | ```java |
46 | | -// Register translations from the interface. |
47 | | -Key name = Key.key("your_plugin", "messages"); |
48 | | -KotonohaTranslationStore<MessageFormat> translator = KotonohaTranslationStore.messageFormat(name); |
49 | | -translator.registerInterface(ExampleMessages.class); |
50 | | - |
51 | | -// Add to global source. |
52 | | -GlobalTranslator.translator().addSource(translator); |
53 | | - |
54 | | -// Create proxy instance. |
| 17 | +KotonohaTranslationStore<MessageFormat> store = KotonohaTranslationStore.messageFormat(name); |
| 18 | +store.registerInterface(ExampleMessages.class); |
| 19 | +GlobalTranslator.translator().addSource(store); |
| 20 | + |
55 | 21 | ExampleMessages messages = KotonohaMessage.createProxy(ExampleMessages.class, FormatTypes.MESSAGE_FORMAT); |
56 | | - |
57 | | -// Get the message and send it. |
58 | | -Component result = messages.welcomeMessage(player.name()); |
59 | | -audience.sendMessage(result); // Welcome, Notch!! |
| 22 | +Componnent message = messages.welcomeMessage(player.displayName()); |
| 23 | +player.sendMessage(message); |
60 | 24 | ``` |
61 | | - |
62 | | -For more information on Adventure's localization: |
63 | | -https://docs.papermc.io/adventure/localization/ |
64 | | - |
| 25 | + |
| 26 | +## Modules |
| 27 | + |
| 28 | +| Module | Description | |
| 29 | +| --- | --- | |
| 30 | +| `kotonoha-annotations` | Common annotations (`@Key`, `@Message`, `@Name`, etc.) | |
| 31 | +| `kotonoha-message` | Proxy factory that builds `TranslatableComponent` from interface calls | |
| 32 | +| `kotonoha-translator` | Registers translations from annotated interfaces into Adventure's `TranslationStore` | |
| 33 | +| `kotonoha-resourcebundle-generator-processor` | Compile-time processor that generates `.properties` files from annotated interfaces | |
| 34 | +| `kotonoha-message-extra-miniplaceholders` | [MiniPlaceholders](https://github.com/MiniPlaceholders/MiniPlaceholders) integration | |
| 35 | + |
65 | 36 | ## Documentation |
66 | | - |
67 | | -Javadocs (Available soon) |
68 | | - |
69 | | -GitHub Wiki (Available soon) |
| 37 | + |
| 38 | +[GitHub Wiki](https://github.com/NamiUni/kotonoha/wiki) |
| 39 | + |
| 40 | +[Javadoc](https://javadoc.io/doc/io.github.namiuni) |
0 commit comments