Skip to content

Commit eb559c8

Browse files
committed
Check for non-root translation keys
1 parent 0f532ca commit eb559c8

7 files changed

Lines changed: 56 additions & 24 deletions

File tree

changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 2.6.7
4+
5+
- Added detection for non-root translation keys
6+
37
## 2.6.6
48

59
- Fixed format code translation not resetting format on color change

common/src/main/java/dev/terminalmc/chatnotify/gui/widget/list/root/notif/trigger/TriggerEditorList.java

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ public class TriggerEditorList extends OptionList {
5757
private boolean restyle;
5858
private MultiLineTextField textDisplayField;
5959
private String displayText = "";
60-
private TextField keyDisplayField;
61-
private String displayKey = "";
60+
private MultiLineTextField keyDisplayField;
61+
private String displayKeys = "";
6262

6363
public TriggerEditorList(
6464
Minecraft mc,
@@ -116,13 +116,17 @@ protected void addEntries() {
116116
));
117117

118118
// Key display field
119-
keyDisplayField = new TextField(dynWideEntryX, 0, dynWideEntryWidth, entryHeight);
120-
keyDisplayField.setMaxLength(256);
121-
keyDisplayField.setValue(displayKey);
122-
addEntry(new Entry.DisplayField(
119+
keyDisplayField = new MultiLineTextField(
123120
dynWideEntryX,
121+
0,
124122
dynWideEntryWidth,
125-
entryHeight,
123+
entryHeight
124+
);
125+
keyDisplayField.setValue(displayKeys);
126+
addSpacedEntry(new Entry.DisplayField(
127+
dynWideEntryX,
128+
dynWideEntryWidth,
129+
entryHeight + itemHeight,
126130
keyDisplayField,
127131
localized("option", "notif.trigger.editor.display.key")
128132
));
@@ -141,9 +145,9 @@ private void setTextDisplayValue(String text) {
141145
textDisplayField.setValue(displayText);
142146
}
143147

144-
private void setKeyDisplayValue(String key) {
145-
displayKey = key;
146-
keyDisplayField.setValue(displayKey);
148+
private void setKeyDisplayValue(String keys) {
149+
displayKeys = keys;
150+
keyDisplayField.setValue(displayKeys);
147151
}
148152

149153
// Chat message list
@@ -503,12 +507,26 @@ private static class MessageEntry extends Entry {
503507
@Override
504508
public boolean mouseClicked(double mouseX, double mouseY, int button) {
505509
list.setTextDisplayValue(FormatUtil.stripCodes(msg.getString()));
506-
list.setKeyDisplayValue(msg.getContents() instanceof TranslatableContents tc
507-
? tc.getKey()
508-
: localized("option", "notif.trigger.editor.display.key.none").getString());
510+
511+
List<String> keys = new ArrayList<>();
512+
getKeys(msg, keys);
513+
list.setKeyDisplayValue(keys.isEmpty()
514+
? localized("option", "notif.trigger.editor.display.key.none").getString()
515+
: String.join("\n", keys));
516+
509517
list.setScrollAmount(0);
510518
return true;
511519
}
520+
521+
private static void getKeys(Component msg, List<String> keys) {
522+
if (msg.getContents() instanceof TranslatableContents tc) {
523+
keys.add(tc.getKey());
524+
}
525+
526+
for (Component sibling : msg.getSiblings()) {
527+
getKeys(sibling, keys);
528+
}
529+
}
512530
}
513531
}
514532
}

common/src/main/java/dev/terminalmc/chatnotify/util/text/MessageUtil.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,8 @@ private static String checkOwner(String cleanStr) {
173173
}
174174
if (recentStart != -1) {
175175
if (debug)
176-
ChatNotify.LOG.warn("{}",
176+
ChatNotify.LOG.warn(
177+
"{}",
177178
"Matched recent message '{}' at index {}",
178179
recentMessages.get(i).getSecond(),
179180
recentStart
@@ -184,7 +185,8 @@ private static String checkOwner(String cleanStr) {
184185
Matcher triggerMatcher = normalSearch(prefix, t.string);
185186
if (triggerMatcher.find()) {
186187
if (debug)
187-
ChatNotify.LOG.warn("{}",
188+
ChatNotify.LOG.warn(
189+
"{}",
188190
"Matched trigger '{}' at index {}",
189191
t.string,
190192
triggerMatcher.start()
@@ -379,6 +381,11 @@ public static boolean keySearch(Component msg, String key) {
379381
return true;
380382
} else if (msg.getContents() instanceof TranslatableContents tc) {
381383
return tc.getKey().contains(key);
384+
} else {
385+
for (Component sibling : msg.getSiblings()) {
386+
if (keySearch(sibling, key))
387+
return true;
388+
}
382389
}
383390
return false;
384391
}

common/src/main/java/dev/terminalmc/chatnotify/util/text/StyleUtil.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public static Component restyle(
127127
msg = restyleLeaves(msg, textStyle, matcher.start(), matcher.end());
128128
} while (restyleAllInstances && matcher.find());
129129
}
130-
case KEY -> msg = restyleRoot(msg, textStyle);
130+
case KEY -> msg = restyleAll(msg, textStyle);
131131
}
132132
}
133133
} catch (IllegalArgumentException e) {
@@ -149,14 +149,17 @@ public static Matcher styleSearch(String msg, String str) {
149149
}
150150

151151
/**
152-
* Overwrites the existing root style of the message with the specified style.
152+
* Overwrites the existing style of the message with the specified style at all levels.
153153
*
154154
* @param msg the message to restyle.
155155
* @param style the {@link TextStyle} to apply.
156156
* @return the restyled message.
157157
*/
158-
private static Component restyleRoot(Component msg, TextStyle style) {
159-
return msg.copy().setStyle(applyStyle(msg.getStyle(), style));
158+
private static Component restyleAll(Component msg, TextStyle style) {
159+
MutableComponent copy = msg.copy();
160+
copy.setStyle(applyStyle(msg.getStyle(), style));
161+
copy.getSiblings().replaceAll((sibling) -> restyleAll(sibling, style));
162+
return copy;
160163
}
161164

162165
/**

common/src/main/resources/assets/chatnotify/lang/en_us.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,8 @@
186186
"option.chatnotify.notif.sound.volume": "Volume: ",
187187
"option.chatnotify.notif.trigger": "Triggers",
188188
"option.chatnotify.notif.trigger.editor": "Trigger Editor",
189-
"option.chatnotify.notif.trigger.editor.display.key": "Key",
190-
"option.chatnotify.notif.trigger.editor.display.key.none": "No translation key",
189+
"option.chatnotify.notif.trigger.editor.display.key": "Keys",
190+
"option.chatnotify.notif.trigger.editor.display.key.none": "No translation keys",
191191
"option.chatnotify.notif.trigger.editor.display.text": "Text",
192192
"option.chatnotify.notif.trigger.editor.display.text.hint": "Click on a message from the list below",
193193
"option.chatnotify.notif.trigger.editor.filter": "Filter",

common/src/main/resources/assets/chatnotify/lang/zh_tw.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,8 @@
186186
"option.chatnotify.notif.sound.volume": "音量:",
187187
"option.chatnotify.notif.trigger": "Triggers",
188188
"option.chatnotify.notif.trigger.editor": "Trigger Editor",
189-
"option.chatnotify.notif.trigger.editor.display.key": "Key",
190-
"option.chatnotify.notif.trigger.editor.display.key.none": "No translation key",
189+
"option.chatnotify.notif.trigger.editor.display.key": "Keys",
190+
"option.chatnotify.notif.trigger.editor.display.key.none": "No translation keys",
191191
"option.chatnotify.notif.trigger.editor.display.text": "Text",
192192
"option.chatnotify.notif.trigger.editor.display.text.hint": "Click on a message from the list below",
193193
"option.chatnotify.notif.trigger.editor.filter": "Filter",

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
template_version=10
1111

1212
# Mod Version
13-
mod_version=2.6.6
13+
mod_version=2.6.7
1414
# 'STABLE', 'BETA' or 'ALPHA'
1515
mod_version_type=STABLE
1616

0 commit comments

Comments
 (0)