Skip to content
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

Allow marking translations reviewed #392

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions mkdocs-utils/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ def get_automated_translation_content(docs_dir: str) -> str:
content = _get_warning_file_content(docs_dir, MACHINE_TRANSLATION_FILENAME)
return content.replace('__ISSUE_URL__', _get_issue_url_for_translation_commitment())

def _get_absolute_reviewed_translation_files(reviewed_translation_files: List[str]) -> List[str]:
if not reviewed_translation_files:
return []
return list(map(lambda f: str(Path(f).resolve(True)), reviewed_translation_files))

class EnFile(File):
pass
Expand Down Expand Up @@ -88,6 +92,10 @@ def get_images_relative_paths(docs_dir: str) -> List[str]:
images = glob.glob(f"{en_docs_path}/images/**/*", recursive=True)
return list(map(lambda i: str(Path(i).relative_to(en_docs_path)), images))

def on_config(config: MkDocsConfig, **_: Any) -> MkDocsConfig:
config.extra['reviewed_translation_files'] = _get_absolute_reviewed_translation_files(config.extra.get("reviewed_translation_files", []))
return config

def on_files(files: Files, *, config: MkDocsConfig) -> Files:

# We circumvent the fact that the config.nav object is not available anymore
Expand Down Expand Up @@ -123,10 +131,14 @@ def _inject_warning(markdown: str, warning: str, page: Page):
def on_page_markdown(
markdown: str, *, page: Page, config: MkDocsConfig, **_: Any
) -> str:
docs_dir=Path(config.docs_dir)
docs_dir = Path(config.docs_dir)
reviewed_translation_files = config.extra['reviewed_translation_files']

if page.file.src_path == "telemetry.md":
print("telemetry.md: ", page.file.abs_src_path, reviewed_translation_files)

if isinstance(page.file, EnFile):
return _inject_warning(markdown=markdown, page=page, warning=get_missing_translation_content(config.docs_dir))
elif docs_dir.parent.name != 'en' and (docs_dir.parent / MACHINE_TRANSLATION_FILENAME).exists():
elif docs_dir.parent.name != 'en' and (docs_dir.parent / MACHINE_TRANSLATION_FILENAME).exists() and page.file.abs_src_path not in reviewed_translation_files:
return _inject_warning(markdown=markdown, page=page, warning=get_automated_translation_content(config.docs_dir))

return markdown
Loading