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

Language switcher doesn't work in Runtime docs and Nature docs #272

Closed
kifumi opened this issue Apr 18, 2023 · 6 comments · Fixed by qiskit-community/qiskit-finance#256
Closed
Assignees
Milestone

Comments

@kifumi
Copy link

kifumi commented Apr 18, 2023

The language switcher does not work in Runtime documents and Nature documents.

In the other docs, it works fine.

image

@woodsp-ibm
Copy link
Member

woodsp-ibm commented Apr 18, 2023

If I look at ML, Opt or Finance I do not see it at all - its does work though!

image

Now it's there it seems, if I click in that area I get a dropdown and can change language - but statically the language and the dropdown arrow is not visible to me, as per the above image (Firefox/Windows if it matters)

@HuangJunye HuangJunye added this to the Theme v1.12.0 milestone Apr 18, 2023
@SooluThomas
Copy link
Member

I think removing docs/_templates/versions.html file in PR #255 caused this. Though I'm not yet sure why things are working perfectly on Main Docs.

@Eric-Arellano
Copy link
Collaborator

Eric-Arellano commented Apr 20, 2023

Thanks for this report!

It should not be #255 - that is only on the main branch of qiskit_sphinx_theme and not the 1.11 branch.

It looks like this has been broken for some time. The missing content for Finance, ML, Opt, etc is because their files versionutils.py are setting version_label rather than language_label. We apparently changed in https://github.com/Qiskit/qiskit_sphinx_theme/pull/49/files#diff-93e646cab52c16e3a78d1b4e89128816440d65384cff09e35bdcb3ddcc428027R3 in October 2022 for the theme to expect language_label to describe the currently selected language. So, you can fix that problem with a diff like this:

diff --git a/docs/versionutils.py b/docs/versionutils.py
index 92033c4..3ad5248 100644
--- a/docs/versionutils.py
+++ b/docs/versionutils.py
@@ -46,7 +46,7 @@ def _extend_html_context(app, config):
     context["translations_list"] = translations_list
     context["current_translation"] = _get_current_translation(config) or config.language
     context["translation_url"] = partial(_get_translation_url, config)
-    context["version_label"] = _get_version_label(config)
+    context["language_label"] = _get_version_label(config)
 
 
 def _get_current_translation(config):

The reason that it's not clickable on Runtime and Nature is that jQuery is missing so the JavaScript code we have does not work. That is because Sphinx 5 used to include jQuery, but Sphinx 6 no longer does. The workaround is to install sphinxcontrib-jquery:

diff --git a/docs/conf.py b/docs/conf.py
index 0d1754b..eef7ee1 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -99,6 +99,7 @@ extensions = [
     "sphinx.ext.doctest",
     "nbsphinx",
     "sphinx.ext.intersphinx",
+    "sphinxcontrib.jquery",
 ]
 html_static_path = ["_static"]
 templates_path = ["_templates"]
diff --git a/docs/versionutils.py b/docs/versionutils.py
index 29702e5..8305b5b 100644
--- a/docs/versionutils.py
+++ b/docs/versionutils.py
@@ -46,7 +46,7 @@ def _extend_html_context(app, config):
     context["translations_list"] = translations_list
     context["current_translation"] = _get_current_translation(config) or config.language
     context["translation_url"] = partial(_get_translation_url, config)
-    context["version_label"] = _get_version_label(config)
+    context["language_label"] = _get_version_label(config)
 
 
 def _get_current_translation(config):
diff --git a/requirements-dev.txt b/requirements-dev.txt
index 5e96877..d5fb701 100644
--- a/requirements-dev.txt
+++ b/requirements-dev.txt
@@ -18,3 +18,4 @@ mypy-extensions>=0.4.3
 nbsphinx
 qiskit_sphinx_theme>=1.10
 networkx>=2.2,<2.6
+sphinxcontrib-jquery

I'm not sure why the other applications and Terra are working. They must be installing jQuery some other way. We should not be using jQuery anymore though: I opened #275 to track this and will release 1.11.1 to include jQuery with the Qiskit Sphinx Theme: #276.

--

Taking a step back, it is not sustainable for each repository to have its own versionutils.py. It is too easy to fall out of sync.

This should be provided for you by qiskit_sphinx_theme, IMO. At most, you only have to configure what languages you want.

