INNER CODE UNIT · Python

count_strings

emanuele-f/PCAPdroid · tools/weblate.py:92

def count_strings(content, translatable_only=False):
    """Count <string name= entries in an Android strings XML."""
    if translatable_only:
        return len(re.findall(r'<string name="[^"]*"(?![^>]*translatable="false")', content))
    return len(re.findall(r'<string name="', content))

def translation_pct(locale):
    """Return translation percentage string for a locale on weblate/master."""
    en_path = f"{STRINGS_BASE}/values/strings.xml"
    path = locale_path(locale)
    en_content = git("show", f"{REMOTE}/master:{en_path}").stdout
    locale_result = git("show", f"{REMOTE}/master:{path}", check=False)
    if locale_result.returncode != 0:
        return "0%"
    total = count_strings(en_content, translatable_only=True)
    if total == 0:
        return "0%"
    translated = count_strings(locale_result.stdout)

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…