Skip to content

Instantly share code, notes, and snippets.

@Towdium
Last active October 13, 2019 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Towdium/df93458ea954855ac1b07186c580754f to your computer and use it in GitHub Desktop.
Save Towdium/df93458ea954855ac1b07186c580754f to your computer and use it in GitHub Desktop.
Convert Minecraft language file from properties to JSON format
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