Skip to content

Commit aa15a53

Browse files
committed
translation
1 parent e60d8bf commit aa15a53

File tree

5 files changed

+129
-59
lines changed

5 files changed

+129
-59
lines changed

src/main/kotlin/net/gunivers/sniffer/debugcmd/AssertCommand.kt

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import com.mojang.logging.LogUtils
66
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback
77
import net.gunivers.sniffer.DatapackDebugger
88
import net.gunivers.sniffer.command.BreakPointCommand
9+
import net.gunivers.sniffer.util.Extension.appendLine
910
import net.minecraft.nbt.NbtByte
1011
import net.minecraft.nbt.NbtElement
1112
import net.minecraft.nbt.NbtHelper
@@ -32,36 +33,35 @@ object AssertCommand {
3233
val result = expr.get(it)
3334
//check result
3435
if(result !is NbtByte){
35-
val text = Text.literal("Assert failed. Result is not a byte: ").styled { style -> style.withColor(Colors.RED) }
36+
val text = Text.translatable("sniffer.commands.assert.failed.not_a_byte").styled { style -> style.withColor(Colors.RED) }
3637
when (result) {
3738
is NbtElement -> text.append(NbtHelper.toPrettyPrintedText(result))
3839
is Text -> text.append(result)
3940
else -> text.append(result.toString())
4041
}
41-
text.append("\n")
42-
text.append("Expression: " + expr.content + "\n")
43-
text.append("Stack trace: \n")
42+
text.appendLine()
43+
text.appendLine(Text.translatable("sniffer.commands.assert.failed.expression", expr.content))
44+
text.appendLine(Text.translatable("sniffer.commands.assert.failed.stack"))
4445
text.append(BreakPointCommand.getErrorStack(10))
4546
it.source.server.playerManager.broadcast(text, false)
4647
return@executes 0
4748
}
4849
if(result.value.toInt() == 0){
49-
val text = Text.literal("Assert failed: result is 0").styled { style -> style.withColor(Colors.RED) };
50-
text.append("\n")
51-
text.append("Expression: " + expr.content + "\n")
52-
text.append("Stack trace:").append("\n")
50+
val text = Text.translatable("sniffer.commands.assert.failed.result_is_zero").styled { style -> style.withColor(Colors.RED) };
51+
text.appendLine()
52+
text.appendLine(Text.translatable("sniffer.commands.assert.failed.expression", expr.content))
53+
text.appendLine(Text.translatable("sniffer.commands.assert.failed.stack"))
5354
text.append(BreakPointCommand.getErrorStack(10))
5455
it.source.server.playerManager.broadcast(text, false)
5556
return@executes 0
5657
}
57-
it.source.sendFeedback({ Text.literal("Assert passed") }, false)
58+
it.source.sendFeedback({ Text.translatable("sniffer.commands.assert.passed") }, false)
5859
return@executes 1
5960
}catch (ex: CommandSyntaxException){
6061
LOGGER.error("Exception while execution command:",ex)
61-
val text = Text.literal("Assert failed: ").styled { style -> style.withColor(Colors.RED) }
62-
text.append(ex.message ?: "Unknown error")
63-
text.append("\n")
64-
text.append("Stack trace:").append("\n")
62+
val text = Text.translatable("sniffer.commands.assert.failed").styled { style -> style.withColor(Colors.RED) }
63+
text.appendLine(ex.message?.let(Text::literal) ?: Text.translatable("sniffer.commands.assert.failed.unknown_error"))
64+
text.appendLine(Text.translatable("sniffer.commands.assert.failed.stack"))
6565
text.append(BreakPointCommand.getStack(10))
6666
it.source.server.playerManager.broadcast(text, false)
6767
return@executes 0

src/main/kotlin/net/gunivers/sniffer/debugcmd/JvmtimerCommand.kt

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ object JvmtimerCommand {
3232
.executes {
3333
val id = StringArgumentType.getString(it, "id")
3434
getTimer(id).start()
35-
it.source.sendFeedback({ Text.literal("Timer $id started") }, false)
35+
it.source.sendFeedback({ Text.translatable("sniffer.commands.jvmtimer.started", id) }, false)
3636
1
3737
}
3838
)
@@ -42,7 +42,7 @@ object JvmtimerCommand {
4242
.executes {
4343
val id = StringArgumentType.getString(it ,"id")
4444
getTimer(id).end()
45-
it.source.sendFeedback({ Text.literal("Timer $id ended") }, false)
45+
it.source.sendFeedback({ Text.translatable("sniffer.commands.jvmtimer.stopped", id) }, false)
4646
1
4747
}
4848
)
@@ -61,7 +61,7 @@ object JvmtimerCommand {
6161
.executes {
6262
val id = StringArgumentType.getString(it ,"id")
6363
getTimer(id).reset()
64-
it.source.sendFeedback({ Text.literal("Timer $id reset") }, false)
64+
it.source.sendFeedback({ Text.translatable("sniffer.commands.jvmtimer.reset", id) }, false)
6565
1
6666
}
6767
)
@@ -71,7 +71,7 @@ object JvmtimerCommand {
7171
.executes {
7272
val id = StringArgumentType.getString(it ,"id")
7373
getTimer(id).disable()
74-
it.source.sendFeedback({ Text.literal("Timer $id disabled") }, false)
74+
it.source.sendFeedback({ Text.translatable("sniffer.commands.jvmtimer.disable", id) }, false)
7575
1
7676
}
7777
)
@@ -125,19 +125,19 @@ object JvmtimerCommand {
125125

126126
fun get(ctx: CommandContext<ServerCommandSource>){
127127
if(count == 0){
128-
ctx.source.sendFeedback({ Text.literal("Timer $id is not started") }, false)
128+
ctx.source.sendFeedback({ Text.translatable("sniffer.commands.jvmtimer.not_started", id) }, false)
129129
return
130130
}
131131
if(!enabled){
132-
ctx.source.sendFeedback({ Text.literal("Timer $id is disabled") }, false)
132+
ctx.source.sendFeedback({ Text.translatable("sniffer.commands.jvmtimer.disable", id) }, false)
133133
return
134134
}
135135
val text = Text.empty()
136-
text.title("Timer $id: ")
137-
.desc("Total time: ").value("${totalTime / 1_000_000.0}ms")
138-
.desc("Count: ").value(count.toString())
139-
.desc("Average time: ").value("${totalTime / count / 1_000_000.0}ms")
140-
.desc("Max/Min time: ").value("${maxTime / 1_000.0}μs/${minTime / 1_000.0}μs")
136+
text.title("sniffer.commands.jvmtimer.info.id").value(id)
137+
.desc("sniffer.commands.jvmtimer.info.total").value("${totalTime / 1_000_000.0}ms")
138+
.desc("sniffer.commands.jvmtimer.info.count").value(count.toString())
139+
.desc("sniffer.commands.jvmtimer.info.average").value("${totalTime / count / 1_000_000.0}ms")
140+
.desc("sniffer.commands.jvmtimer.info.max_min").value("${maxTime / 1_000.0}μs/${minTime / 1_000.0}μs")
141141
ctx.source.sendFeedback({ text }, false)
142142
}
143143
fun reset(){
@@ -155,10 +155,10 @@ object JvmtimerCommand {
155155
}
156156

157157
private fun MutableText.title(str: String): MutableText =
158-
this.appendLine(Text.literal(str).styled { it.withColor(Colors.CYAN).withBold(true) })
158+
this.appendLine(Text.translatable(str).styled { it.withColor(Colors.CYAN).withBold(true) })
159159

160160
private fun MutableText.desc(str: String): MutableText =
161-
this.appendLine(Text.literal(str).styled { it.withColor(Colors.WHITE).withBold(false) })
161+
this.appendLine(Text.translatable(str).styled { it.withColor(Colors.WHITE).withBold(false) })
162162

163163
private fun MutableText.value(str: String): MutableText =
164164
this.appendLine(Text.literal(str).styled { it.withColor(Colors.CYAN).withBold(false) })

src/main/kotlin/net/gunivers/sniffer/debugcmd/WatchCommand.kt

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,21 @@ object WatchCommand {
8282
//set if watcher will auto reload function when changed
8383
val bool = BoolArgumentType.getBool(it, "bool")
8484
isAutoReload = bool
85+
if(isAutoReload){
86+
it.source.sendFeedback({ Text.translatable("sniffer.commands.watcher.auto.enable")}, false)
87+
}else{
88+
it.source.sendFeedback({ Text.translatable("sniffer.commands.watcher.auto.disable")}, false)
89+
}
8590
return@executes 1
8691
}
8792
).executes {
8893
//return if auto reload is enabled
89-
it.source.sendFeedback({ Text.literal("Auto reload: $isAutoReload") }, false)
94+
it.source.sendFeedback({ Text.translatable("sniffer.commands.watcher.auto", isAutoReload) }, false)
9095
return@executes 1
9196
}
9297
).then(literal<ServerCommandSource?>("reload")
9398
.executes {
99+
it.source.sendFeedback({Text.translatable("sniffer.commands.watcher.hot_reload")}, false)
94100
hotReload(it.source.server)
95101
return@executes 1
96102
}
@@ -105,7 +111,7 @@ object WatchCommand {
105111
val datapackPath = server.getSavePath(WorldSavePath.DATAPACKS)
106112
val packPath = datapackPath.resolve(id)
107113
if(Files.notExists(packPath)){
108-
src.sendError(Text.literal("Datapack $id not found"))
114+
src.sendError(Text.translatable("sniffer.commands.watcher.failed.datapack_not_found", id))
109115
return 0
110116
}
111117
val functionsRoot = packPath.resolve("data")
@@ -120,14 +126,14 @@ object WatchCommand {
120126
}
121127
}
122128
if(ok){
123-
src.sendFeedback({ Text.literal("Started watching: $id") }, false)
129+
src.sendFeedback({ Text.translatable("sniffer.commands.watcher.start", id) }, false)
124130
return 1
125131
}else{
126-
src.sendError(Text.literal("Failed to start watching: $id"))
132+
src.sendError(Text.translatable("sniffer.commands.watcher.start.failed", id))
127133
return 0
128134
}
129135
}catch (ex: Exception){
130-
src.sendError(Text.literal("Failed to start watching: $id"))
136+
src.sendError(Text.translatable("sniffer.commands.watcher.start.failed", id))
131137
LOGGER.error("Failed to start watching: $id", ex)
132138
return 0
133139
}
@@ -137,14 +143,14 @@ object WatchCommand {
137143
try{
138144
val ok = WatcherManager.stop(id)
139145
if(ok){
140-
src.sendFeedback({ Text.literal("Stopped watching: $id") }, false)
146+
src.sendFeedback({ Text.translatable("sniffer.commands.watcher.stop", id) }, false)
141147
return 1
142148
}else{
143-
src.sendError(Text.literal("Failed to stop watching: $id"))
149+
src.sendError(Text.translatable("sniffer.commands.watcher.stop.failed", id))
144150
return 0
145151
}
146152
}catch (ex: Exception){
147-
src.sendError(Text.literal("Failed to stop watching: $id"))
153+
src.sendError(Text.translatable("sniffer.commands.watcher.stop.failed", id))
148154
LOGGER.error("Failed to stop watching: $id", ex)
149155
return 0
150156
}
@@ -226,15 +232,15 @@ object WatchCommand {
226232
try{
227233
return@map CommandFunction.create(identifier, dispatcher, serverCommandSource, lines)
228234
}catch (ex: Exception){
229-
val text = Text.literal("Failed to modify: $identifier").withColor(Colors.RED)
235+
val text = Text.translatable("sniffer.commands.watcher.modify.failed", identifier).withColor(Colors.RED)
230236
server.playerManager.broadcast(text, false)
231237
LOGGER.error("Failed to modify function: $identifier", ex)
232238
return@map null
233239
}
234240
}.filterNotNull()
235241
}.handle {modified, ex ->
236242
if(ex != null){
237-
val text = Text.literal("Exception while modifying functions: ${ex.message}").withColor(Colors.RED)
243+
val text = Text.translatable("sniffer.commands.watcher.modify.failed.ex", ex.message).withColor(Colors.RED)
238244
server.playerManager.broadcast(text, false)
239245
LOGGER.error("Failed to modify functions", ex)
240246
}
@@ -264,15 +270,15 @@ object WatchCommand {
264270
try{
265271
return@map CommandFunction.create(identifier, dispatcher, serverCommandSource, lines)
266272
}catch (ex: Exception){
267-
val text = Text.literal("Failed to create: $identifier").withColor(Colors.RED)
273+
val text = Text.translatable("sniffer.commands.watcher.create.failed", identifier).withColor(Colors.RED)
268274
server.playerManager.broadcast(text, false)
269275
LOGGER.error("Failed to create function: $identifier", ex)
270276
return@map null
271277
}
272278
}.filterNotNull()
273279
}.handle {created, ex ->
274280
if(ex != null){
275-
val text = Text.literal("Exception while creating functions: ${ex.message}").withColor(Colors.RED)
281+
val text = Text.translatable("sniffer.commands.watcher.create.failed.ex", ex.message).withColor(Colors.RED)
276282
server.playerManager.broadcast(text, false)
277283
LOGGER.error("Failed to create functions", ex)
278284
}
@@ -295,7 +301,7 @@ object WatchCommand {
295301
}
296302
}.handle {deleted, ex ->
297303
if(ex != null){
298-
val text = Text.literal("Exception while deleting functions: ${ex.message}").withColor(Colors.RED)
304+
val text = Text.translatable("sniffer.commands.watcher.delete.failed.ex", ex.message).withColor(Colors.RED)
299305
server.playerManager.broadcast(text, false)
300306
LOGGER.error("Failed to delete functions", ex)
301307
}
Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,56 @@
11
{
2-
"sniffer.commands.breakpoint.set": "Breakpoint has triggered",
2+
"sniffer.commands.assert.failed": "Assert failed: ",
3+
"sniffer.commands.assert.failed.expression": "Expression: %s",
4+
"sniffer.commands.assert.failed.not_a_byte": "Assert failed. Result is not a byte: ",
5+
"sniffer.commands.assert.failed.result_is_zero": "Assert failed: result is 0",
6+
"sniffer.commands.assert.failed.stack": "Stack trace: ",
7+
"sniffer.commands.assert.failed.unknown_error": "Unknown error",
8+
"sniffer.commands.assert.passed": "Assert passed",
39
"sniffer.commands.breakpoint.get": "Argument %s has the following value: %s",
410
"sniffer.commands.breakpoint.get.fail": "Failed to get the value of argument %s",
511
"sniffer.commands.breakpoint.get.fail.error": "Unexpected error while getting the value of argument: %s",
612
"sniffer.commands.breakpoint.get.fail.not_macro": "Current function is not a macro",
713
"sniffer.commands.breakpoint.move": "The game is now moving on",
814
"sniffer.commands.breakpoint.move.not_debugging": "Can only use `move` command in breakpoint mode",
15+
"sniffer.commands.breakpoint.off": "Breakpoint is now inactive",
16+
"sniffer.commands.breakpoint.on": "Breakpoint is now active",
17+
"sniffer.commands.breakpoint.run": "Executing: %s",
18+
"sniffer.commands.breakpoint.set": "Breakpoint has triggered",
919
"sniffer.commands.breakpoint.step.fail": "Can only use `step` command in breakpoint mode",
1020
"sniffer.commands.breakpoint.step.over": "Current tick has finished, exiting breakpoint mode",
11-
"sniffer.commands.breakpoint.run": "Executing: %s",
12-
"sniffer.commands.breakpoint.on": "Breakpoint is now active",
13-
"sniffer.commands.breakpoint.off": "Breakpoint is now inactive",
14-
"sniffer.step": "Step Into",
15-
"sniffer.name": "Sniffer",
16-
"sniffer.config.title": "Sniffer Configuration",
21+
"sniffer.commands.jvmtimer.disable": "Timer %s is disabled",
22+
"sniffer.commands.jvmtimer.info.average": "Average time: ",
23+
"sniffer.commands.jvmtimer.info.count": "Count: ",
24+
"sniffer.commands.jvmtimer.info.id": "Timer id: ",
25+
"sniffer.commands.jvmtimer.info.max_min": "Max/Min time: ",
26+
"sniffer.commands.jvmtimer.info.total": "Total time: ",
27+
"sniffer.commands.jvmtimer.not_started": "Timer %s hasn't started",
28+
"sniffer.commands.jvmtimer.reset": "Timer %s is reset",
29+
"sniffer.commands.jvmtimer.started": "Timer %s is started",
30+
"sniffer.commands.jvmtimer.stopped": "Timer %s is stopped",
31+
"sniffer.commands.watcher.auto": "Auto reload enabled: %s",
32+
"sniffer.commands.watcher.auto.disable": "Auto reload now is disabled",
33+
"sniffer.commands.watcher.auto.enable": "Auto reload now is enabled",
34+
"sniffer.commands.watcher.create.failed": "Failed to create: %s",
35+
"sniffer.commands.watcher.create.failed.ex": "Exception while creating functions: %s",
36+
"sniffer.commands.watcher.delete.failed": "Failed to delete: %s",
37+
"sniffer.commands.watcher.delete.failed.ex": "Exception while deleting functions: %s",
38+
"sniffer.commands.watcher.failed.datapack_not_found": "Datapack %s not found",
39+
"sniffer.commands.watcher.hot_reload": "Hot reloading",
40+
"sniffer.commands.watcher.modify.failed": "Failed to modify: %s",
41+
"sniffer.commands.watcher.modify.failed.ex": "Exception while modifying functions: %s",
42+
"sniffer.commands.watcher.start": "Started watching: %s",
43+
"sniffer.commands.watcher.start.failed": "Failed to start watching: %s",
44+
"sniffer.commands.watcher.stop": "Stopped watching: %s",
45+
"sniffer.commands.watcher.stop.failed": "Failed to stop watching: %s",
1746
"sniffer.config.category.main": "Main Settings",
18-
"sniffer.config.port": "WebSocket Port",
19-
"sniffer.config.port.tooltip": "The port on which the debugger WebSocket server will run (1024-65535)",
2047
"sniffer.config.path": "WebSocket Path",
2148
"sniffer.config.path.tooltip": "The endpoint path for the WebSocket connection",
49+
"sniffer.config.port": "WebSocket Port",
50+
"sniffer.config.port.tooltip": "The port on which the debugger WebSocket server will run (1024-65535)",
2251
"sniffer.config.server_address": "Server Address: %s",
23-
"sniffer.config.server_address.tooltip": "The complete address to connect your debugger client to"
52+
"sniffer.config.server_address.tooltip": "The complete address to connect your debugger client to",
53+
"sniffer.config.title": "Sniffer Configuration",
54+
"sniffer.name": "Sniffer",
55+
"sniffer.step": "Step Into"
2456
}

0 commit comments

Comments
 (0)