Skip to content

Using lazy_gettext in boot-time translations#37

Open
mesemus wants to merge 3 commits intoinveniosoftware:masterfrom
mesemus:lazy_gettext
Open

Using lazy_gettext in boot-time translations#37
mesemus wants to merge 3 commits intoinveniosoftware:masterfrom
mesemus:lazy_gettext

Conversation

@mesemus
Copy link
Copy Markdown
Contributor

@mesemus mesemus commented Oct 23, 2024

Description

This pull request fixes premature evaluation of i18n strings inside static fields. gettext call, that causes
the evaluation to be performed at boot time, was replaced with gettext_lazy that is performed at
request time. This fixes sort options not being translated when language is changed.

Checklist

Ticks in all boxes and 🟢 on all GitHub actions status checks are required to merge:

Frontend

Reminder

By using GitHub, you have already agreed to the GitHub’s Terms of Service including that:

  1. You license your contribution under the same terms as the current repository’s license.
  2. You agree that you have the right to license your contribution under the current repository’s license.

@mesemus
Copy link
Copy Markdown
Contributor Author

mesemus commented Oct 23, 2024

Please backport this change to RDM 12

@Samk13
Copy link
Copy Markdown
Member

Samk13 commented Oct 25, 2024

LGTM! Thanks for the great addition!

I noticed that some packages register translations as:

invenio_i18n.translations =
    messages = invenio_i18n

while others use:

invenio_i18n.translations =
    invenio_i18n = invenio_i18n

see: here
For clarity and consistency, we should standardize on invenio_pkg_name = invenio_pkg_name across packages, although it doesn't make a big difference here. Using the package name as the namespace avoids ambiguity and prevents potential conflicts.

@utnapischtim utnapischtim added this to v14 Dec 19, 2025
@utnapischtim utnapischtim moved this to 👀 In review in v14 Dec 19, 2025
mesemus and others added 2 commits April 19, 2026 13:39
* the problem was that with gettext the translations for facets
  have been only be calculated on boot time.

* using lazy_gettext instead fixes that, because it calculates
  the translation at the request level

Co-authored-by: Mirek Simek <miroslav.simek@cesnet.cz>
* there were no tests for translations in administration interface in this package

* this commit adds tests that at least some of the strings get translated and translations work

Note: In order that the test runs successfully, you need to invoke python setup.py compile_catalog prior running the tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: 👀 In review

Development

Successfully merging this pull request may close these issues.

3 participants