sphinx-book-theme
sphinx-book-theme copied to clipboard
Bugged language support?
Describe the bug
context and bug
The language support seems not working (or partially working) now when used together with Jupyter Book. No matter what language is set in _config.yml, for example:
sphinx:
config:
language: fr
There will still be many words remaining untranslated (i.e. in English). Based on the following example, it seems that it used to work but not anymore.
Reproduce the bug
I forked a Jupyter Book written in French (associated Github repo) and pushed the book to my Github pages (associated Github repo) using exactly the same Github Action.
Screenshot from the original Book pages (last push was on Dec 8, 2021)

Screenshot from the forked Book pages (last push was on Jul 10, 2022)

You can see while some of the words are translated (e.g. Suivant and juil.), many others are not (Last updated, By, ...).
@pnavaro I would like to ping you here since I used your book as a test case. Maybe you also have some ideas about this?
List your environment
Latest version on conda in Dec 8, 2021 vs Jul 10, 2022.
Thanks for opening your first issue here! Engagement like this is essential for open source projects! :hugs:
If you haven't done so already, check out EBP's Code of Conduct. Also, please try to follow the issue template as it helps other community members to contribute more effectively.
If your issue is a feature request, others may react to it, to raise its prominence (see Feature Voting).
Welcome to the EBP community! :tada:
Linked to #538 perharps ?
Further digging this today made me realize that it is because of the missing .mo files in ${sphinx_book_theme_root}/theme/sphinx_book_theme/static/locales/*/LC_MESSAGES, as required by sphinx.locale.get_translation.
A quick workaround is
- go to
${sphinx_book_theme_root} - delete all existing
.pofiles byrm -rf theme/sphinx_book_theme/static/locales/* - run
python _compile_translations.pyand regenerate both the.poand.mofiles. Now it should be no problem to generate a fully translated Jupyter Book.
But here I wonder if we could address this in the next few releases since it is so important for all international JB users. It seems to me that _compile_translations.py was executed at build time (so we see .po files), but failed to generate .mo files for an unknown reason.
Thanks a lot for this workaround! I tried it on Windows (10) and it worked after some additional steps. Here all the steps I did to get it working.
- Locate your Sphinx installation. It should be located where you global libraries are located. In case you use a
venv:
C:\{path to your venv}\Lib\site-packages\sphinx_book_theme\ - From there navigate to
sphinx_book_theme\theme\sphinx_book_theme\static\locales
and delete everything inside the folder. - Install GetText from https://gnuwin32.sourceforge.net/packages/gettext.htm. This is the Windows version of a unixtool for native language support. The executable
msgfrm.exeis needed from this installation to generate the.mofiles. Add thebinfolder of the installation to the%path%system variable. In my case the path isC:\GnuWin32\bin. - Navigate to
sphinx_book_theme\and locate the file_compile_translations.py. Edit the file:
Change line 57 from
with out_path.open("a") as f:
to
with out_path.open("a", encoding="utf-8") as f:
and safe it. - Open a new terminal window (cmd). Acvtivate your venv if you have one. Now run the python script:
python .\_compile_translations.py. All the translations should be fine now. Rebuild your Jupyter-Book book.
The sphinx_book_theme-0.3.3-py3-none-any.whl file does not contain *.mo files, this can be also resolved by installing sphinx-book-theme from source:
pip install sphinx-book-theme --no-binary 'sphinx-book-theme'
I’m not sure why it is not working on your side. I had no time to reproduce this error. My first guess is, you did not start the script from the right directory.
Please navigate (with cd on the command prompt) to the directory sphinx_book_theme\ and afterwards try to execute the script again (._compile_translations.py).
Regards Adrian
Von: Gouvernathor @.> Gesendet: Donnerstag, 24. November 2022 22:05 An: executablebooks/sphinx-book-theme @.> Cc: Busin Adrian (busi) @.>; Mention @.> Betreff: Re: [executablebooks/sphinx-book-theme] Bugged language support? (Issue #584)
@iasbusihttps://github.com/iasbusi your 5. doesn't work on my end.
C:\Windows\system32>cd C:\Program Files\Python39\Lib\site-packages\sphinx_book_theme
C:\Program Files\Python39\Lib\site-packages\sphinx_book_theme>py ./_compile_translations.py
[SBT]: Compiling translations
C:\Program Files\Python39\Lib\site-packages\sphinx_book_theme\assets\translations....\theme\sphinx_book_theme\static\locales\ar\LC_MESSAGES\booktheme.po
Traceback (most recent call last):
File "C:\Program Files\Python39\Lib\site-packages\sphinx_book_theme_compile_translations.py", line 78, in
convert_json()
File "C:\Program Files\Python39\Lib\site-packages\sphinx_book_theme_compile_translations.py", line 66, in convert_json
subprocess.check_call(
File "C:\Program Files\Python39\lib\subprocess.py", line 368, in check_call
retcode = call(*popenargs, **kwargs)
File "C:\Program Files\Python39\lib\subprocess.py", line 349, in call
with Popen(*popenargs, **kwargs) as p:
File "C:\Program Files\Python39\lib\subprocess.py", line 951, in init
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:\Program Files\Python39\lib\subprocess.py", line 1420, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] Le fichier spécifié est introuvable
C:\Program Files\Python39\Lib\site-packages\sphinx_book_theme>
The last line means "the specified file is not found".
NB : I'm not using sphinx in the context of a notebook, so apologies if it's the reason, but I doubt it.
— Reply to this email directly, view it on GitHubhttps://github.com/executablebooks/sphinx-book-theme/issues/584#issuecomment-1326833407, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AAR4UETNP6SX4N6YX2BHFU3WJ7J7PANCNFSM53EWBZNQ. You are receiving this because you were mentioned.Message ID: @.@.>>
I updated the top comment from @whyjz to describe what I think are two potential problems that we need to resolve (see "Diagnosis of problem" section). Would love help from anybody that knows how to fix this! cc @AakashGfude in case he has cycles to look into this, I'd appreciate it!