Skip to content

Commit

Permalink
translate for pre language
Browse files Browse the repository at this point in the history
  • Loading branch information
cubewhy committed Jan 17, 2024
1 parent 0d217f4 commit 43d15c5
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 7 deletions.
31 changes: 31 additions & 0 deletions src/main/java/org/cubewhy/celestial/gui/Language.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Celestial Launcher <me@lunarclient.top>
* License under GPLv3
* Do NOT remove this note if you want to copy this file.
*/

package org.cubewhy.celestial.gui;

import lombok.Getter;

@Getter
public enum Language {
ENGLISH("English", "en"),
CHINESE("简体中文", "zh"),
JAPANESE("日本語", "ja"),
KOREAN("한국인", "ko");

private final String view;
private final String code;

Language(String view, String code) {
this.view = view;
this.code = code;
}


@Override
public String toString() {
return this.code;
}
}
22 changes: 15 additions & 7 deletions src/main/java/org/cubewhy/celestial/gui/pages/GuiSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.apache.commons.io.FileUtils;
import org.cubewhy.celestial.game.addon.LunarCNMod;
import org.cubewhy.celestial.game.addon.WeaveMod;
import org.cubewhy.celestial.gui.Language;
import org.cubewhy.celestial.gui.dialogs.ArgsConfigDialog;
import org.cubewhy.celestial.gui.layouts.VerticalFlowLayout;
import org.cubewhy.celestial.utils.GuiUtils;
Expand Down Expand Up @@ -170,7 +171,7 @@ private void initGui() {
// language
JPanel p6 = new JPanel();
p6.add(new JLabel(f.getString("gui.settings.launcher.language")));
p6.add(getAutoSaveComboBox(config.getConfig(), "language", List.of(new String[]{"zh", "en", "ja", "ko"})));
p6.add(getAutoSaveComboBox(config.getConfig(), "language", List.of((Language[]) Language.values())));
panelLauncher.add(p6);
// max threads
JPanel p7 = new JPanel();
Expand Down Expand Up @@ -388,15 +389,22 @@ private void addUnclaimed(JPanel basePanel, @NotNull JsonObject json) {
}
}

private @NotNull JComboBox<String> getAutoSaveComboBox(JsonObject json, String key, @NotNull List<String> items) {
JComboBox<String> cb = new JComboBox<>();
for (String item : items) {
cb.addItem(item);
private @NotNull JComboBox<?> getAutoSaveComboBox(JsonObject json, String key, @NotNull List<?> items) {
JComboBox<Object> cb = new JComboBox<>();
for (Object item : items) {
if (item instanceof Language) {
cb.addItem(((Language) item).getView() + "/" + ((Language) item).getCode());
} else {
cb.addItem(item);
}
}
cb.setSelectedItem(json.get(key).getAsString());
cb.addActionListener((e) -> {
JComboBox<String> source = (JComboBox<String>) e.getSource();
String v = (String) source.getSelectedItem();
JComboBox<Object> source = (JComboBox<Object>) e.getSource();
if (source.getSelectedItem() == null) {
return;
}
String v = source.getSelectedItem().toString();
json.addProperty(key, v);
config.save();
});
Expand Down

0 comments on commit 43d15c5

Please sign in to comment.