mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-29 09:15:27 +00:00
Move English message text into messages/en_US.json
Message classes now declare only ids; the English text, line lists and plural forms load from one bundled JSON resource, which IrisMessages turns into the catalog. A constant whose id is missing or has the wrong shape fails at class load. EnglishMessageCatalogTest guards that every English id has exactly one constant. A round-trip dump of the new catalog is byte-identical to the generated resource. Java: -4711 lines; net -3185 including the JSON.
This commit is contained in:
1 parent
5e2eaba07e
commit
bcc5a1abb9
17 files changed
+3192
-6377
No files matched your search
@@ -1,12 +1,13 @@
|
||||
package art.arcane.iris.core.gui;
|
||||
|
||||
import art.arcane.iris.core.localization.DesktopUiMessages;
|
||||
import art.arcane.iris.core.localization.IrisMessages;
|
||||
import art.arcane.iris.engine.framework.render.RenderType;
|
||||
import art.arcane.volmlib.util.localization.MessageKey;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
|
||||
public class VisionRenderTypeTest {
|
||||
@Test
|
||||
@@ -26,8 +27,6 @@ public class VisionRenderTypeTest {
|
||||
}
|
||||
|
||||
private static void assertTrueCatalogMember(MessageKey key) {
|
||||
assertEquals(key.id(), 1, DesktopUiMessages.keys().stream()
|
||||
.filter(candidate -> candidate.id().equals(key.id()))
|
||||
.count());
|
||||
assertSame(key.id(), key, IrisMessages.catalog().key(key.id()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package art.arcane.iris.core.localization;
|
||||
|
||||
import art.arcane.volmlib.util.director.DirectorMessages;
|
||||
import art.arcane.volmlib.util.localization.MessageKey;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class EnglishMessageCatalogTest {
|
||||
private static final List<Class<?>> MESSAGE_CLASSES = List.of(
|
||||
IrisMessages.class,
|
||||
BukkitCommandMessages.class,
|
||||
BukkitCommandMessagesExtended.class,
|
||||
ModdedCommandMessages.class,
|
||||
DirectorCommandMessages.class,
|
||||
ModdedHelpMessages.class,
|
||||
RuntimeUiMessages.class,
|
||||
BukkitRuntimeMessages.class,
|
||||
RuntimeProgressMessages.class,
|
||||
PackDownloadMessages.class,
|
||||
ClientUiMessages.class,
|
||||
BukkitUiMessages.class,
|
||||
DesktopUiMessages.class
|
||||
);
|
||||
|
||||
@Test
|
||||
public void everyEnglishMessageHasExactlyOneConstant() throws Exception {
|
||||
Set<String> declaredIds = new HashSet<>();
|
||||
for (Class<?> messageClass : MESSAGE_CLASSES) {
|
||||
for (MessageKey key : publicKeys(messageClass)) {
|
||||
assertTrue("Duplicate constant for " + key.id(), declaredIds.add(key.id()));
|
||||
}
|
||||
}
|
||||
|
||||
Set<String> englishIds = new TreeSet<>(IrisMessages.catalog().ids());
|
||||
DirectorMessages.keys().forEach(key -> englishIds.remove(key.id()));
|
||||
Set<String> orphanedIds = new TreeSet<>(englishIds);
|
||||
orphanedIds.removeAll(declaredIds);
|
||||
|
||||
assertEquals("Messages without a constant", Set.of(), orphanedIds);
|
||||
assertEquals(englishIds, new TreeSet<>(declaredIds));
|
||||
}
|
||||
|
||||
private static List<MessageKey> publicKeys(Class<?> messageClass) throws IllegalAccessException {
|
||||
List<MessageKey> keys = new ArrayList<>();
|
||||
for (Field field : messageClass.getDeclaredFields()) {
|
||||
if (Modifier.isPublic(field.getModifiers()) && MessageKey.class.isAssignableFrom(field.getType())) {
|
||||
keys.add((MessageKey) field.get(null));
|
||||
}
|
||||
}
|
||||
return keys;
|
||||
}
|
||||
}
|
||||
@@ -116,7 +116,7 @@ public class IrisLanguageTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void usesCodeOwnedEnglishWithoutLocaleFile() {
|
||||
public void usesBundledEnglishWithoutLocaleFile() {
|
||||
String rendered = IrisLanguage.plain(
|
||||
IrisMessages.COMMAND_PERMISSION_DENIED,
|
||||
MessageArgument.untrusted("permission", "iris.all")
|
||||
|
||||
Reference in new issue
Block a user