Skip to content

enh: create a graphic or visual that helps us visualize % translated for each section of the guide by language #493

Open
@lwasser

Description

@lwasser

One of the benefits of using a tool like crowin is the bar plots that quickly help a user understand how far along translations are in a specific language.

We can generate a graphic like this using Python and post it in our translation file and README file for a quick overview of the translation status. Below is a somewhat ugly, messy version of this using Babel. But it starts to get at what i'm thinking about!

If someone is interested in a python project, you could work on this and

  • Turn it into a runnable script with a main() function.
  • Fix the plots to make them look nicer using perhaps a different plotting tool
  • Create subplots one for each language
  • Save the plot in the repository directory so we can then add it to our README and other files.
  • Document everything!

from pathlib import Path
import os
from babel.messages import pofile
import matplotlib.pyplot as plt

# Path to your locales directory
# Go up one directory and locate the locales folder (i'm thinking this will live in a /scripts directory at the root of the repo
BASE_DIR = Path(__file__).resolve().parent.parent
LOCALES_DIR = BASE_DIR / "locales"
print(LOCALES_DIR)

def calculate_translation_percentage(po_path):
    with open(po_path, "r", encoding="utf-8") as f:
        catalog = pofile.read_po(f)
    total = len(catalog)
    translated = sum(1 for message in catalog if message.string)
    percent = (translated / total * 100) if total > 0 else 0
    return round(percent, 1)

def get_translation_progress(locales_dir):
    progress = {}
    for lang_dir in locales_dir.iterdir():
        # skip os stuff like .DS_Store
        if not lang_dir.is_dir():
            continue  #

        lang = lang_dir.name
        lc_messages_dir = lang_dir / "LC_MESSAGES"
        if not lc_messages_dir.exists():
            continue

        po_files = lc_messages_dir.glob("*.po")

        for po_file in po_files:
            percent = calculate_translation_percentage(po_file)
            key = f"{lang}/{po_file.stem}"
            progress[key] = percent

    return progress


# Get progress data and plot
progress = get_translation_progress(LOCALES_DIR)
print(progress)

langs = list(progress.keys())
percents = list(progress.values())
print(percents)

plt.figure(figsize=(10, 6))
plt.barh(langs, percents)
plt.xlabel("Translation %")
plt.title("Translation progress by language")
plt.xlim(0, 100)
plt.grid(axis="x", linestyle="--", alpha=0.5)
plt.tight_layout()
plt.show()

The follow-up issue associated with this would be to add CI to run this automatically each week. I think that can be a sub-issue that we can make once this issue is complete!

Metadata

Metadata

Assignees

Labels

help wantedWe welcome a contributor to work on this issue! thank you in advance!sprintable

Type

No type

Projects

Status

python programming

Status

pyconus-25

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions