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

BUG - Fix i18n files and compilation for distribution #2042

Merged
merged 17 commits into from
Nov 25, 2024

Conversation

trallard
Copy link
Collaborator

While investigating #2040 I noticed that our current release missed the updated .mo files.
This was a bug I introduced in #1959 when reworking the localisation workflows.

TLD;R—Since we use stb to build the theme, I did not realise that compiling the i18n files had to be done within the stb package (I removed it from the webpack file as this was causing the infinite reload while working on our docs).

Since this was an easy miss, I added our build and inspect job to the pre-release workflow that runs on a chron job to check our build process periodically.

Once we merge this, we can make a small release to patch the current issue.

@trallard trallard added kind: bug Something isn't working tag: i18N Items related to internationalization labels Nov 18, 2024
@@ -75,7 +75,7 @@ jobs:
# if not we use the default version
# example substitution: tox run -e compile-assets,i18n-compile,py39-tests
else
python -Im tox run -e compile,i18n-compile,py$(echo ${{ matrix.python-version }} | tr -d .)-tests
python -Im tox run -e compile-assets,i18n-compile,py$(echo ${{ matrix.python-version }} | tr -d .)-tests
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For whatever reason I had missed this when renaming to compile-assets

@@ -82,7 +82,7 @@ file, and visible to localizers. For example:

{# L10n: Navigation button at the bottom of the page #}
<button type="button">
{{- _("Next page") -}}
{{- _('Next page') -}}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit as we use single quotes in a lot of our localisable strings

tox.ini Show resolved Hide resolved
Copy link

Coverage report

This PR does not seem to contain any modification to coverable code.

Copy link
Collaborator

@gabalafou gabalafou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice detective work. There are some things I don't understand, so I left some questions inline.

@@ -170,3 +172,21 @@ module.exports = {
topLevelAwait: true,
},
};

module.exports = (env, argv) => {
// since STB isolates the build, we need to compile the translations here for releases
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you provide a link in this code comment to more info? What does it mean that STB isolates the build?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Under the hood stb uses build for perform stb package (which in turn calls python -m build).
build builds the package in an isolated env to create the source distribution (https://build.pypa.io/en/stable/)

That means, when compiling assets from tox (or even doing npm run build during development or in our CI) it would result in something like

# note I added a simple console print to demonstrate
Webpack is building the theme in my-local-dir/pydata-sphinx-theme/src/pydata_sphinx_theme/theme/pydata_sphinx_theme/static
Locale will be located in my-local-dir/pydata-sphinx-theme/src/pydata_sphinx_theme/locale

When calling via stb package or python -m build (which is what we do to build the dist) this is instead

Webpack is building the theme in /private/var/folders/6p/062gm41556s5p63x1555cjzw0000gn/T/build-via-sdist-rmc_7ti7/pydata_sphinx_theme-0.16.1.dev0/src/pydata_sphinx_theme/theme/pydata_sphinx_theme/static
Locale will be located in /private/var/folders/6p/062gm41556s5p63x1555cjzw0000gn/T/build-via-sdist-rmc_7ti7/pydata_sphinx_theme-0.16.1.dev0/src/pydata_sphinx_theme/locale

so if you compile the translation files first with tox run -e i18n-compile then the compiled .mo will not be included in the distribution files by default (this isolation helps to avoid unwanted files and what not to be added to the distribution packages afterall)

MANIFEST.in Outdated Show resolved Hide resolved
.github/workflows/prerelease.yml Show resolved Hide resolved
webpack.config.js Show resolved Hide resolved
gabalafou
gabalafou previously approved these changes Nov 21, 2024
Copy link
Collaborator

@gabalafou gabalafou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked that this brought in new translations on a test Sphinx site of my own, so this seems to be working.

However, I do have one concern about pybabel sending output to stderr (see inline comment).

webpack.config.js Show resolved Hide resolved
webpack.config.js Outdated Show resolved Hide resolved
@trallard trallard requested a review from gabalafou November 25, 2024 12:32
@trallard
Copy link
Collaborator Author

@gabalafou, I needed to re-request a review since I added your suggestion.
Can you have a check, please so we can merge

@trallard trallard merged commit 458415f into pydata:main Nov 25, 2024
25 checks passed
@trallard trallard deleted the trallard/patch-translations branch November 25, 2024 15:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: bug Something isn't working tag: i18N Items related to internationalization
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants