From da857ce2a175843a2b1696a6091c7dd78c6a2af2 Mon Sep 17 00:00:00 2001 From: LostLuma Date: Fri, 19 Apr 2024 04:10:12 +0200 Subject: [PATCH] Improve translation key generation and fallback role names --- .../gui/widget/DescriptionListWidget.java | 16 +++++++++++++--- .../resources/assets/modmenu/lang/en_us.json | 1 + 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/terraformersmc/modmenu/gui/widget/DescriptionListWidget.java b/src/main/java/com/terraformersmc/modmenu/gui/widget/DescriptionListWidget.java index e237804a..c1993f1b 100644 --- a/src/main/java/com/terraformersmc/modmenu/gui/widget/DescriptionListWidget.java +++ b/src/main/java/com/terraformersmc/modmenu/gui/widget/DescriptionListWidget.java @@ -223,9 +223,7 @@ public void renderList(DrawContext DrawContext, int mouseX, int mouseY, float de var role = iterator.next(); var roleName = role.getKey(); - var component = Text.translatableWithFallback("modmenu.credits.role." + roleName.toLowerCase(), roleName); - - for (var line : textRenderer.wrapLines(component.append(Text.literal(":")), wrapWidth - 16)) { + for (var line : textRenderer.wrapLines(this.creditsRoleText(roleName), wrapWidth - 16)) { children().add(new DescriptionEntry(line, indent)); indent = 16; } @@ -352,6 +350,18 @@ public void renderScrollBar(BufferBuilder bufferBuilder, Tessellator tessellator } } + private Text creditsRoleText(String roleName) { + // Replace spaces and dashes in role names with underscores if they exist + // Notably Quilted Fabric API does this with FabricMC as "Upstream Owner" + var translationKey = roleName.replaceAll("[\s-]", "_"); + + // Add an s to the default untranslated string if it ends in r since this + // Fixes common role names people use in English (e.g. Author -> Authors) + var fallback = roleName.endsWith("r") ? roleName + "s" : roleName; + + return Text.translatableWithFallback("modmenu.credits.role." + translationKey, fallback).append(Text.literal(":")); + } + protected class DescriptionEntry extends ElementListWidget.Entry { protected OrderedText text; protected int indent; diff --git a/src/main/resources/assets/modmenu/lang/en_us.json b/src/main/resources/assets/modmenu/lang/en_us.json index e0df0b13..11f13b63 100644 --- a/src/main/resources/assets/modmenu/lang/en_us.json +++ b/src/main/resources/assets/modmenu/lang/en_us.json @@ -93,6 +93,7 @@ "modmenu.credits.role.maintainer": "Maintainers", "modmenu.credits.role.playtester": "Playtesters", "modmenu.credits.role.illustrator": "Illustrators", + "modmenu.credits.role.owner": "Owners", "modmenu.modsFolder": "Open Mods Folder", "modmenu.configsFolder": "Open Configs Folder",