sphinx-book-theme icon indicating copy to clipboard operation
sphinx-book-theme copied to clipboard

Bugged language support?

Open whyjz opened this issue 3 years ago • 3 comments
trafficstars

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) 1

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

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.

whyjz avatar Jul 10 '22 08:07 whyjz

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:

welcome[bot] avatar Jul 10 '22 08:07 welcome[bot]

Linked to #538 perharps ?

pnavaro avatar Jul 10 '22 10:07 pnavaro

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

  1. go to ${sphinx_book_theme_root}
  2. delete all existing .po files by rm -rf theme/sphinx_book_theme/static/locales/*
  3. run python _compile_translations.py and regenerate both the .po and .mo files. 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.

whyjz avatar Jul 11 '22 07:07 whyjz

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.

  1. 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\
  2. From there navigate to
    sphinx_book_theme\theme\sphinx_book_theme\static\locales
    and delete everything inside the folder.
  3. 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.exe is needed from this installation to generate the .mo files. Add the bin folder of the installation to the %path% system variable. In my case the path is C:\GnuWin32\bin.
  4. 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.
  5. 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.

iasbusi avatar Nov 02 '22 11:11 iasbusi

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'

twalen avatar Nov 04 '22 16:11 twalen

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: @.@.>>

iasbusi avatar Nov 28 '22 16:11 iasbusi

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!

choldgraf avatar Jan 26 '23 17:01 choldgraf