translation file support

This commit is contained in:
2025-11-07 16:35:40 +01:00
parent 00a216cd38
commit d2ca2f9338
10 changed files with 32 additions and 25 deletions

View File

@@ -3,7 +3,7 @@ yarn_mappings=1.21.10+build.2
loader_version=0.17.3 loader_version=0.17.3
loom_version=1.13-SNAPSHOT loom_version=1.13-SNAPSHOT
library_version=1.0 library_version=1.1
maven_group=com.kasetoatz maven_group=com.kasetoatz
archives_base_name=dacl archives_base_name=dacl

View File

@@ -5,7 +5,7 @@ import net.minecraft.text.Text;
public abstract class AbstractButtonOption<T> extends AbstractOption<T> public abstract class AbstractButtonOption<T> extends AbstractOption<T>
{ {
public AbstractButtonOption(String text, String key, T defaultValue) public AbstractButtonOption(Text text, String key, T defaultValue)
{ {
super(text, key, defaultValue); super(text, key, defaultValue);
} }

View File

@@ -14,13 +14,13 @@ public abstract class AbstractInputOption<T> extends AbstractOption<T>
public InputField textField; public InputField textField;
private AbstractValidator<T> validator; private AbstractValidator<T> validator;
public AbstractInputOption(String text, String key, T defaultValue, AbstractValidator<T> validator) public AbstractInputOption(Text text, String key, T defaultValue, AbstractValidator<T> validator)
{ {
super(text, key, defaultValue); super(text, key, defaultValue);
this.validator = validator; this.validator = validator;
} }
public AbstractInputOption(String text, String key, T defaultValue) public AbstractInputOption(Text text, String key, T defaultValue)
{ {
super(text, key, defaultValue); super(text, key, defaultValue);
} }

View File

@@ -10,9 +10,9 @@ public abstract class AbstractOption<T>
private final T defaultValue; private final T defaultValue;
private T value; private T value;
public AbstractOption(String text, String key, T defaultValue) public AbstractOption(Text text, String key, T defaultValue)
{ {
this.text = Text.of(text); this.text = text;
this.key = key; this.key = key;
this.defaultValue = defaultValue; this.defaultValue = defaultValue;
this.value = defaultValue; this.value = defaultValue;

View File

@@ -9,7 +9,7 @@ import static com.kasetoatz.dacl.DumbassConfig.BOOLEAN_TRUE_COLOR;
public class BoolOption extends AbstractButtonOption<Boolean> public class BoolOption extends AbstractButtonOption<Boolean>
{ {
public BoolOption(String text, String key, boolean defaultValue) public BoolOption(Text text, String key, boolean defaultValue)
{ {
super(text, key, defaultValue); super(text, key, defaultValue);
} }
@@ -17,7 +17,7 @@ public class BoolOption extends AbstractButtonOption<Boolean>
@Override @Override
public Text getButtonText() public Text getButtonText()
{ {
return this.getValue() ? Text.literal("True").withColor(BOOLEAN_TRUE_COLOR) : Text.literal("False").withColor(BOOLEAN_FALSE_COLOR); return this.getValue() ? Text.translatable("text.button.true").withColor(BOOLEAN_TRUE_COLOR) : Text.translatable("text.button.false").withColor(BOOLEAN_FALSE_COLOR);
} }
@Override @Override

View File

@@ -2,15 +2,16 @@ package com.kasetoatz.dacl.options;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.kasetoatz.dacl.options.validators.AbstractValidator; import com.kasetoatz.dacl.options.validators.AbstractValidator;
import net.minecraft.text.Text;
public class FloatOption extends AbstractInputOption<Float> public class FloatOption extends AbstractInputOption<Float>
{ {
public FloatOption(String text, String key, Float defaultValue, AbstractValidator<Float> validator) public FloatOption(Text text, String key, Float defaultValue, AbstractValidator<Float> validator)
{ {
super(text, key, defaultValue, validator); super(text, key, defaultValue, validator);
} }
public FloatOption(String text, String key, Float defaultValue) public FloatOption(Text text, String key, Float defaultValue)
{ {
super(text, key, defaultValue); super(text, key, defaultValue);
} }

View File

@@ -2,15 +2,16 @@ package com.kasetoatz.dacl.options;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.kasetoatz.dacl.options.validators.AbstractValidator; import com.kasetoatz.dacl.options.validators.AbstractValidator;
import net.minecraft.text.Text;
public class IntOption extends AbstractInputOption<Integer> public class IntOption extends AbstractInputOption<Integer>
{ {
public IntOption(String text, String key, Integer defaultValue, AbstractValidator<Integer> validator) public IntOption(Text text, String key, Integer defaultValue, AbstractValidator<Integer> validator)
{ {
super(text, key, defaultValue, validator); super(text, key, defaultValue, validator);
} }
public IntOption(String text, String key, Integer defaultValue) public IntOption(Text text, String key, Integer defaultValue)
{ {
super(text, key, defaultValue); super(text, key, defaultValue);
} }

View File

@@ -17,7 +17,7 @@ public class SubOption extends AbstractButtonOption<JsonObject>
private final Gson gson = new GsonBuilder().setPrettyPrinting().create(); private final Gson gson = new GsonBuilder().setPrettyPrinting().create();
private ConfigScreen ui; private ConfigScreen ui;
private SubOption(String text, String key) private SubOption(Text text, String key)
{ {
super(text, key, null); super(text, key, null);
} }
@@ -25,7 +25,7 @@ public class SubOption extends AbstractButtonOption<JsonObject>
@Override @Override
public Text getButtonText() public Text getButtonText()
{ {
return Text.literal("Open"); return Text.translatable("text.button.suboption");
} }
@Override @Override
@@ -56,7 +56,7 @@ public class SubOption extends AbstractButtonOption<JsonObject>
} }
} }
public static Builder builder(String text, String key) public static Builder builder(Text text, String key)
{ {
return new Builder(text, key); return new Builder(text, key);
} }
@@ -65,7 +65,7 @@ public class SubOption extends AbstractButtonOption<JsonObject>
{ {
private final SubOption option; private final SubOption option;
private Builder(String text, String key) private Builder(Text text, String key)
{ {
this.option = new SubOption(text, key); this.option = new SubOption(text, key);
} }

View File

@@ -1,5 +1,7 @@
package com.kasetoatz.dacl.options.validators; package com.kasetoatz.dacl.options.validators;
import net.minecraft.text.Text;
public class RangeValidator<T extends Number & Comparable<T>> extends AbstractValidator<T> public class RangeValidator<T extends Number & Comparable<T>> extends AbstractValidator<T>
{ {
private final T min; private final T min;
@@ -28,19 +30,14 @@ public class RangeValidator<T extends Number & Comparable<T>> extends AbstractVa
@Override @Override
public String getErrorMessage() public String getErrorMessage()
{ {
String error = "Number must be ";
if (min == null && max != null) if (min == null && max != null)
{ {
error += "smaller than " + max; return Text.translatable("error.range.smaller", max).toString();
} }
else if (min != null && max == null) if (min != null && max == null)
{ {
error += "larger than " + min; return Text.translatable("error.range.larger", min).toString();
} }
else return Text.translatable("error.range.between", min, max).toString();
{
error += "between " + min + " and " + max;
}
return error;
} }
} }

View File

@@ -0,0 +1,8 @@
{
"text.button.true": "True",
"text.button.false": "False",
"error.range.smaller": "Number must be smaller than %s",
"error.range.larger": "Number must be larger than %s",
"error.range.between": "Number must be between %s and %s",
"text.button.suboption": "Open"
}