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 support is broken - .mo files not bundled with this theme's wheel #584

Closed
whyjz opened this issue Jul 10, 2022 · 7 comments · Fixed by #684
Closed

Language support is broken - .mo files not bundled with this theme's wheel #584

whyjz opened this issue Jul 10, 2022 · 7 comments · Fixed by #684
Labels
bug Something isn't working
Milestone

Comments

@whyjz
Copy link
Contributor

whyjz commented Jul 10, 2022

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.

Likely diagnosis of problem

There are potentially two problems:

  1. .mo files are not bundled with this theme. For example, in this pre-release there are generated language files in theme/sphinx_book_theme/static/locales/ but they are only .po and not .mo.

    Here's where the compilation happens:

    # compile mo
    for path in (out_folder / "locales").glob("**/booktheme.po"):
    print(path)
    subprocess.check_call(
    [
    "msgfmt",
    os.path.abspath(path),
    "-o",
    os.path.abspath(path.parent / "booktheme.mo"),
    ]
    )

    It isn't clear why this is happening - the only thing I can think of is that the glob isn't picking up the .po files at the end only in the build job for some reason? They are there when I build it locally.

  2. Some theme wording has likely changed. For example, Toggle primary sidebar is (I think) a new phrase that is not in our inventory of language translation phrases. We should find the new phrases that aren't there, and add them via the instructions in that readme.

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 whyjz added the bug Something isn't working label Jul 10, 2022
@welcome
Copy link

welcome bot commented Jul 10, 2022

Thanks for opening your first issue here! Engagement like this is essential for open source projects! 🤗

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! 🎉

@pnavaro
Copy link

pnavaro commented Jul 10, 2022

Linked to #538 perharps ?

@whyjz
Copy link
Contributor Author

whyjz commented Jul 11, 2022

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.

@iasbusi
Copy link

iasbusi commented Nov 2, 2022

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.

@twalen
Copy link

twalen commented Nov 4, 2022

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'

@iasbusi
Copy link

iasbusi commented Nov 28, 2022 via email

@choldgraf choldgraf added this to the v0.4.0 milestone Jan 26, 2023
@choldgraf choldgraf changed the title Bugged language support? Language support is broken - .mo files not bundled with this theme's wheel Jan 26, 2023
@choldgraf
Copy link
Member

choldgraf commented Jan 26, 2023

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants