-
Notifications
You must be signed in to change notification settings - Fork 62
docs: adding translation stats to docs #511
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
lwasser
merged 13 commits into
pyOpenSci:main
from
RobPasMue:feat/translation-graph-render
Jun 17, 2025
Merged
Changes from 3 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
e018c21
docs: adding translation stats to docs
RobPasMue f2ce21d
Update _ext/translation_graph.py
RobPasMue a3567ca
chore: change single quotes for double quotes
RobPasMue 3dfe760
Merge branch 'main' into feat/translation-graph-render
tkoyama010 b3e26d8
Update _ext/translation_graph.py
RobPasMue 0429129
Merge branch 'main' into feat/translation-graph-render
RobPasMue 11bd218
Apply suggestions from code review
RobPasMue 1c5f63a
feat: adding @sneakers-the-rat suggestions
RobPasMue 5681b0b
feat: adding heatmap style colors, percentage and sorting
RobPasMue 0b8720f
Update _ext/translation_graph.py
RobPasMue 81f7cb0
feat: increasing number size
RobPasMue 005a4dc
Merge branch 'main' into feat/translation-graph-render
RobPasMue 43582fb
feat: CSS enhancements
RobPasMue File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
from pathlib import Path | ||
import json | ||
|
||
from docutils import nodes | ||
from docutils.parsers.rst import Directive | ||
import plotly.graph_objects as go | ||
from plotly.offline import plot | ||
|
||
RobPasMue marked this conversation as resolved.
Show resolved
Hide resolved
|
||
class TranslationGraph(Directive): | ||
# Tells Sphinx that this directive can be used in the document body | ||
# and has no content | ||
has_content = False | ||
|
||
def run(self): | ||
# Read the JSON file containing translation statistics | ||
json_path = Path(__file__).parent.parent / "_static" / "translation_stats.json" | ||
RobPasMue marked this conversation as resolved.
Show resolved
Hide resolved
|
||
with json_path.open("r") as f: | ||
data = json.load(f) | ||
RobPasMue marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# Collect all module names -- iterates over the JSON data in 2 levels | ||
all_modules = {module for stats in data.values() for module in stats} | ||
all_modules = sorted(all_modules) | ||
|
||
# Build one trace per locale with full hover info | ||
traces = [] | ||
|
||
for locale, modules in data.items(): | ||
y_vals = [] | ||
hover_texts = [] | ||
|
||
for module in all_modules: | ||
stats = modules.get(module) | ||
y_vals.append(stats["percentage"]) | ||
|
||
hover_text = ( | ||
f"<b>{module}</b><br>" | ||
f"Translated: {stats['translated']}<br>" | ||
f"Fuzzy: {stats['fuzzy']}<br>" | ||
f"Untranslated: {stats['untranslated']}<br>" | ||
f"Total: {stats['total']}<br>" | ||
f"Completed: {stats['percentage']}%" | ||
) | ||
hover_texts.append(hover_text) | ||
|
||
traces.append(go.Bar( | ||
name=locale, | ||
x=all_modules, | ||
y=y_vals, | ||
hovertext=hover_texts, | ||
hoverinfo="text" | ||
)) | ||
|
||
# Create figure | ||
fig = go.Figure(data=traces) | ||
RobPasMue marked this conversation as resolved.
Show resolved
Hide resolved
|
||
fig.update_layout( | ||
RobPasMue marked this conversation as resolved.
Show resolved
Hide resolved
|
||
barmode="group", | ||
title="Translation Coverage by Module and Locale", | ||
xaxis_title="Module", | ||
yaxis_title="Percentage Translated", | ||
height=600, | ||
margin=dict(l=40, r=40, t=40, b=40) | ||
) | ||
|
||
div = plot(fig, output_type="div", include_plotlyjs=True) | ||
return [nodes.raw("", div, format="html")] | ||
RobPasMue marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
def setup(app): | ||
app.add_directive("translation-graph", TranslationGraph) | ||
return { | ||
"version": "0.1", | ||
"parallel_read_safe": True, | ||
"parallel_write_safe": True, | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe here would be a good spot to include the link to the site
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems like we would want both directions? from the contributing page here and vice versa?