|
@@ -6,42 +6,38 @@ import net.fabricmc.api.Environment;
|
|
import net.minecraft.client.resource.language.I18n;
|
|
import net.minecraft.client.resource.language.I18n;
|
|
import net.minecraft.text.Text;
|
|
import net.minecraft.text.Text;
|
|
import net.minecraft.text.TranslatableText;
|
|
import net.minecraft.text.TranslatableText;
|
|
-import org.apache.commons.lang3.ArrayUtils;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
-import java.util.Arrays;
|
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Optional;
|
|
import java.util.Optional;
|
|
-import java.util.regex.Pattern;
|
|
|
|
|
|
|
|
public final class TranslationKey {
|
|
public final class TranslationKey {
|
|
|
|
|
|
- private static final String DELIMITER = ".";
|
|
|
|
|
|
+ private static final char DELIMITER = '.';
|
|
|
|
|
|
public static TranslationKey from(Config config) {
|
|
public static TranslationKey from(Config config) {
|
|
- return new TranslationKey("config" + DELIMITER + config.getMod().getId());
|
|
|
|
|
|
+ return new TranslationKey("config" + DELIMITER + config.getMod().getId(), null);
|
|
}
|
|
}
|
|
|
|
|
|
private final String modKey;
|
|
private final String modKey;
|
|
- private final String[] subKey;
|
|
|
|
|
|
+ private final String subKey;
|
|
|
|
|
|
@Environment(EnvType.CLIENT)
|
|
@Environment(EnvType.CLIENT)
|
|
- private TranslationKey(String modKey, String... subKey) {
|
|
|
|
|
|
+ private TranslationKey(String modKey, String subKey) {
|
|
this.modKey = modKey;
|
|
this.modKey = modKey;
|
|
this.subKey = subKey;
|
|
this.subKey = subKey;
|
|
}
|
|
}
|
|
|
|
|
|
private String getKey() {
|
|
private String getKey() {
|
|
- StringBuilder builder = new StringBuilder(modKey);
|
|
|
|
- for (String keyPart : subKey) {
|
|
|
|
- builder.append(DELIMITER);
|
|
|
|
- builder.append(keyPart);
|
|
|
|
|
|
+ if (subKey == null) {
|
|
|
|
+ return modKey;
|
|
|
|
+ } else {
|
|
|
|
+ return modKey + subKey;
|
|
}
|
|
}
|
|
- return builder.toString();
|
|
|
|
}
|
|
}
|
|
|
|
|
|
public TranslationKey root() {
|
|
public TranslationKey root() {
|
|
- return new TranslationKey(modKey);
|
|
|
|
|
|
+ return new TranslationKey(modKey, null);
|
|
}
|
|
}
|
|
|
|
|
|
public boolean exists() {
|
|
public boolean exists() {
|
|
@@ -53,9 +49,14 @@ public final class TranslationKey {
|
|
}
|
|
}
|
|
|
|
|
|
public TranslationKey append(String... subKeys) {
|
|
public TranslationKey append(String... subKeys) {
|
|
- return new TranslationKey(modKey, ArrayUtils.addAll(subKey, Arrays.stream(subKeys).map(subKey -> {
|
|
|
|
- return subKey.split(Pattern.quote(DELIMITER));
|
|
|
|
- }).flatMap(Arrays::stream).toArray(String[]::new)));
|
|
|
|
|
|
+ StringBuilder subKeyBuilder = new StringBuilder();
|
|
|
|
+ if (subKey != null) {
|
|
|
|
+ subKeyBuilder.append(subKey);
|
|
|
|
+ }
|
|
|
|
+ for (String subKey : subKeys) {
|
|
|
|
+ subKeyBuilder.append(DELIMITER).append(subKey);
|
|
|
|
+ }
|
|
|
|
+ return new TranslationKey(modKey, subKeyBuilder.toString());
|
|
}
|
|
}
|
|
|
|
|
|
public Optional<TranslationKey[]> appendTooltip() {
|
|
public Optional<TranslationKey[]> appendTooltip() {
|