Skip to content

Instantly share code, notes, and snippets.

@corcoran
Created July 13, 2017 16:40
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 corcoran/9f620d4a190f0889976cbf7a0160ec79 to your computer and use it in GitHub Desktop.
Save corcoran/9f620d4a190f0889976cbf7a0160ec79 to your computer and use it in GitHub Desktop.
CrowdIn translations Android helper
#!/usr/bin/env python
import os
import shutil
import zipfile
# Fully translated only
translation_mapping = {
'cs': 'cs',
'de': 'de',
'fr': 'fr',
'hi': 'hi-rIN',
'hu': 'hu',
'it': 'it',
'ja': 'ja',
'nl': 'nl',
'pl': 'pl',
'pt-BR': 'pt',
'ro': 'ro',
'ru': 'ru',
'sk': 'sk',
'tr': 'tr',
'uk': 'uk',
'zh-CN': 'zh-rCN'
}
zip_file = "/home/jeff/Downloads/xda-feed.zip"
tmp_dir = "/tmp/feed_translations"
dst_dir = "/home/jeff/Android/Feed/app/src/main/res"
str_file = "strings.xml"
if __name__ == "__main__":
zip_ref = zipfile.ZipFile(zip_file, 'r')
zip_ref.extractall(tmp_dir)
zip_ref.close()
for l in sorted(translation_mapping.keys()):
dest_path = '%s/values-%s' % (dst_dir, translation_mapping[l])
if not os.path.exists(dest_path):
os.mkdir(dest_path)
shutil.copy('%s/%s/%s' % (tmp_dir, l, str_file), '%s/%s' % (dest_path,
str_file))
print("Copied new values-%s/%s" % (translation_mapping[l], str_file))
shutil.rmtree(tmp_dir, True)
os.unlink(zip_file)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment