Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prompts/popups use translation strings #2283

Open
wants to merge 15 commits into
base: dev
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ public static OptionPage performance() {
.add(OptionImpl.createBuilder(int.class, sodiumOpts)
.setName(Component.translatable("sodium.options.chunk_update_threads.name"))
.setTooltip(Component.translatable("sodium.options.chunk_update_threads.tooltip"))
.setControl(o -> new SliderControl(o, 0, Runtime.getRuntime().availableProcessors(), 1, ControlValueFormatter.quantityOrDisabled("threads", "Default")))
.setControl(o -> new SliderControl(o, 0, Runtime.getRuntime().availableProcessors(), 1, ControlValueFormatter.quantityOrDisabled(Component.translatable("sodium.options.chunk_update_threads.value").getString(), Component.translatable("options.gamma.default").getString())))
.setImpact(OptionImpact.HIGH)
.setBinding((opts, value) -> opts.performance.chunkBuilderThreads = value, opts -> opts.performance.chunkBuilderThreads)
.setFlags(OptionFlag.REQUIRES_RENDERER_RELOAD)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import java.util.EnumSet;
import java.util.HashSet;
import java.util.List;
import java.util.Collections;
import java.util.stream.Stream;

// TODO: Rename in Sodium 0.6
Expand All @@ -56,7 +57,7 @@ public class SodiumOptionsGUI extends Screen implements ScreenPromptable {
private @Nullable ScreenPrompt prompt;

private SodiumOptionsGUI(Screen prevScreen) {
super(Component.literal("Sodium Renderer Settings"));
super(Component.translatable("sodium.name_renderer.settings"));

this.prevScreen = prevScreen;

Expand Down Expand Up @@ -107,8 +108,12 @@ private void checkPromptTimers() {
}

private void openDonationPrompt(SodiumGameOptions options) {
var prompt = new ScreenPrompt(this, DONATION_PROMPT_MESSAGE, 320, 190,
new ScreenPrompt.Action(Component.literal("Buy us a coffee"), this::openDonationPage));
var donateContents = Component.translatable("sodium.prompt.donate.contents.main",
Component.translatable("sodium.prompt.donate.contents.segment.1").withColor(0x27eb92),
Component.translatable("sodium.prompt.donate.contents.segment.2").withColor(0xff6e00),
Component.translatable("sodium.prompt.donate.contents.segment.3").withColor(0xed49ce));
var prompt = new ScreenPrompt(this, Collections.singletonList(donateContents), 320, 190,
new ScreenPrompt.Action(Component.translatable("sodium.prompt.donate.action"), this::openDonationPage));
prompt.setFocused(true);

options.notifications.hasSeenDonationPrompt = true;
Expand Down Expand Up @@ -436,16 +441,4 @@ public ScreenPrompt getPrompt() {
public Dim2i getDimensions() {
return new Dim2i(0, 0, this.width, this.height);
}

private static final List<FormattedText> DONATION_PROMPT_MESSAGE;

static {
DONATION_PROMPT_MESSAGE = List.of(
FormattedText.composite(Component.literal("Hello!")),
FormattedText.composite(Component.literal("It seems that you've been enjoying "), Component.literal("Sodium").withColor(0x27eb92), Component.literal(", the free and open-source optimization mod for Minecraft.")),
FormattedText.composite(Component.literal("Mods like these are complex. They require "), Component.literal("thousands of hours").withColor(0xff6e00), Component.literal(" of development, debugging, and tuning to create the experience that players have come to expect.")),
FormattedText.composite(Component.literal("If you'd like to show your token of appreciation, and support the development of our mod in the process, then consider "), Component.literal("buying us a coffee").withColor(0xed49ce), Component.literal(".")),
FormattedText.composite(Component.literal("And thanks again for using our mod! We hope it helps you (and your computer.)"))
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,11 @@
import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class ConfigCorruptedScreen extends Screen {
private static final String TEXT_BODY_RAW = """
A problem occurred while trying to load the configuration file. This
can happen when the file has been corrupted on disk, or when trying
to manually edit the file by hand.

If you continue, the configuration file will be reset back to known-good
defaults, and you will lose any changes that have since been made to your
Video Settings.

More information about the error can be found in the log file.
""";

private static final List<Component> TEXT_BODY = Arrays.stream(TEXT_BODY_RAW.split("\n"))
.map(Component::literal)
private static final List<Component> TEXT_BODY = IntStream.rangeClosed(1, 9)
.mapToObj(i -> Component.translatable("sodium.console.config_corrupt.contents." + i))
.collect(Collectors.toList());

private static final int BUTTON_WIDTH = 140;
Expand All @@ -41,7 +30,7 @@ public class ConfigCorruptedScreen extends Screen {
private final Function<Screen, Screen> nextScreen;

public ConfigCorruptedScreen(@Nullable Screen prevScreen, @Nullable Function<Screen, Screen> nextScreen) {
super(Component.literal("Sodium failed to load the configuration file"));
super(Component.translatable("sodium.console.config_corrupt.short"));

this.prevScreen = prevScreen;
this.nextScreen = nextScreen;
Expand All @@ -53,14 +42,14 @@ protected void init() {

int buttonY = this.height - SCREEN_PADDING - BUTTON_HEIGHT;

this.addRenderableWidget(Button.builder(Component.literal("Continue"), (btn) -> {
this.addRenderableWidget(Button.builder(Component.translatable("gui.continue"), (btn) -> {
Console.instance().logMessage(MessageLevel.INFO, Component.translatable("sodium.console.config_file_was_reset"), 3.0);

SodiumClientMod.restoreDefaultOptions();
Minecraft.getInstance().setScreen(this.nextScreen.apply(this.prevScreen));
}).bounds(this.width - SCREEN_PADDING - BUTTON_WIDTH, buttonY, BUTTON_WIDTH, BUTTON_HEIGHT).build());

this.addRenderableWidget(Button.builder(Component.literal("Go back"), (btn) -> {
this.addRenderableWidget(Button.builder(Component.translatable("gui.back"), (btn) -> {
Minecraft.getInstance().setScreen(this.prevScreen);
}).bounds(SCREEN_PADDING, buttonY, BUTTON_WIDTH, BUTTON_HEIGHT).build());
}
Expand All @@ -69,8 +58,8 @@ protected void init() {
public void render(GuiGraphics graphics, int mouseX, int mouseY, float delta) {
super.render(graphics, mouseX, mouseY, delta);

graphics.drawString(this.font, Component.literal("Sodium Renderer"), 32, 32, 0xffffff);
graphics.drawString(this.font, Component.literal("Could not load the configuration file"), 32, 48, 0xff0000);
graphics.drawString(this.font, Component.translatable("sodium.name_renderer"), 32, 32, 0xffffff);
graphics.drawString(this.font, Component.translatable("sodium.console.config_corrupt.title"), 32, 48, 0xff0000);

for (int i = 0; i < TEXT_BODY.size(); i++) {
if (TEXT_BODY.get(i).getString().isEmpty()) {
Expand Down
19 changes: 19 additions & 0 deletions src/main/resources/assets/sodium/lang/en_us.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"sodium.name_renderer": "Sodium Renderer",
"sodium.name_renderer.settings": "Sodium Renderer Settings",
"sodium.option_impact.low": "Low",
"sodium.option_impact.medium": "Medium",
"sodium.option_impact.high": "High",
Expand Down Expand Up @@ -47,6 +49,7 @@
"sodium.options.use_persistent_mapping.tooltip": "For debugging only. If enabled, persistent memory mappings will be used for the staging buffer so that unnecessary memory copies can be avoided. Disabling this can be useful for narrowing down the cause of graphical corruption.\n\nRequires OpenGL 4.4 or ARB_buffer_storage.",
"sodium.options.chunk_update_threads.name": "Chunk Update Threads",
"sodium.options.chunk_update_threads.tooltip": "Specifies the number of threads to use for chunk building and sorting. Using more threads can speed up chunk loading and update speed, but may negatively impact frame times. The default value is usually good enough for all situations.",
"sodium.options.chunk_update_threads.value": "threads",
"sodium.options.always_defer_chunk_updates.name": "Always Defer Chunk Updates",
"sodium.options.always_defer_chunk_updates.tooltip": "If enabled, rendering will never wait for chunk updates to finish, even if they are important. This can greatly improve frame rates in some scenarios, but it may create significant visual lag where blocks take a while to appear or disappear.",
"sodium.options.sort_behavior.name": "Translucency Sorting",
Expand All @@ -56,12 +59,28 @@
"sodium.options.buttons.undo": "Undo",
"sodium.options.buttons.apply": "Apply",
"sodium.options.buttons.donate": "Buy us a coffee!",
"sodium.prompt.donate.contents.main": "Hello!\n\nIt seems that you've been enjoying %s, the free and open-source optimization mod for Minecraft.\n\nMods like these are complex. They require %s of development, debugging, and tuning to create the experience that players have come to expect.\n\nIf you'd like to show your token of appreciation, and support the development of our mod in the process, then consider %s.\n\nAnd thanks again for using our mod! We hope it helps you (and your computer.)",
"sodium.prompt.donate.contents.segment.1": "Sodium",
"sodium.prompt.donate.contents.segment.2": "thousands of hours",
"sodium.prompt.donate.contents.segment.3": "buying us a coffee",
"sodium.prompt.donate.action": "Buy us a coffee",
Copy link
Contributor Author

@Madis0 Madis0 Jan 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Intentionally separate string from ln 59 because the prompt action can be different from the static button (#2008)

"sodium.console.game_restart": "The game must be restarted to apply one or more video settings!",
"sodium.console.broken_nvidia_driver": "Your NVIDIA graphics drivers are out of date!\n * This will cause severe performance issues and crashes when Sodium is installed.\n * Please update your graphics drivers to the latest version (version 536.23 or newer.)",
"sodium.console.pojav_launcher": "PojavLauncher is not supported when using Sodium.\n * You are very likely to run into extreme performance issues, graphical bugs, and crashes.\n * You will be on your own if you decide to continue -- we will not help you with any bugs or crashes!",
"sodium.console.core_shaders_error": "The following resource packs are incompatible with Sodium:",
"sodium.console.core_shaders_warn": "The following resource packs may be incompatible with Sodium:",
"sodium.console.core_shaders_info": "Check the game log for detailed information.",
"sodium.console.config_corrupt.title": "Could not load the configuration file",
"sodium.console.config_corrupt.short": "Sodium failed to load the configuration file",
"sodium.console.config_corrupt.contents.1": "A problem occurred while trying to load the configuration file. This",
"sodium.console.config_corrupt.contents.2": "can happen when the file has been corrupted on disk, or when trying",
"sodium.console.config_corrupt.contents.3": "to manually edit the file by hand.",
"sodium.console.config_corrupt.contents.4": "",
"sodium.console.config_corrupt.contents.5": "If you continue, the configuration file will be reset back to known-good",
"sodium.console.config_corrupt.contents.6": "defaults, and you will lose any changes that have since been made to your",
"sodium.console.config_corrupt.contents.7": "Video Settings.",
"sodium.console.config_corrupt.contents.8": "",
"sodium.console.config_corrupt.contents.9": "More information about the error can be found in the log file.",
"sodium.console.config_not_loaded": "The configuration file for Sodium has been corrupted, or is currently unreadable. Some options have been temporarily reset to their defaults. Please open the Video Settings screen to resolve this problem.",
"sodium.console.config_file_was_reset": "The config file has been reset to known-good defaults."
}
Loading