-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Error when internationalizing documentation with ipynb files #11357
Comments
I tried to troubleshoot the issue and found that
|
Same problem here. TracebackTraceback (most recent call last):
File "/----/lib/python3.11/site-packages/sphinx/cmd/build.py", line 298, in build_main
app.build(args.force_all, args.filenames)
File "/----/lib/python3.11/site-packages/sphinx/application.py", line 355, in build
self.builder.build_update()
File "/----/lib/python3.11/site-packages/sphinx/builders/__init__.py", line 293, in build_update
self.build(to_build,
File "/----/lib/python3.11/site-packages/sphinx/builders/__init__.py", line 313, in build
updated_docnames = set(self.read())
^^^^^^^^^^^
File "/----/lib/python3.11/site-packages/sphinx/builders/__init__.py", line 420, in read
self._read_serial(docnames)
File "/----/lib/python3.11/site-packages/sphinx/builders/__init__.py", line 441, in _read_serial
self.read_doc(docname)
File "/----/lib/python3.11/site-packages/sphinx/builders/__init__.py", line 498, in read_doc
publisher.publish()
File "/----/lib/python3.11/site-packages/docutils/core.py", line 236, in publish
self.apply_transforms()
File "/----/lib/python3.11/site-packages/docutils/core.py", line 216, in apply_transforms
self.document.transformer.apply_transforms()
File "/----/lib/python3.11/site-packages/sphinx/transforms/__init__.py", line 83, in apply_transforms
super().apply_transforms()
File "/----/lib/python3.11/site-packages/docutils/transforms/__init__.py", line 182, in apply_transforms
transform.apply(**kwargs)
File "/----/lib/python3.11/site-packages/sphinx/transforms/i18n.py", line 397, in apply
patch = publish_msgstr(self.app, msgstr, source,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/----/lib/python3.11/site-packages/sphinx/transforms/i18n.py", line 73, in publish_msgstr
doc = reader.read(
^^^^^^^^^^^^
File "/----/lib/python3.11/site-packages/docutils/readers/__init__.py", line 70, in read
self.parse()
File "/----/lib/python3.11/site-packages/docutils/readers/__init__.py", line 76, in parse
self.parser.parse(self.input, document)
File "/----/lib/python3.11/site-packages/myst_nb/sphinx_.py", line 89, in parse
notebook = nb_reader.read(inputstring)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/----/lib/python3.11/site-packages/myst_nb/core/read.py", line 38, in standard_nb_read
return nbf.reads(text, as_version=NOTEBOOK_VERSION)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/----/lib/python3.11/site-packages/nbformat/__init__.py", line 89, in reads
nb = reader.reads(s, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/----/lib/python3.11/site-packages/nbformat/reader.py", line 76, in reads
nb_dict = parse_json(s, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^
File "/----/lib/python3.11/site-packages/nbformat/reader.py", line 26, in parse_json
raise NotJSONError(message) from e
nbformat.reader.NotJSONError: Notebook does not appear to be JSON: 'some translated text' |
I don't think this is a problem of Sphinx (at least not immediately), so this should be reported to the affected extensions. For |
I'll close the issue since it's not directly related to Sphinx core. Please report the issue to nbsphinx (should be the one responsible for nbformat). If they tell you that the problem is here, feel free to reopen the issue (or create a new one if it is locked). |
Thanks for the information. workaroundimport polib
import json
po = polib.pofile("<path to the .po file>")
def is_from_notebook(occurrences):
for filename, _linenum in occurrences:
if filename.endswith(".ipynb"):
return True
return False
for entry in po:
if is_from_notebook(entry.occurrences) and entry.msgstr != "":
wrapped = {
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [entry.msgstr],
},
],
"metadata": {
"kernelspec": {
"display_name": "venv",
"language": "python",
"name": "python3",
},
"language_info": {
"codemirror_mode": {"name": "ipython", "version": 3},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.12",
},
},
"nbformat": 4,
"nbformat_minor": 2,
}
entry.msgstr = json.dumps(wrapped)
po.save("<path to the .po file>") At least for me, this code will resolve the error and the rendered text appears to be correct as well. |
Describe the bug
When attempting to internationalize Sphinx documentation that contains ipynb files using the
make -e SPHINXOPTS="-D language='de'" html
command, the following error occurs:How to Reproduce
git clone https://github.com/hwchase17/langchain.git
cd langchain/docs
locale_dirs = ['locale/'] # path is example but recommended.
make gettext
sphinx-intl update -p _build/gettext -l de
make -e SPHINXOPTS="-D language='de'" html
Environment Information
Sphinx extensions
Additional context
No response
The text was updated successfully, but these errors were encountered: