Skip to content

Commit

Permalink
增加中文翻译
Browse files Browse the repository at this point in the history
  • Loading branch information
wling-art committed Jan 15, 2025
1 parent 230a881 commit 3cb700b
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 6 deletions.
24 changes: 23 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.example.calcStack</groupId>
<artifactId>CalcStack</artifactId>
<version>1.0</version>
<version>1.1</version>
<packaging>jar</packaging>

<name>CalcStack</name>
Expand Down Expand Up @@ -38,7 +38,19 @@
<goals>
<goal>shade</goal>
</goals>
<configuration>
<filters>
<filter>
<artifact>com.github.Rubix327:ItemsLangAPI</artifact>
<excludes>
<exclude>META-INF/MANIFEST.MF</exclude>
<exclude>plugin.yml</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>

</executions>
</plugin>
</plugins>
Expand All @@ -59,6 +71,10 @@
<id>sonatype</id>
<url>https://oss.sonatype.org/content/groups/public/</url>
</repository>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>

<dependencies>
Expand All @@ -68,5 +84,11 @@
<version>1.21-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.Rubix327</groupId>
<artifactId>ItemsLangAPI</artifactId>
<version>1.0.2</version>
</dependency>
</dependencies>

</project>
14 changes: 12 additions & 2 deletions src/main/java/com/example/calcStack/CalculateCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@
import org.bukkit.inventory.ShapedRecipe;
import org.bukkit.inventory.ShapelessRecipe;
import org.bukkit.Bukkit;
import me.rubix327.itemslangapi.ItemsLangAPI;
import me.rubix327.itemslangapi.Lang;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.*;
import java.util.stream.Collectors;


public class CalculateCommand implements TabExecutor {

private final CalcStackPlugin plugin;
Expand Down Expand Up @@ -79,7 +82,7 @@ public boolean onCommand(@Nullable CommandSender sender, @Nullable Command comma

Bukkit.getScheduler().runTask(plugin, () -> {
sender.sendMessage(getLangMessage("result.header"));
sender.sendMessage(getLangMessage("result.item").replace("{item}", material.name().toLowerCase()));
sender.sendMessage(getLangMessage("result.item").replace("{item}", material.name().toLowerCase()).replace("{translated_name}", getTranslatedItemName(material)));
sender.sendMessage(getLangMessage("result.quantity").replace("{quantity}", String.valueOf(quantity)));
sender.sendMessage(getLangMessage("result.stacks").replace("{stacks}", String.valueOf(totalStacks))
.replace("{stack_size}", String.valueOf(maxStackSize)));
Expand Down Expand Up @@ -131,7 +134,7 @@ private String formatMaterialDetail(Material material, int quantity, int maxStac
int chests = calculateChests(totalStacks, remainingItems, chestSize);

return getLangMessage("result.ingredients.item")
.replace("{ingredient}", material.name().toLowerCase())
.replace("{ingredient}", material.name().toLowerCase()).replace("{translated_name}", getTranslatedItemName(material))
.replace("{quantity}", String.valueOf(quantity))
+ "\n" + getLangMessage("result.ingredients.stacks")
.replace("{stacks}", String.valueOf(totalStacks))
Expand Down Expand Up @@ -178,4 +181,11 @@ private String getLangMessage(@Nonnull String path) {
String message = plugin.getLangConfig().getString(path);
return message != null ? message : "§c配置错误: 未找到语言文件内容 (" + path + ")!";
}

private String getTranslatedItemName(Material material) {
String translatedName = ItemsLangAPI.getApi().translate(material, Lang.ZH_CN);
return translatedName != null ? translatedName : material.name().toLowerCase();
}


}
4 changes: 2 additions & 2 deletions src/main/resources/lang.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ error:

result:
header: "§a===== 计算结果 ====="
item: "§b物品: {item}"
item: "§b物品: {item}({translated_name})"
quantity: "§b数量: {quantity}"
stacks: "§b堆叠: {stacks} 组 ({stack_size} 个/组)"
remaining: "§b剩余: {remaining} 个"
chests: "§b需要箱子: {chests} 个 (每个箱子 {chest_size} 格)"
footer: "§a===================="
ingredients:
header: "§a===== 原材料 ====="
item: "§b- {ingredient}: {quantity} 个"
item: "§b- {ingredient}({translated_name}): {quantity} 个"
stacks: " §7- {stacks} 组 ({stack_size} 个/组)"
remaining: " §7- 剩余 {remaining} 个"
chests: " §7- 需要箱子: {chests} 个 (每个箱子 {chest_size} 格)"
4 changes: 3 additions & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
name: CalcStack
version: '1.0'
version: ${project.version}
main: com.example.calcStack.CalcStackPlugin
api-version: '1.13'
load: STARTUP
author: Mr.ling - wling
description: 计算物品堆叠和箱子数量

commands:
calculate:
Expand Down

0 comments on commit 3cb700b

Please sign in to comment.