Skip to content

Instantly share code, notes, and snippets.

@rouuuge
Forked from JEuler/string2json.py
Created April 29, 2021 08:04
Show Gist options
  • Save rouuuge/bd2fa6e71d58bc06174f9d5b6e76a58e to your computer and use it in GitHub Desktop.
Save rouuuge/bd2fa6e71d58bc06174f9d5b6e76a58e to your computer and use it in GitHub Desktop.
import json
import io
from xml.dom import minidom
xmldoc = minidom.parse('values-ru/strings.xml')
itemlist = xmldoc.getElementsByTagName('string')
with io.open('app_ru.arb', 'w', encoding='utf8') as out_file:
out_file.write('{'.decode('utf-8'))
for s in itemlist:
if (s.firstChild != None):
out_file.write('"'.decode('utf-8'))
out_file.write(s.getAttribute("name").decode('utf-8'))
out_file.write('"'.decode('utf-8'))
out_file.write(": ".decode('utf-8'))
out_file.write('"'.decode('utf-8'))
out_file.write(s.firstChild.data.encode('utf-8').decode('utf-8'))
out_file.write('"'.decode('utf-8'))
out_file.write(','.decode('utf-8'))
out_file.write('\n'.decode('utf-8'))
else:
out_file.write(''.decode('utf-8'))
out_file.write('}'.decode('utf-8'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment