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

Add test for internationalization and translations #1138

Merged
merged 1 commit into from
Feb 6, 2023
Merged
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
59 changes: 59 additions & 0 deletions tests/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -787,3 +787,62 @@ def test_empty_templates(sphinx_build_factory):
sphinx_build = sphinx_build_factory("base", confoverrides=confoverrides).build()
toc_items = sphinx_build.html_tree("page1.html").select(".toc-item")
assert not any(ii.select(".tocsection.sourcelink") for ii in toc_items)


def test_translations(sphinx_build_factory):
"""Test that basic translation functionality works.

This will build our test site with the French language, and test
that a few phrases are in French.

TODO: At first, we expect some of these phrases to be *incorrectly* in
English. This is because we haven't added translation files for them.
We should change this test to the appropriate French versions once we add
support for other languages.

Then, we use this test to catch regressions if we change wording without
changing the translation files."""

confoverrides = {
"language": "fr",
"html_context": {
"github_user": "pydata",
"github_repo": "pydata-sphinx-theme",
"github_version": "main",
},
"html_theme_options": {
"use_edit_page_button": True,
},
}
sphinx_build = sphinx_build_factory("base", confoverrides=confoverrides).build()

# Use a section page so that we have section navigation in the sidebar
index = sphinx_build.html_tree("section1/index.html")

# TODO: Add translations where there are english phrases below
sidebar_primary = index.select(".bd-sidebar-primary")[0]
assert "Site Navigation" in str(sidebar_primary)
assert "Section Navigation" in str(sidebar_primary)

# TODO: Add translations where there are english phrases below
sidebar_secondary = index.select(".bd-sidebar-secondary")[0]
assert "Montrer le code source" in str(sidebar_secondary)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a translation that you came up with or is it from sphinx?
I'm a native speaker and that sounds very weird compared to "Voir code source"

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this is just what sphinx spat out - was not my translation! Another good reason to add out own translations? 🙂

assert "Edit this page" in str(sidebar_secondary)

# TODO: Add translations where there are english phrases below
header = index.select(".bd-header")[0]
assert "light/dark" in str(header)

# TODO: Add translations where there are english phrases below
footer = index.select(".bd-footer")[0]
assert "Copyright" in str(footer)
assert "Created using" in str(footer)
assert "Built with the" in str(footer)

footer_article = index.select(".bd-footer-article")[0]
assert "précédent" in str(footer_article)
assert "suivant page" in str(footer_article)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here it should just be "Suivant" or "Page suivante"


# Search bar
# TODO: Add translations where there are english phrases below
assert "Search the docs" in str(index.select(".bd-search")[0])