Skip to content

Commit b4b5a3f

Browse files
RobPasMuelwasser
authored andcommitted
docs: adding translation stats to docs
1 parent c487789 commit b4b5a3f

File tree

4 files changed

+81
-0
lines changed

4 files changed

+81
-0
lines changed

TRANSLATING.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ This guide will help you get started contributing to the translation of the Pyth
88

99
The process of contributing to the translation of the guide is similar to the process of contributing to the guide itself, except that instead of working on the guide source files directly, you will be working on the translation files.
1010

11+
# Translation Status
12+
13+
```{translation-graph}
14+
```
15+
1116
## Overview of the Translation Process
1217

1318
The process of adapting software to different languages is called internationalization, or i18n for short. Internationalization makes sure that translation can happen without having to modify the source code, or in our case, the original English source files of the guide.

_ext/translation_graph.py

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
from pathlib import Path
2+
import json
3+
4+
from docutils import nodes
5+
from docutils.parsers.rst import Directive
6+
import plotly.graph_objects as go
7+
from plotly.offline import plot
8+
9+
class TranslationGraph(Directive):
10+
# Tells Sphinx that this directive can be used in the document body
11+
# and has no content
12+
has_content = False
13+
14+
def run(self):
15+
# Read the JSON file containing translation statistics
16+
json_path = Path(__file__).parent.parent / '_static' / 'translation_stats.json'
17+
with json_path.open('r') as f:
18+
data = json.load(f)
19+
20+
# Collect all module names -- iterates over the JSON data in 2 levels
21+
all_modules = {module for stats in data.values() for module in stats}
22+
all_modules = sorted(all_modules)
23+
24+
# Build one trace per locale with full hover info
25+
traces = []
26+
27+
for locale, modules in data.items():
28+
y_vals = []
29+
hover_texts = []
30+
31+
for module in all_modules:
32+
stats = modules.get(module)
33+
y_vals.append(stats["percentage"])
34+
35+
hover_text = (
36+
f"<b>{module}</b><br>"
37+
f"Translated: {stats['translated']}<br>"
38+
f"Fuzzy: {stats['fuzzy']}<br>"
39+
f"Untranslated: {stats['untranslated']}<br>"
40+
f"Total: {stats['total']}<br>"
41+
f"Completed: {stats['percentage']}%"
42+
)
43+
hover_texts.append(hover_text)
44+
45+
traces.append(go.Bar(
46+
name=locale,
47+
x=all_modules,
48+
y=y_vals,
49+
hovertext=hover_texts,
50+
hoverinfo="text"
51+
))
52+
53+
# Create figure
54+
fig = go.Figure(data=traces)
55+
fig.update_layout(
56+
barmode='group',
57+
title="Translation Coverage by Module and Locale",
58+
xaxis_title="Module",
59+
yaxis_title="Percentage Translated",
60+
height=600,
61+
margin=dict(l=40, r=40, t=40, b=40)
62+
)
63+
64+
div = plot(fig, output_type='div', include_plotlyjs=True)
65+
return [nodes.raw('', div, format='html')]
66+
67+
def setup(app):
68+
app.add_directive("translation-graph", TranslationGraph)
69+
return {
70+
"version": "0.1",
71+
"parallel_read_safe": True,
72+
"parallel_write_safe": True,
73+
}

conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
"sphinxext.opengraph",
8484
"sphinx_favicon",
8585
"sphinxcontrib.bibtex",
86+
'_ext.translation_graph',
8687
]
8788

8889
# colon fence for card support in md

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ dependencies = [
2222
"sphinx-inline-tabs",
2323
# for project cards
2424
"matplotlib",
25+
# for translation graphs
26+
"plotly",
2527
# for license page bibliography
2628
"sphinxcontrib-bibtex",
2729
]

0 commit comments

Comments
 (0)