I will submit soon PRs to each repo with the short-term fixes. But I also propose that the theme 1.12 starts including versionutils.py for you so that this Just Works in the future. (Along with other structural fixes for Ecosystem projects like #267)

@Eric-Arellano Eric-Arellano self-assigned this Apr 20, 2023
Eric-Arellano added a commit that referenced this issue Apr 21, 2023
…r JavaScript issues (#277)

Sphinx 6 stopped including jQuery by default, but we're still using it
in some places. As a result, the docs' functionality is broken in some
places like the language selection not being clickable:
#272

I wanted to remove jQuery via
#275, but it is too
hard to safely due with Pytorch because we have 105 usages. We will need
to wait for the switch to Furo.

So, for now, we will include jQuery by default. We also try to activate
the extension by default with the line
`app.setup_extension("sphinxcontrib.jquery"),` but I'm having issues
with that actually working. So, projects may need to still add
`"sphinxcontrib.jquery"` explicitly in their extensions in `conf.py` -
but they at least won't have to explicitly include
`sphinxcontrib-jquery` in their requirements.

--

This PR also fixes other issues with our JavaScript, as reported by the
developer console:

1. `languages.html` was not recognizing jQuery. So, rewrite it to modern
JavaScript
2. `pytorchAnchors.bind();` was not defined so caused some of our setup
to fail
3. `handleLeftMenu:` function was failing because
`document.getElementById("docs-tutorials-resources")` does not exist.
Since that function failed, it looks like it wasn't actually necessary
anymore.
Eric-Arellano added a commit to Eric-Arellano/qiskit_sphinx_theme that referenced this issue Apr 21, 2023
…r JavaScript issues (Qiskit#277)

Sphinx 6 stopped including jQuery by default, but we're still using it
in some places. As a result, the docs' functionality is broken in some
places like the language selection not being clickable:
Qiskit#272

I wanted to remove jQuery via
Qiskit#275, but it is too
hard to safely due with Pytorch because we have 105 usages. We will need
to wait for the switch to Furo.

So, for now, we will include jQuery by default. We also try to activate
the extension by default with the line
`app.setup_extension("sphinxcontrib.jquery"),` but I'm having issues
with that actually working. So, projects may need to still add
`"sphinxcontrib.jquery"` explicitly in their extensions in `conf.py` -
but they at least won't have to explicitly include
`sphinxcontrib-jquery` in their requirements.

--

This PR also fixes other issues with our JavaScript, as reported by the
developer console:

1. `languages.html` was not recognizing jQuery. So, rewrite it to modern
JavaScript
2. `pytorchAnchors.bind();` was not defined so caused some of our setup
to fail
3. `handleLeftMenu:` function was failing because
`document.getElementById("docs-tutorials-resources")` does not exist.
Since that function failed, it looks like it wasn't actually necessary
anymore.
Eric-Arellano added a commit that referenced this issue Apr 21, 2023
…r JavaScript issues (Cherry-pick of #277) (#278)

Sphinx 6 stopped including jQuery by default, but we're still using it
in some places. As a result, the docs' functionality is broken in some
places like the language selection not being clickable:
#272

I wanted to remove jQuery via
#275, but it is too
hard to safely due with Pytorch because we have 105 usages. We will need
to wait for the switch to Furo.

So, for now, we will include jQuery by default. We also try to activate
the extension by default with the line
`app.setup_extension("sphinxcontrib.jquery"),` but I'm having issues
with that actually working. So, projects may need to still add
`"sphinxcontrib.jquery"` explicitly in their extensions in `conf.py` -
but they at least won't have to explicitly include
`sphinxcontrib-jquery` in their requirements.

--

This PR also fixes other issues with our JavaScript, as reported by the
developer console:

1. `languages.html` was not recognizing jQuery. So, rewrite it to modern
JavaScript
2. `pytorchAnchors.bind();` was not defined so caused some of our setup
to fail
3. `handleLeftMenu:` function was failing because
`document.getElementById("docs-tutorials-resources")` does not exist.
Since that function failed, it looks like it wasn't actually necessary
anymore.
@Eric-Arellano
Copy link
Collaborator

I've started to fix some ecosystem projects, like qiskit-community/qiskit-finance#256. The fix isn't complete though: when changing the language, we stop showing what is currently chosen.

image_360

I suspect this is because versionutils.py is not up-to-date. I will fix this soon.

@Eric-Arellano
Copy link
Collaborator

@SooluThomas figured out why the Finance docs weren't working when switching to other languages. We weren't properly deploying docs to qiskit.org/ecosystem, only the legacy qiskit.org/documentation. Fixed by qiskit-community/qiskit-translations#1108.

Everything is now fixed on the qiskit_sphinx_theme side thanks to #278. I am going through each project in the ecosystem today to fix any translations not working correctly.

The theme release for 1.12 will start including the versionutils.py logic in the theme itself so that we can stop copying and pasting it in every project: #262.

@Eric-Arellano
Copy link
Collaborator

The theme release for 1.12 will start including the versionutils.py logic in the theme itself so that we can stop copying and pasting it in every project: #262.

See #302

Eric-Arellano added a commit that referenced this issue May 9, 2023
…302)

Part of #262.
Before, to add translation support, you would have to copy and paste
`versionutils.py`. Now, you ~only need to define `translations_list` in
`conf.py` and `qiskit_sphinx_theme` will set up the rest for you.

That duplication of `versionutils.py` was annoying to copy and also made
it too easy to fall out of sync, resulting in
#272.

To prove this works, this PR removes `language_utils.py` from
`example_docs/` and instead sets its values in `conf.py`. Translations
still work:

<img width="753" alt="Screenshot 2023-05-05 at 1 13 59 PM"
src="https://user-images.githubusercontent.com/14852634/236549631-2f844db4-8ff6-49e7-9ef0-af1cbbcb5c43.png">

This PR intentionally does not refactor any of the `translations.py`
code. It only copies and pastes what we had from all our projects, to
make it easier to review. The only divergences are:

* Removing the `translations` config option and HTML context. It wasn't
being used by anything.
* Removing the `current_translation` HTML context. It wasn't being used
by anything.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants