Repository navigation
Make the sidebar toggle tooltips translatable - #1013
Open
chanellebingham wants to merge 2 commits into
Open
chanellebingham wants to merge 2 commits into
chanellebingham wants to merge 2 commits into
Conversation
The "Toggle primary sidebar" and "Toggle secondary sidebar" tooltips in components/toggle-primary-sidebar.html and components/toggle-secondary-sidebar.html were hard-coded in English, while the rest of the theme's strings go through the theme's message catalog. Wrap both strings in the theme's translate() helper and add them to the translation JSONs, with the Hungarian translations supplied in the issue. Other languages fall back to the English string, as before. Closes executablebooks#998
Build the test site with language = "hu" and check that both sidebar toggle buttons carry the Hungarian tooltip. The compiled booktheme.mo catalogs come from `stb compile` and are not present in every test environment, so the test compiles a catalog for the two strings from the translation JSONs with Babel (a Sphinx dependency) and registers it for the "booktheme" domain before building.
This branch has not been deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #998
The "Toggle primary sidebar" and "Toggle secondary sidebar" tooltips were hard-coded in English in
components/toggle-primary-sidebar.htmlandcomponents/toggle-secondary-sidebar.html. In a site built withlanguage = "hu"they stayed English while the neighbouring header buttons were translated ("Forrásfájl letöltése", "Nyomtatás PDF-be", "Teljes képernyős mód").Changes:
translate()helper, which the other templates already use for thebookthemecatalog.Toggle primary sidebar.jsonandToggle secondary sidebar.jsonundersrc/sphinx_book_theme/assets/translations/jsons/, with the English source string and the Hungarian translations from the issue. Other languages fall back to the English string, as they do today. The files are formatted with prettier as described in the translations README.test_sidebar_toggle_tooltips_translated, which builds the test site withlanguage = "hu"and checks thetitleattribute of both toggle buttons. The compiledbooktheme.mocatalogs come fromstb compileand are not present in every test environment, so the test compiles a catalog for the two strings from the JSONs with Babel (already a Sphinx dependency) and registers it for thebookthemedomain viasphinx.locale.initbefore building. docutils has no Hungarian localisation and warns about that, so the test setssuppress_warnings = ["docutils"].Testing:
Rendered
titleattributes of a small site built with-D language=hu, before and after:The default-language (English) build is unchanged, so the
build__header-article.htmlregression fixture did not need updating.The new test fails on
mainand passes with the change:It also passes with no compiled
static/locales/directory present at all.Full suite:
pytest-> 30 passed, 1 skipped on Sphinx 9.1.0 and on Sphinx 8.2.3 (mainis 29 passed, 1 skipped).ruff check,ruff format --check(ruff 0.15.20),codespell(2.4.2) andprettier --check(3.9.4) are clean on the changed files.Noticed while testing, not changed here:
_compile_translations.pywrites the.pofiles with the platform default encoding, so on Windows it fails on the first non-Latin-1 string unless run withpython -X utf8. Happy to open a separate small PR for that if useful.Open questions:
enandhu. The translations README describes generating the other languages with the smodin.io service; would you like that done in this PR, or left for native speakers (as for the other strings)?toggle-primary-sidebar.html. Whichever lands second needs a trivial rebase; happy to do that on this side.sphinx.locale.initstep exists only because test environments have no compiled catalogs. It can be dropped if you would rather keep the suite simpler.I used an AI assistant (Claude) to help investigate and write this change; I reviewed the diff and ran the tests myself before opening.