Skip to content

Translationmixin can not handle exact regional locales (like 'en-us', 'de-at',...) #1591

@MyPyDavid

Description

@MyPyDavid

Description / Beschreibung

Some unexpected behaviour of a failing test in the local development setup lead to finding a bug in the Translationmixin.trans method, it fails to use the exact regional languages.

Expected behaviour / Erwartetes Verhalten

When 'en' is defined in the 'settings.LANGUAGES' and 'en-us' is set as the current locale language then the 'en' field on the Model instance should be used for the translation.

Steps to reproduce / Schritte zum Reproduzieren

I though it would be easy to add a simple test for this but I think that the TranslationMixin is broken somehow and we need to add a fix for that as well.

(Pdb)  django.utils.translation.get_language()
'en-us'
(Pdb) rdmo.core.utils.get_languages()
[('en', 'English', 'lang1'), ('de', 'German', 'lang2')]

and we try to compare 'en' == 'en-us'....

if lang_code == current_language:

(Pdb) section.short_title_lang1
'SectionShorty'
(Pdb) section.short_title
''

🤯 ❓

Originally posted by @MyPyDavid in #1586 (comment)

Context / Kontext

2.4.4

References / Verweise

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No fields configured for Bug.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions