Skip to content

Instantly share code, notes, and snippets.

@nguyentruongtho
Created December 16, 2014 04:03
Show Gist options
  • Save nguyentruongtho/a1e9dcca2e2ef6ee7e35 to your computer and use it in GitHub Desktop.
Save nguyentruongtho/a1e9dcca2e2ef6ee7e35 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import re
import sys
from os import listdir
from os.path import isfile, join, basename, normpath
def usage():
print """
usage: remove_non_translatable <path/to/values-xxx/folder>
"""
if len(sys.argv) <= 1:
usage()
exit(0)
mypath = sys.argv[1]
if not basename(normpath(mypath)).startswith("values-"):
print "Target folder must start with \"values-\""
exit(0)
files = [ f for f in listdir(mypath) if isfile(join(mypath, f)) and f.endswith(".xml") ]
for translateFile in files:
print "Processing %s" % (translateFile)
filePath = join(mypath, translateFile)
sourceWithOutTranslatable = None
with open(filePath, "r") as f:
sourceWithOutTranslatable = "".join([line for line in f.readlines() if "translatable=\"false\"" not in line])
if sourceWithOutTranslatable:
with open(filePath, "w") as f:
f.write(sourceWithOutTranslatable)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment