Skip to content

Instantly share code, notes, and snippets.

@tterrag1098
Last active January 14, 2018 08:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tterrag1098/b0f98649380cde794594fc9a153288ba to your computer and use it in GitHub Desktop.
Save tterrag1098/b0f98649380cde794594fc9a153288ba to your computer and use it in GitHub Desktop.
{
"item.chisel.chisel_iron.name": "Chisel",
"item.chisel.chisel_diamond.name": "Diamond Chisel",
"item.chisel.chisel_hitech.name": "iChisel",
"item.chisel.offsettool.name": "Ender Offset Wand",
"__comment": "Test comment!",
"item.chisel.chisel.desc.gui": "%sRight-click%s to open GUI",
"item.chisel.chisel.desc.lc1": "%sLeft-click%s to chisel blocks in the world",
"item.chisel.chisel.desc.lc2": "%sTarget a block%s by leaving it in the inventory"
}
item.chisel.chisel_iron.name=Chisel
item.chisel.chisel_diamond.name=Diamond Chisel
item.chisel.chisel_hitech.name=iChisel
item.chisel.offsettool.name=Ender Offset Wand
# Test comment!
invalid line
item.chisel.chisel.desc.gui=%sRight-click%s to open GUI
item.chisel.chisel.desc.lc1=%sLeft-click%s to chisel blocks in the world
item.chisel.chisel.desc.lc2=%sTarget a block%s by leaving it in the inventory
package chisel.scripts;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.io.FileUtils;
import com.google.common.base.Charsets;
import com.google.gson.stream.JsonWriter;
public class Lang2Json {
public static void main(String[] args) throws IOException {
File file = new File(args[0]);
File outfile = new File(args[0].replace(".lang", ".json"));
Pattern MAPPING_PATTERN = Pattern.compile("^(\\S+)=(.+)$");
try (JsonWriter out = new JsonWriter(new FileWriter(outfile))) {
out.setIndent(" ");
out.beginObject();
for (String s : FileUtils.readLines(file, Charsets.UTF_8)) {
s = s.trim();
if (s.startsWith("#")) {
out.name("__comment").value(s.substring(1).trim());
} else {
Matcher m = MAPPING_PATTERN.matcher(s);
if (m.matches()) {
out.name(m.group(1)).value(m.group(2));
}
}
}
out.endObject();
}
}
}
@elifoster
Copy link

line 29 should be } else if (!s.isEmpty()) {, no?

@tterrag1098
Copy link
Author

Actually it's not needed at all. I had already changed it locally just forgot to update this :P

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment