Skip to content

Commit

Permalink
simple rule translation
Browse files Browse the repository at this point in the history
  • Loading branch information
Fallen-Breath committed Aug 1, 2021
1 parent 839d286 commit 6fc7d2c
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/main/java/carpet/commands/CarpetCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,15 @@ private static int displayRuleMenu(CommandSource source, ParsedRule<?> rule)
}
catch (CommandSyntaxException e)
{
Messenger.m(source, "w "+rule.name +" is set to: ","wb "+rule.getAsString());
Messenger.m(source, "w "+rule.translatedName() +" is set to: ","wb "+rule.getAsString());
return 1;
}

Messenger.m(player, "");
Messenger.m(player, "wb "+rule.name,"!/carpet "+rule.name,"^g refresh");
Messenger.m(player, "w "+rule.description);
Messenger.m(player, "wb "+rule.translatedName(),"!/carpet "+rule.name,"^g refresh");
Messenger.m(player, "w "+rule.translatedDescription());

rule.extraInfo.forEach(s -> Messenger.m(player, "g " + s));
rule.translatedExtras().forEach(s -> Messenger.m(player, "g " + s));

List<ITextComponent> tags = new ArrayList<>();
tags.add(Messenger.c("w Tags: "));
Expand Down Expand Up @@ -145,9 +145,9 @@ private static int removeDefault(CommandSource source, ParsedRule<?> rule)
private static ITextComponent displayInteractiveSetting(ParsedRule<?> e)
{
List<Object> args = new ArrayList<>();
args.add("w - "+e.name+" ");
args.add("w - "+e.translatedName()+" ");
args.add("!/carpet "+e.name);
args.add("^y "+e.description);
args.add("^y "+e.translatedDescription());
for (String option: e.options)
{
args.add(makeSetRuleButton(e, option, true));
Expand Down
32 changes: 32 additions & 0 deletions src/main/java/carpet/settings/ParsedRule.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import carpet.CarpetServer;
import carpet.utils.Messenger;
import carpet.utils.Translations;
import com.google.common.collect.ImmutableList;
import net.minecraft.command.CommandSource;

Expand All @@ -12,6 +13,8 @@
import java.util.List;
import java.util.Locale;

import static carpet.utils.Translations.tr;

public final class ParsedRule<T> implements Comparable<ParsedRule> {
public final Field field;
public final String name;
Expand Down Expand Up @@ -216,4 +219,33 @@ public String toString()
{
return this.name + ": " + getAsString();
}

private String translationKey()
{
return String.format("rule.%s.name", name);
}

public String translatedName(){
String key = translationKey();
return Translations.hasTranslation(key) ? tr(key) + String.format(" (%s)", name): name;
}

public String translatedDescription()
{
return tr(String.format("rule.%s.desc", (name)), description);
}

public List<String> translatedExtras()
{
if (!Translations.hasTranslations()) return extraInfo;
String keyBase = String.format("rule.%s.extra.", name);
List<String> extras = new ArrayList<>();
int i = 0;
while (Translations.hasTranslation(keyBase+i))
{
extras.add(Translations.tr(keyBase+i));
i++;
}
return (extras.isEmpty()) ? extraInfo : extras;
}
}

0 comments on commit 6fc7d2c

Please sign in to comment.