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

Translation support #6

Merged
merged 7 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
Expand All @@ -48,7 +49,9 @@

@SuppressWarnings("unused")
public class InstallerPanel extends JPanel {
public static final L10nManager TRANSLATIONS = new L10nManager("neoforged/installer", new File(SimpleInstaller.getMCDir(), "libraries/.neoforge_installer.properties"));
private static final Path INSTALLER_SETTINGS = new File(SimpleInstaller.getMCDir(), "libraries/.neoforge_installer.properties").toPath();
Matyrobbrt marked this conversation as resolved.
Show resolved Hide resolved
public static final L10nManager TRANSLATIONS = new L10nManager("neoforged/installer", INSTALLER_SETTINGS);

private static final long serialVersionUID = 1L;
private File targetDir;
private ButtonGroup choiceButtonGroup;
Expand Down
22 changes: 14 additions & 8 deletions src/main/java/net/minecraftforge/installer/ui/L10nManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
import java.util.Set;

public class L10nManager {
public static final ResourceBundle.Control CONTROL = new ResourceBundle.Control() {
private static final ResourceBundle.Control CONTROL = new ResourceBundle.Control() {
@Override
public ResourceBundle newBundle(String baseName, Locale locale, String format, ClassLoader loader, boolean reload) throws IllegalAccessException, InstantiationException, IOException {
if (format.equals("java.class")) {
Expand All @@ -61,9 +61,12 @@ public ResourceBundle newBundle(String baseName, Locale locale, String format, C
throw new IllegalArgumentException("unknown format: " + format);
}

// Copied from the javadocs of ResourceBundle.Control
final String bundleName = toBundleName(baseName, locale);

if (bundleName.contains("://")) return null;
if (bundleName.contains("://")) {
return null;
}
final String resourceName = toResourceName(bundleName, "xml");

InputStream is = null;
Expand All @@ -82,7 +85,10 @@ public ResourceBundle newBundle(String baseName, Locale locale, String format, C
is = loader.getResourceAsStream(resourceName);
}

if (is == null) return null;
if (is == null) {
return null;
}

try (final InputStream i = is) {
final Properties props = new Properties();
props.loadFromXML(i);
Expand Down Expand Up @@ -117,13 +123,13 @@ protected Set<String> handleKeySet() {
private final Path settingsFile;
private final List<LocaleSelection> known;

public L10nManager(String bundleName, File settingsFileIn) {
public L10nManager(String bundleName, Path settingsFile) {
this.bundleName = bundleName;
this.settingsFile = settingsFileIn.toPath();
this.settingsFile = settingsFile;
this.known = Collections.unmodifiableList(computeKnownLocales());

if (Files.exists(settingsFile)) {
try (final InputStream is = Files.newInputStream(settingsFile)) {
if (Files.exists(this.settingsFile)) {
try (final InputStream is = Files.newInputStream(this.settingsFile)) {
final Properties props = new Properties();
props.load(is);
final String lang = props.getProperty("language");
Expand Down Expand Up @@ -265,7 +271,7 @@ public String toString() {
}
}

public static final class MergedEnumeration implements Enumeration<String> {
private static final class MergedEnumeration implements Enumeration<String> {

private final Set<String> set;
private final Iterator<String> iterator;
Expand Down