Skip to content

Instantly share code, notes, and snippets.

@ottosch
Last active January 10, 2019 23:49
Show Gist options
  • Save ottosch/03e32240b33ddd420e9947699c2c71da to your computer and use it in GitHub Desktop.
Save ottosch/03e32240b33ddd420e9947699c2c71da to your computer and use it in GitHub Desktop.
#!/usr/bin/python
# Will print which language strings exist in the English file, but not in other languages.
# Usage: Place the script in the project root and run "python samourai-strings.py LANGUAGE".
# For example, Spanish would be "python samourai-strings.py es".
# Version 0.2
import sys
import os
import xml.etree.ElementTree as ET
if len(sys.argv) == 1:
print("Usage: python " + sys.argv[0] + " LANGUAGE\n")
sys.exit(1)
lang = sys.argv[1].lower()
res_dir = "./app/src/main/res/"
try:
tree = ET.parse(res_dir + "values/strings.xml")
except FileNotFoundError:
print("File strings.xml not found. Please make sure you're in project root.\nThere should be an 'app' directory in it.")
sys.exit(1)
str_elements = tree.getroot().findall("string")
print("Language: " + lang)
strings_en = [ s.get("name") for s in str_elements ]
for root, dirs, files in os.walk(res_dir):
if ("values-" + lang) not in root.lower() or "strings.xml" not in files:
continue
str_file = root + "/strings.xml"
tree = ET.parse(str_file)
str_elements = tree.getroot().findall("string")
strings = [ s.get("name") for s in str_elements ]
diff = [ s for s in strings_en if s not in strings ]
print("\n".join(diff))
print("\n\nMissing " + str(len(diff)) + " strings\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment