Skip to content

Commit

Permalink
Improve translation key generation and fallback role names
Browse files Browse the repository at this point in the history
  • Loading branch information
LostLuma committed Apr 19, 2024
1 parent 99bb770 commit da857ce
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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<DescriptionEntry> {
protected OrderedText text;
protected int indent;
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/assets/modmenu/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit da857ce

Please sign in to comment.