Skip to content

Translations in themes remove messages provided by Nikola #3835

Open
@htgoebel

Description

@htgoebel

Environment

  • Python Version: 3.10
  • Nikola Version: Nikola v8.3.1
  • Operating System: GNU/Linux

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.

  1. 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]}")
  1. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions