Skip to content

Commit

Permalink
docs: add javadoc for i18n
Browse files Browse the repository at this point in the history
  • Loading branch information
smartcmd committed Sep 22, 2024
1 parent 39dfa20 commit 276422e
Show file tree
Hide file tree
Showing 15 changed files with 55 additions and 13 deletions.
3 changes: 3 additions & 0 deletions api/src/main/java/org/allaymc/api/i18n/LangCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import lombok.AllArgsConstructor;

/**
* @author daoge_cmd
*/
@AllArgsConstructor
public enum LangCode {
en_US("English (United States)"),
Expand Down
2 changes: 2 additions & 0 deletions api/src/main/java/org/allaymc/api/i18n/MayContainTrKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import java.lang.annotation.Target;

/**
* This annotation is used to mark the text which may contains translation key.
*
* @author daoge_cmd
*/
@Retention(RetentionPolicy.RUNTIME)
Expand Down
38 changes: 38 additions & 0 deletions api/src/main/java/org/allaymc/api/i18n/TextReceiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,62 @@
import org.allaymc.api.utils.Utils;

/**
* Represents a text receiver.
*
* @author daoge_cmd
*/
public interface TextReceiver {
/**
* Send a text to the receiver.
*
* @param text the text.
*/
void sendText(String text);

/**
* Send a text which may contains translation key to the receiver.
*
* @param key the text which may contains translation key.
* @param forceTranslatedByClient whether the text should be translated by the client.
* @param args the arguments used in the translation.
*/
void sendTr(@MayContainTrKey String key, boolean forceTranslatedByClient, String... args);

/**
* Send a text which may contains translation key to the receiver.
*
* @param key the text which may contains translation key.
* @param args the arguments used in the translation.
*/
default void sendTr(@MayContainTrKey String key, String... args) {
sendTr(key, false, args);
}

/**
* Send a text which may contains translation key to the receiver.
*
* @param key the text which may contains translation key.
* @param args the arguments used in the translation.
*/
default void sendTr(@MayContainTrKey String key, Object... args) {
sendTr(key, Utils.objectArrayToStringArray(args));
}

/**
* Send a text which may contains translation key to the receiver.
*
* @param key the text which may contains translation key.
*/
default void sendTr(@MayContainTrKey String key) {
sendTr(key, false, Utils.EMPTY_STRING_ARRAY);
}

/**
* Send the command outputs to the receiver.
*
* @param sender the sender of the command.
* @param status the status of the command.
* @param outputs the command outputs.
*/
void sendCommandOutputs(CommandSender sender, int status, TrContainer... outputs);
}
2 changes: 2 additions & 0 deletions api/src/main/java/org/allaymc/api/i18n/TrContainer.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.allaymc.api.i18n;

/**
* TrContainer is used to store the translation key and the arguments used in the translation.
*
* @author daoge_cmd
*/
public record TrContainer(String str, Object... args) {
Expand Down
2 changes: 1 addition & 1 deletion api/src/main/java/org/allaymc/api/i18n/TrKeys.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.allaymc.api.i18n;

/**
* @author daoge_cmd
* Automatically generated by {@code org.allaymc.codegen.TrKeysGen}
*/
public interface TrKeys {
String A_ALLAY_STARTING = "allay:allay.starting";
Expand Down
3 changes: 2 additions & 1 deletion codegen/src/main/java/org/allaymc/codegen/TrKeysGen.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ public static void main(String[] args) {
.getAsJsonObject()
.keySet();
var codeBuilder = TypeSpec.interfaceBuilder(ClassNames.TR_KEYS)
.addModifiers(Modifier.PUBLIC);
.addModifiers(Modifier.PUBLIC)
.addJavadoc("Automatically generated by {@code org.allaymc.codegen.TrKeysGen}");
for (var key : keys) {
var identifier = new Identifier(key);
var namespace = handleNamespace(identifier.namespace());
Expand Down
3 changes: 1 addition & 2 deletions data/resources/lang/en_US.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"allay:allay.starting": "Starting up allay...",
"allay:api.implemented": "This server is running §b%1§r (§a%2§r), implement §ballay-api§r version §a%3",
"allay:blockentitytype.loaded": "Loaded %1 block entity types",
"allay:blockentitytype.loading": "Loading block entity types...",
Expand Down Expand Up @@ -86,7 +85,7 @@
"allay:plugin.loading": "Loading plugin %1",
"allay:recipe.loaded": "Loaded %1 recipes",
"allay:recipe.loading": "Loading recipes...",
"allay:server.starting": "Starting allay...",
"allay:server.starting": "Starting up allay...",
"allay:server.stopped": "Server stopped",
"allay:world.loaded": "World %1 is loaded",
"allay:world.loading": "Loading world %1",
Expand Down
1 change: 0 additions & 1 deletion data/resources/lang/zh_CN.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"allay:allay.starting": "正在启动allay...",
"allay:api.implemented": "此服务器正在运行 §b%1§r (§a%2§r), 实现§ballay-api§r版本 §a%3",
"allay:blockentitytype.loaded": "加载完成 %1 个方块实体类型",
"allay:blockentitytype.loading": "正在加载方块实体类型...",
Expand Down
3 changes: 1 addition & 2 deletions data/resources/unpacked/lang_raw/allay/en_US.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
{
"server.starting": "Starting allay...",
"server.starting": "Starting up allay...",
"server.stopped": "Server stopped",
"lang.set": "Server language was set to %1",
"api.implemented": "This server is running §b%1§r (§a%2§r), implement §ballay-api§r version §a%3",
"network.server.starting": "Starting up network server...",
"network.server.started": "Network server started at %1:%2 (%3 ms)",
"network.client.connected": "Client connected, IP: %1",
"network.client.disconnected": "Client disconnected, IP: %1",
"allay.starting": "Starting up allay...",
"blocktype.loading": "Loading block types...",
"blocktype.loaded": "Loaded %1 block types",
"blockentitytype.loading": "Loading block entity types...",
Expand Down
1 change: 0 additions & 1 deletion data/resources/unpacked/lang_raw/allay/zh_CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"network.server.started": "网络服务器已在 %1:%2 启动 (%3 毫秒)",
"network.client.connected": "客户端已连接, 地址: %1",
"network.client.disconnected": "客户端断开连接, 地址: %1",
"allay.starting": "正在启动allay...",
"blocktype.loading": "正在加载方块类型...",
"blocktype.loaded": "加载完成 %1 个方块类型",
"blockentitytype.loading": "正在加载方块实体类型...",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.allaymc.api.i18n.I18n;
import org.allaymc.api.i18n.I18nLoader;
import org.allaymc.api.i18n.LangCode;

import java.util.EnumMap;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.allaymc.server.i18n;

import com.google.gson.reflect.TypeToken;
import org.allaymc.api.i18n.I18nLoader;
import org.allaymc.api.i18n.LangCode;
import org.allaymc.api.utils.JSONUtils;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
package org.allaymc.api.i18n;
package org.allaymc.server.i18n;

import org.allaymc.api.i18n.LangCode;

import java.util.Map;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.allaymc.api.i18n.I18n;
import org.allaymc.api.i18n.I18nLoader;
import org.allaymc.server.i18n.I18nLoader;
import org.allaymc.api.i18n.LangCode;
import org.allaymc.api.i18n.TrKeys;
import org.allaymc.api.plugin.*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import lombok.Getter;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.allaymc.api.i18n.I18nLoader;
import org.allaymc.server.i18n.I18nLoader;
import org.allaymc.api.i18n.LangCode;
import org.allaymc.api.plugin.PluginContainer;
import org.allaymc.api.plugin.PluginDescriptor;
Expand Down

0 comments on commit 276422e

Please sign in to comment.