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

Create i18n enums for better localized string validation. #895

Merged
merged 1 commit into from
Apr 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
16 changes: 10 additions & 6 deletions src/main/java/net/glowstone/GlowPluginTypeDetector.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package net.glowstone;

import static net.glowstone.LocalizedStrings.logInfo;

import com.google.common.io.PatternFilenameFilter;
import java.io.File;
import java.io.IOException;
Expand All @@ -13,6 +11,7 @@
import java.util.logging.Level;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import net.glowstone.i18n.LocalizedStrings;
import org.objectweb.asm.AnnotationVisitor;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassVisitor;
Expand All @@ -37,7 +36,7 @@ public GlowPluginTypeDetector(File directory) {
* Scans all jars in the plugin directory for their types.
*/
public void scan() {
LocalizedStrings.logInfo("console.info.plugin.scanning");
LocalizedStrings.Console.Info.Plugin.SCANNING.log();
File[] files = directory.listFiles(new PatternFilenameFilter(".+\\.jar"));
if (files == null || files.length == 0) {
return;
Expand All @@ -47,9 +46,14 @@ public void scan() {
scanFile(file);
}

logInfo("console.info.plugin.counts", bukkitPlugins.size(),
spongePlugins.size(), forgefPlugins.size() + forgenPlugins.size(),
canaryPlugins.size(), unrecognizedPlugins.size(), files.length);
LocalizedStrings.Console.Info.Plugin.COUNTS.log(
bukkitPlugins.size(),
spongePlugins.size(),
forgefPlugins.size() + forgenPlugins.size(),
canaryPlugins.size(),
unrecognizedPlugins.size(),
files.length
);

if (!unrecognizedPlugins.isEmpty()) {
for (File file : unrecognizedPlugins) {
Expand Down
197 changes: 86 additions & 111 deletions src/main/java/net/glowstone/GlowServer.java

Large diffs are not rendered by default.

69 changes: 0 additions & 69 deletions src/main/java/net/glowstone/LocalizedStrings.java

This file was deleted.

4 changes: 2 additions & 2 deletions src/main/java/net/glowstone/constants/GlowBiome.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
import static org.bukkit.block.Biome.values;

import java.util.Arrays;
import net.glowstone.LocalizedStrings;
import net.glowstone.i18n.LocalizedStrings;
import org.bukkit.block.Biome;

/**
Expand Down Expand Up @@ -168,7 +168,7 @@ public static Biome getBiome(int id) {
if (id < biomes.length) {
return biomes[id];
} else {
LocalizedStrings.logError("console.error.biome.unknown", id);
LocalizedStrings.Console.Error.Biome.UNKNOWN.log(id);
return null;
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/net/glowstone/i18n/LocalizedString.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package net.glowstone.i18n;

public interface LocalizedString {
String get();

String get(Object... args);
}
35 changes: 35 additions & 0 deletions src/main/java/net/glowstone/i18n/LocalizedStringImpl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package net.glowstone.i18n;

import java.text.MessageFormat;
import java.util.ResourceBundle;
import lombok.Getter;

class LocalizedStringImpl implements LocalizedString {
private static final ResourceBundle STRINGS = ResourceBundle.getBundle("strings");

@Getter
private final String key;

private final ResourceBundle resourceBundle;

LocalizedStringImpl(String key) {
this.key = key;
this.resourceBundle = STRINGS;
}

LocalizedStringImpl(String key, ResourceBundle resourceBundle) {
this.key = key;
this.resourceBundle = resourceBundle;
}

@Override
public String get() {
return resourceBundle.getString(getKey());
}

@Override
public String get(Object... args) {
return MessageFormat.format(get(), args);
}

}
Loading