Skip to content

Instantly share code, notes, and snippets.

@spotco
Last active May 31, 2017 21:14
Show Gist options
  • Select an option

  • Save spotco/85bd8ca0f0a738ee3613f9f36a07f122 to your computer and use it in GitHub Desktop.

Select an option

Save spotco/85bd8ca0f0a738ee3613f9f36a07f122 to your computer and use it in GitHub Desktop.
import sys
import json
import io
def use_i_token(i_token, i_token_to_key):
key = i_token_to_key[i_token]
return key == "en-US" or key == "fr" or key == "de" or key == "it" or key == "ja" or key == "pt-BR" or key == "ru" or key == "es"
i_line = 0
i_token_to_key = {}
js_out = []
for line in open(sys.argv[1],'r').read().split("\n"):
itr_token = {}
line_key = ""
i_token = 0
for token in line.split("\t"):
if i_line == 0:
i_token_to_key[i_token] = token
elif i_token == 0:
line_key = token
else:
if use_i_token(i_token, i_token_to_key) and len(token) > 0:
itr_token[i_token_to_key[i_token]] = token
i_token = i_token + 1
if len(itr_token) > 1:
js_out.append({
"key": line_key,
"values": itr_token
})
i_line = i_line + 1
print json.dumps(js_out, ensure_ascii=False, encoding='utf8',indent=4).encode('utf-8')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment