Skip to content

Commit 458415f

Browse files
trallardpre-commit-ci[bot]gabalafou
authored
BUG - Fix i18n files and compilation for distribution (#2042)
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. --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: gabalafou <[email protected]>
1 parent 23fa1b5 commit 458415f

File tree

17 files changed

+80
-45
lines changed

17 files changed

+80
-45
lines changed

.github/workflows/CI.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ jobs:
7575
# if not we use the default version
7676
# example substitution: tox run -e compile-assets,i18n-compile,py39-tests
7777
else
78-
python -Im tox run -e compile,i18n-compile,py$(echo ${{ matrix.python-version }} | tr -d .)-tests
78+
python -Im tox run -e compile-assets,i18n-compile,py$(echo ${{ matrix.python-version }} | tr -d .)-tests
7979
fi
8080
- name: "Upload coverage data to GH artifacts 📤"
8181
if: matrix.python-version == '3.12' && matrix.os == 'ubuntu-latest' && matrix.sphinx-version == 'dev'

.github/workflows/prerelease.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ jobs:
4040
python -Im tox run -e compile-assets,i18n-compile,py$(echo ${{ matrix.python-version }} | tr -d .)-tests-no-cov
4141
echo "PYTEST_ERRORS=$?" >> $GITHUB_ENV
4242
43+
- name: "Build and inspect package 📦"
44+
uses: hynek/build-and-inspect-python-package@v2
45+
if: matrix.python-version == '3.9'
46+
id: baipp
47+
48+
- run: echo Packages can be found at ${{ steps.baipp.outputs.dist }}
49+
if: matrix.python-version == '3.9'
50+
4351
# If either the docs build or the tests resulted in an error, create an issue to note it
4452
- name: "Create an issue if failure"
4553
uses: JasonEtco/create-an-issue@v2

docs/community/topics/i18n.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ file, and visible to localizers. For example:
8282
8383
{# L10n: Navigation button at the bottom of the page #}
8484
<button type="button">
85-
{{- _("Next page") -}}
85+
{{- _('Next page') -}}
8686
</button>
8787
8888
.. _updating-localization-files:

src/pydata_sphinx_theme/locale/ca/LC_MESSAGES/sphinx.po

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
# Translators:
77
# Cristhian Rivera, 2024
88
# Oriol Abril-Pla <[email protected]>, 2024
9-
#
109
msgid ""
1110
msgstr ""
1211

@@ -145,11 +144,10 @@ msgstr "Fosc"
145144
msgid "System Settings"
146145
msgstr "Configuració del sistema"
147146

148-
#: src/pydata_sphinx_theme/theme/pydata_sphinx_theme/components/theme-version.html:3
147+
#: src/pydata_sphinx_theme/theme/pydata_sphinx_theme/components/theme-version.html:4
149148
#, python-format
150149
msgid ""
151-
"Built with the <a href=\"https://pydata-sphinx-"
152-
"theme.readthedocs.io/en/stable/index.html\">PyData Sphinx Theme</a> "
150+
"Built with the <a href=\"%(PST_url)s\">PyData Sphinx Theme</a> "
153151
"%(theme_version)s."
154152
msgstr ""
155153
"Construïda amb el <a href=\"https://pydata-sphinx-"

src/pydata_sphinx_theme/locale/cs/LC_MESSAGES/sphinx.po

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,10 @@ msgstr "Tmavý"
141141
msgid "System Settings"
142142
msgstr ""
143143

144-
#: src/pydata_sphinx_theme/theme/pydata_sphinx_theme/components/theme-version.html:3
144+
#: src/pydata_sphinx_theme/theme/pydata_sphinx_theme/components/theme-version.html:4
145145
#, python-format
146146
msgid ""
147-
"Built with the <a href=\"https://pydata-sphinx-"
148-
"theme.readthedocs.io/en/stable/index.html\">PyData Sphinx Theme</a> "
147+
"Built with the <a href=\"%(PST_url)s\">PyData Sphinx Theme</a> "
149148
"%(theme_version)s."
150149
msgstr ""
151150
"Vytvořeno pomocí <a href=\"https://pydata-sphinx-"

src/pydata_sphinx_theme/locale/en/LC_MESSAGES/sphinx.po

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,10 @@ msgstr ""
139139
msgid "System Settings"
140140
msgstr ""
141141

142-
#: src/pydata_sphinx_theme/theme/pydata_sphinx_theme/components/theme-version.html:3
142+
#: src/pydata_sphinx_theme/theme/pydata_sphinx_theme/components/theme-version.html:4
143143
#, python-format
144144
msgid ""
145-
"Built with the <a href=\"https://pydata-sphinx-"
146-
"theme.readthedocs.io/en/stable/index.html\">PyData Sphinx Theme</a> "
145+
"Built with the <a href=\"%(PST_url)s\">PyData Sphinx Theme</a> "
147146
"%(theme_version)s."
148147
msgstr ""
149148

@@ -182,3 +181,9 @@ msgstr ""
182181

183182
#~ msgid "light/dark"
184183
#~ msgstr ""
184+
185+
#~ msgid ""
186+
#~ "Built with the <a href=\"https://pydata-"
187+
#~ "sphinx-theme.readthedocs.io/en/stable/index.html\">PyData "
188+
#~ "Sphinx Theme</a> %(theme_version)s."
189+
#~ msgstr ""

src/pydata_sphinx_theme/locale/es/LC_MESSAGES/sphinx.po

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
# Cristhian Rivera, 2024
99
# Felipe Moreno, 2024
1010
# Tania Allard, 2024
11-
#
1211
msgid ""
1312
msgstr ""
1413

@@ -42,8 +41,7 @@ msgstr "Error"
4241

4342
#: src/pydata_sphinx_theme/theme/pydata_sphinx_theme/search.html:9
4443
msgid "Please activate JavaScript to enable the search functionality."
45-
msgstr ""
46-
"Por favor, active JavaScript para habilitar la funcionalidad de búsqueda."
44+
msgstr "Por favor, active JavaScript para habilitar la funcionalidad de búsqueda."
4745

4846
#: src/pydata_sphinx_theme/theme/pydata_sphinx_theme/components/breadcrumbs.html:6
4947
msgid "Breadcrumb"
@@ -148,11 +146,10 @@ msgstr "Oscuro"
148146
msgid "System Settings"
149147
msgstr "Sistema"
150148

151-
#: src/pydata_sphinx_theme/theme/pydata_sphinx_theme/components/theme-version.html:3
149+
#: src/pydata_sphinx_theme/theme/pydata_sphinx_theme/components/theme-version.html:4
152150
#, python-format
153151
msgid ""
154-
"Built with the <a href=\"https://pydata-sphinx-"
155-
"theme.readthedocs.io/en/stable/index.html\">PyData Sphinx Theme</a> "
152+
"Built with the <a href=\"%(PST_url)s\">PyData Sphinx Theme</a> "
156153
"%(theme_version)s."
157154
msgstr ""
158155
"Construido con el <a href=\"https://pydata-sphinx-"

src/pydata_sphinx_theme/locale/fr/LC_MESSAGES/sphinx.po

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
# Translators:
77
# Rambaud Pierrick <[email protected]>, 2024
88
# Denis Bitouzé <[email protected]>, 2024
9-
#
109
msgid ""
1110
msgstr ""
1211

@@ -145,11 +144,10 @@ msgstr "Sombre"
145144
msgid "System Settings"
146145
msgstr "Paramètres système"
147146

148-
#: src/pydata_sphinx_theme/theme/pydata_sphinx_theme/components/theme-version.html:3
147+
#: src/pydata_sphinx_theme/theme/pydata_sphinx_theme/components/theme-version.html:4
149148
#, python-format
150149
msgid ""
151-
"Built with the <a href=\"https://pydata-sphinx-"
152-
"theme.readthedocs.io/en/stable/index.html\">PyData Sphinx Theme</a> "
150+
"Built with the <a href=\"%(PST_url)s\">PyData Sphinx Theme</a> "
153151
"%(theme_version)s."
154152
msgstr ""
155153
"Construit avec le <a href=\"https://pydata-sphinx-"

src/pydata_sphinx_theme/locale/it/LC_MESSAGES/sphinx.po

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,10 @@ msgstr "Scuro"
141141
msgid "System Settings"
142142
msgstr ""
143143

144-
#: src/pydata_sphinx_theme/theme/pydata_sphinx_theme/components/theme-version.html:3
144+
#: src/pydata_sphinx_theme/theme/pydata_sphinx_theme/components/theme-version.html:4
145145
#, python-format
146146
msgid ""
147-
"Built with the <a href=\"https://pydata-sphinx-"
148-
"theme.readthedocs.io/en/stable/index.html\">PyData Sphinx Theme</a> "
147+
"Built with the <a href=\"%(PST_url)s\">PyData Sphinx Theme</a> "
149148
"%(theme_version)s."
150149
msgstr ""
151150
"Prodotto con il tema <a href=\"https://pydata-sphinx-"

src/pydata_sphinx_theme/locale/ja/LC_MESSAGES/sphinx.po

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,10 @@ msgstr "ダーク"
143143
msgid "System Settings"
144144
msgstr ""
145145

146-
#: src/pydata_sphinx_theme/theme/pydata_sphinx_theme/components/theme-version.html:3
146+
#: src/pydata_sphinx_theme/theme/pydata_sphinx_theme/components/theme-version.html:4
147147
#, python-format
148148
msgid ""
149-
"Built with the <a href=\"https://pydata-sphinx-"
150-
"theme.readthedocs.io/en/stable/index.html\">PyData Sphinx Theme</a> "
149+
"Built with the <a href=\"%(PST_url)s\">PyData Sphinx Theme</a> "
151150
"%(theme_version)s."
152151
msgstr ""
153152
"<a href=\"https://pydata-sphinx-"

src/pydata_sphinx_theme/locale/ru/LC_MESSAGES/sphinx.po

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,10 @@ msgstr "темная"
141141
msgid "System Settings"
142142
msgstr ""
143143

144-
#: src/pydata_sphinx_theme/theme/pydata_sphinx_theme/components/theme-version.html:3
144+
#: src/pydata_sphinx_theme/theme/pydata_sphinx_theme/components/theme-version.html:4
145145
#, python-format
146146
msgid ""
147-
"Built with the <a href=\"https://pydata-sphinx-"
148-
"theme.readthedocs.io/en/stable/index.html\">PyData Sphinx Theme</a> "
147+
"Built with the <a href=\"%(PST_url)s\">PyData Sphinx Theme</a> "
149148
"%(theme_version)s."
150149
msgstr ""
151150
"Собрано с использованием темы <a href=\\\"https://pydata-sphinx-"

src/pydata_sphinx_theme/locale/sphinx.pot

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44
# project.
55
# FIRST AUTHOR <EMAIL@ADDRESS>, 2024.
66
#
7+
#, fuzzy
78
msgid ""
89
msgstr ""
9-
"Project-Id-Version: pydata-sphinx-theme 0.16.0rc0\n"
10+
"Project-Id-Version: pydata-sphinx-theme 0.16.1.dev0\n"
1011
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
11-
"POT-Creation-Date: 2024-09-30 17:53+0100\n"
12+
"POT-Creation-Date: 2024-11-18 12:43+0000\n"
1213
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
1314
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1415
"Language-Team: LANGUAGE <[email protected]>\n"
@@ -150,11 +151,10 @@ msgstr ""
150151
msgid "System Settings"
151152
msgstr ""
152153

153-
#: src/pydata_sphinx_theme/theme/pydata_sphinx_theme/components/theme-version.html:3
154+
#: src/pydata_sphinx_theme/theme/pydata_sphinx_theme/components/theme-version.html:4
154155
#, python-format
155156
msgid ""
156-
"Built with the <a href=\"https://pydata-sphinx-"
157-
"theme.readthedocs.io/en/stable/index.html\">PyData Sphinx Theme</a> "
157+
"Built with the <a href=\"%(PST_url)s\">PyData Sphinx Theme</a> "
158158
"%(theme_version)s."
159159
msgstr ""
160160

src/pydata_sphinx_theme/locale/zh/LC_MESSAGES/sphinx.po

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,10 @@ msgstr "暗色"
141141
msgid "System Settings"
142142
msgstr ""
143143

144-
#: src/pydata_sphinx_theme/theme/pydata_sphinx_theme/components/theme-version.html:3
144+
#: src/pydata_sphinx_theme/theme/pydata_sphinx_theme/components/theme-version.html:4
145145
#, python-format
146146
msgid ""
147-
"Built with the <a href=\"https://pydata-sphinx-"
148-
"theme.readthedocs.io/en/stable/index.html\">PyData Sphinx Theme</a> "
147+
"Built with the <a href=\"%(PST_url)s\">PyData Sphinx Theme</a> "
149148
"%(theme_version)s."
150149
msgstr ""
151150
"使用 <a href=\"https://pydata-sphinx-"

src/pydata_sphinx_theme/theme/pydata_sphinx_theme/components/page-toc.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<div
66
id="{{ page_navigation_heading_id }}"
77
class="page-toc tocsection onthispage">
8-
<i class="fa-solid fa-list"></i> {{ _("On this page") }}
8+
<i class="fa-solid fa-list"></i> {{ _('On this page') }}
99
</div>
1010
<nav class="bd-toc-nav page-toc" aria-labelledby="{{ page_navigation_heading_id }}">
1111
{{ page_toc }}
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
{# Displays the version of pydata-sphinx-theme used to build the documentation. #}
22
<p class="theme-version">
3-
{% trans theme_version=theme_version|e %}Built with the <a href="https://pydata-sphinx-theme.readthedocs.io/en/stable/index.html">PyData Sphinx Theme</a> {{ theme_version }}.{% endtrans %}
3+
<!-- # L10n: Setting the PST URL as an argument as this does not need to be localized -->
4+
{% trans trimmed theme_version=theme_version|e, PST_url="https://pydata-sphinx-theme.readthedocs.io/en/stable/index.html" %}
5+
Built with the <a href="{{ PST_url }}">PyData Sphinx Theme</a> {{ theme_version }}.
6+
{% endtrans %}
47
</p>

tox.ini

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ env_list =
1515
# helping contributors run common tasks without needing to call all the steps
1616
# For example to run the tests: tox run -m tests
1717
labels =
18-
tests = compile-assets, i18n-compile, py312-tests
18+
tests = compile-assets, i18n-compile, py312-tests
1919
a11y = compile-assets, i18n-compile, py312-docs, a11y-tests
2020
i18n = i18n-extract, i18n-compile
2121
live-server = compile-assets, i18n-compile, docs-live
@@ -156,7 +156,8 @@ allowlist_externals = bash
156156
commands =
157157
# explicitly pass this as a bash command to set PST_VERSION
158158
bash -c "PST_VERSION=$(pip show pydata-sphinx-theme | grep Version | awk -F': ' '{print $2}') && \
159-
pybabel extract . -F babel.cfg -o src/pydata_sphinx_theme/locale/sphinx.pot --project=pydata-sphinx-theme --copyright-holder='PyData developers' --version=$PST_VERSION"
159+
pybabel extract . -F babel.cfg -o src/pydata_sphinx_theme/locale/sphinx.pot --keywords='_ __ l_ lazy_gettext' \
160+
--project=pydata-sphinx-theme --copyright-holder='PyData developers' --version=$PST_VERSION"
160161
pybabel update -i src/pydata_sphinx_theme/locale/sphinx.pot -d src/pydata_sphinx_theme/locale -D sphinx {posargs}
161162

162163
# add a new locale for translations based on the catalog template

webpack.config.js

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@ const CssMinimizerPlugin = require("css-minimizer-webpack-plugin");
1616
const TerserPlugin = require("terser-webpack-plugin");
1717
const dedent = require("dedent");
1818
const { Compilation } = require("webpack");
19+
const { exec } = require("child_process");
1920

2021
/*******************************************************************************
2122
* Paths for various assets (sources and destinations)
2223
*/
2324

2425
const scriptPath = resolve(__dirname, "src/pydata_sphinx_theme/assets/scripts");
2526
const staticPath = resolve(__dirname, "src/pydata_sphinx_theme/theme/pydata_sphinx_theme/static");
27+
const localePath = resolve(__dirname, "src/pydata_sphinx_theme/locale");
2628

2729
/*******************************************************************************
2830
* functions to load the assets in the html head
@@ -96,8 +98,8 @@ const htmlWebpackPlugin = new HtmlWebpackPlugin({
9698
templateContent: macroTemplate,
9799
});
98100

99-
module.exports = {
100-
mode: "production",
101+
// webpack main configuration
102+
var config = {
101103
devtool: "source-map",
102104
entry: {
103105
"pydata-sphinx-theme": resolve(scriptPath, "pydata-sphinx-theme.js"),
@@ -170,3 +172,31 @@ module.exports = {
170172
topLevelAwait: true,
171173
},
172174
};
175+
176+
module.exports = (env, argv) => {
177+
// Sphinx Theme Builder creates a completely isolated working directory
178+
// when packaging the theme. That means that we cannot follow a workflow
179+
// like this:
180+
// 1. run command to compile the translations
181+
// 2. run command to package the theme (`stb package`)
182+
// We must instead compile the translations **as part of** the command
183+
// that builds the theme:
184+
// 1. command to package theme
185+
// a. compile translations
186+
// The theme builder calls `npm run-script build` (`webpack --mode=production` per our
187+
// package.json) so we compile the translations here.
188+
if (argv.mode === 'production') {
189+
exec(`pybabel compile -d ${localePath} -D sphinx`, (error, stdout, stderr) => {
190+
if (error) {
191+
console.error(`Error: ${error.message}`);
192+
return;
193+
}
194+
if (stderr) {
195+
console.error(`stderr: ${stderr}`);
196+
return;
197+
}
198+
console.log(`stdout: ${stdout}`);
199+
});
200+
}
201+
return config;
202+
};

0 commit comments

Comments
 (0)