Last active
October 13, 2019 14:11
-
-
Save Towdium/df93458ea954855ac1b07186c580754f to your computer and use it in GitHub Desktop.
Convert Minecraft language file from properties to JSON format
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import codecs | |
usage = ''' | |
Usage: python lang2json.py some.lang | |
Python 3 please | |
''' | |
def convert(file): | |
assert file.endswith(".lang") | |
output = "{\n" | |
with codecs.open(file, 'r', 'utf-8') as f: | |
for line in f: | |
if not line.startswith('#') and '=' in line: | |
words = line[:-1].split('=') | |
output += ' ' + '"{:s}": "{:s}",\n'.format(words[0], words[1].replace('"', '\\"')) | |
output += '}\n' | |
with codecs.open(file[:-5] + '.json', 'w', 'utf-8') as f: | |
f.write(output) | |
if __name__ == '__main__': | |
if len(sys.argv) == 1: | |
print(usage) | |
elif len(sys.argv) == 2: | |
convert(sys.argv[1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment