You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When creating a theme that provides additional translated message, the messages provided by Nikola are no longer translated.
Expected
The messages provided by Nikola are till present in the translation.
Reproduce
To reproduce the issue, we call load_messages like nikola would do in a project.
Save this code to a file called translations-bug.py
from nikola.utils import load_messages
# mimic the arguments "nkola build" would pass
msgs = load_messages(
['my-themes/dummy', 'nikola/data/themes/base'],
{'de': ''},
'de',
['themes'])
for s in (
"Posted:", # string translated in "base" theme
"My new message", # string translated in dummy theme
):
if s not in msgs["de"]:
print(f"{s:<20} string missing")
elif msgs["de"][s] == s:
print(f"{s:<20} not translated")
else:
print(f"{s:<20} translated to {msgs['de'][s]}")
Run it like this:
MSG_FILE='my-themes/dummy/messages/messages_de.py'
MSG_DIR=$(dirname $MSG_FILE)
mkdir -p $MSG_DIR
echo '===== Without translation file in theme ---'
rm -rf $MSG_DIR/*
python translations-bug.py
echo
echo '===== With translation file in theme ---'
rm -rf $MSG_DIR/*
echo > $MSG_FILE 'MESSAGES = {"My new message": "Meine neue Meldung"}'
python translations-bug.py
echo
echo '===== With translation file containing no strings in theme ---'
rm -rf $MSG_DIR/*
echo > $MSG_FILE 'MESSAGES = {}'
python translations-bug.py
Output:
===== Without translation file in theme ---
Posted: translated to Veröffentlicht:
My new message string missing
===== With translation file in theme ---
Posted: not translated
My new message translated to Meine neue Meldung
===== With translation file containing no strings in theme ---
Posted: not translated
My new message string missing
Expected output:
===== Without translation file in theme ---
Posted: translated to Veröffentlicht:
My new message string missing
===== With translation file in theme ---
Posted: translated to Veröffentlicht:
My new message translated to Meine neue Meldung
===== With translation file containing no strings in theme ---
Posted: translated to Veröffentlicht:
My new message string missing
The text was updated successfully, but these errors were encountered:
I don’t think we’ve ever documented that messages would be picked up from the parent theme, I can’t find any mention of that in our docs.
We haven’t changed messages in 7 years, and considering most users don’t override them, it will be easier for you to just copy the file from the base theme and modify it to your needs. I don’t think we’ll change that.
The issue is not about overwriting, but about adding. Obviously the idea is to allow adding translations without the need to copy all the strings. Otherwise the code would simply load the theme's translation file.
I just created #3836 fixing the issue (and cleaning up the method).
As I understand the original code, its primary goal is to ensure all messages have some value (even if it’s the English one) to avoid crashes for missing messages. The proposed change looks OK to me, but needs more testing and needs to avoid overwriting messages with English ones if the base theme has those.
Environment
Description:
When creating a theme that provides additional translated message, the messages provided by Nikola are no longer translated.
Expected
The messages provided by Nikola are till present in the translation.
Reproduce
To reproduce the issue, we call
load_messages
like nikola would do in a project.translations-bug.py
Output:
Expected output:
The text was updated successfully, but these errors were encountered: