INNER CODE UNIT · Python

locale_exists_on_disk

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

def locale_exists_on_disk(locale):
    return os.path.isdir(os.path.join(STRINGS_BASE, f"values-{locale}"))

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)

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…