translation file support
This commit is contained in:
@@ -3,7 +3,7 @@ yarn_mappings=1.21.10+build.2
|
||||
loader_version=0.17.3
|
||||
loom_version=1.13-SNAPSHOT
|
||||
|
||||
library_version=1.0
|
||||
library_version=1.1
|
||||
maven_group=com.kasetoatz
|
||||
archives_base_name=dacl
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import net.minecraft.text.Text;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -14,13 +14,13 @@ public abstract class AbstractInputOption<T> extends AbstractOption<T>
|
||||
public InputField textField;
|
||||
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);
|
||||
this.validator = validator;
|
||||
}
|
||||
|
||||
public AbstractInputOption(String text, String key, T defaultValue)
|
||||
public AbstractInputOption(Text text, String key, T defaultValue)
|
||||
{
|
||||
super(text, key, defaultValue);
|
||||
}
|
||||
|
||||
@@ -10,9 +10,9 @@ public abstract class AbstractOption<T>
|
||||
private final T defaultValue;
|
||||
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.defaultValue = defaultValue;
|
||||
this.value = defaultValue;
|
||||
|
||||
@@ -9,7 +9,7 @@ import static com.kasetoatz.dacl.DumbassConfig.BOOLEAN_TRUE_COLOR;
|
||||
|
||||
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);
|
||||
}
|
||||
@@ -17,7 +17,7 @@ public class BoolOption extends AbstractButtonOption<Boolean>
|
||||
@Override
|
||||
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
|
||||
|
||||
@@ -2,15 +2,16 @@ package com.kasetoatz.dacl.options;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.kasetoatz.dacl.options.validators.AbstractValidator;
|
||||
import net.minecraft.text.Text;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
public FloatOption(String text, String key, Float defaultValue)
|
||||
public FloatOption(Text text, String key, Float defaultValue)
|
||||
{
|
||||
super(text, key, defaultValue);
|
||||
}
|
||||
|
||||
@@ -2,15 +2,16 @@ package com.kasetoatz.dacl.options;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.kasetoatz.dacl.options.validators.AbstractValidator;
|
||||
import net.minecraft.text.Text;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
public IntOption(String text, String key, Integer defaultValue)
|
||||
public IntOption(Text text, String key, Integer defaultValue)
|
||||
{
|
||||
super(text, key, defaultValue);
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ public class SubOption extends AbstractButtonOption<JsonObject>
|
||||
private final Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
||||
private ConfigScreen ui;
|
||||
|
||||
private SubOption(String text, String key)
|
||||
private SubOption(Text text, String key)
|
||||
{
|
||||
super(text, key, null);
|
||||
}
|
||||
@@ -25,7 +25,7 @@ public class SubOption extends AbstractButtonOption<JsonObject>
|
||||
@Override
|
||||
public Text getButtonText()
|
||||
{
|
||||
return Text.literal("Open");
|
||||
return Text.translatable("text.button.suboption");
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
@@ -65,7 +65,7 @@ public class SubOption extends AbstractButtonOption<JsonObject>
|
||||
{
|
||||
private final SubOption option;
|
||||
|
||||
private Builder(String text, String key)
|
||||
private Builder(Text text, String key)
|
||||
{
|
||||
this.option = new SubOption(text, key);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.kasetoatz.dacl.options.validators;
|
||||
|
||||
import net.minecraft.text.Text;
|
||||
|
||||
public class RangeValidator<T extends Number & Comparable<T>> extends AbstractValidator<T>
|
||||
{
|
||||
private final T min;
|
||||
@@ -28,19 +30,14 @@ public class RangeValidator<T extends Number & Comparable<T>> extends AbstractVa
|
||||
@Override
|
||||
public String getErrorMessage()
|
||||
{
|
||||
String error = "Number must be ";
|
||||
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
|
||||
{
|
||||
error += "between " + min + " and " + max;
|
||||
}
|
||||
return error;
|
||||
return Text.translatable("error.range.between", min, max).toString();
|
||||
}
|
||||
}
|
||||
|
||||
8
src/main/resources/assets/dacl/lang/en_us.json
Normal file
8
src/main/resources/assets/dacl/lang/en_us.json
Normal 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"
|
||||
}
|
||||
Reference in New Issue
Block a user