Bug 51633 - Fix univention.lib.i18n broken functionality
Fix univention.lib.i18n broken functionality
Status: CLOSED FIXED
Product: UCS
Classification: Unclassified
Component: univention-lib
UCS 5.0
Other Linux
: P5 normal (vote)
: UCS 5.0
Assigned To: Florian Best
Philipp Hahn
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2020-07-07 10:44 CEST by Florian Best
Modified: 2021-05-25 16:02 CEST (History)
1 user (show)

See Also:
What kind of report is it?: Development Internal
What type of bug is this?: ---
Who will be affected by this bug?: ---
How will those affected feel about the bug?: ---
User Pain:
Enterprise Customer affected?:
School Customer affected?:
ISV affected?:
Waiting Support:
Flags outvoted (downgraded) after PO Review:
Ticket number:
Bug group (optional):
Max CVSS v3 score:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Florian Best univentionstaff 2020-07-07 10:44:11 CEST
Some functions in univention.lib.i18n are broken:

from univention.lib import i18n
i18n.Locale('deu_GER') # → is valid de_DE, should raise exception
str(i18n.Locale('ca_ES@valencia')) # is transformed into "ca_ES.valencia"
str(i18n.Locale()) # raises TypeError: __str__ returned non-string (type NoneType)
Comment 1 Florian Best univentionstaff 2020-07-07 10:47:35 CEST
Fixed all cases:

univention-lib (9.0.0-30)
| Bug #51633: fix univention.lib.i18n

changelog-5.0-0.xml
| Changelog Bug #51633
Comment 2 Philipp Hahn univentionstaff 2020-12-01 17:04:17 CET
Bzgl. locale: Die seltsame Schreibweise mit `lang[_territory][.codeset][:charmap]` stammt daher, dass UCS das 2-Tupel (`locale`, `charset`) in UCR speichern will/muss, damit `locale-gen` seine Arbeit erledigen kann. Das eigentliche Format für `locale` sieht `:charmap` nicht vor, das ist nur eine extra-Information die *nur* `locale-gen` braucht: Wenn bei der `locale` explizit das `.codeset` angegeben ist, dann ergibt sich die `chapmap` daraus. Historisch wurde das aber nicht explizit anegegeben und jede Sprache hat ihren eigenen alten Default: `ISO-8859-X`, `ENC-JP`, … und wie sie allte heßen. Aber da `locale-gen` eben diese Information braucht, wird sie in `/etc/locale.gen` eben einfach immer mit angegeben. Und desegen auch in UCRV `locale` und `locale/default`.
Fast alle UCR tmplates, die diese beiden UCRV auswerten, zerteilen die Listen an ` ` und schneiden dann alles vor `:` ab, weil das eben der Separator für `locale.gen` ist, der dafür aber durch ein Leerzeichen ersetzt wird, weil das Format Zeilen von 2-Tupel ist.
Von daher gehört das `:charmap` IMHO nicht den den (generischen) Parser für "locales", weil es nur eine Besonderheit von UCRV `locale` und `locale/default` ist.
Comment 3 Philipp Hahn univentionstaff 2020-12-01 19:01:45 CET
univention-lib/unittest/test_i18n.py::TestLocale::test_init looks wrong for `de_DE.UTF-8:UTF-8@euro`: This is never the right format, as locale is
> language[_territory][.codeset][@modifier]
The appended `:UTF-8` would come after that in UCRV `locale` and `locale/default`, as `:` is the separator, so that the resulting line in `/etc/locale.gen` would become
> de_DE.UTF-8@euro UTF-8

I fixed this in

[5.0-0] 663d25e551 Bug #52194 lib/i18n: Fix setting locale
 base/univention-lib/python/i18n.py         |  62 ++++++++++++--------
 base/univention-lib/unittests/test_i18n.py | 155 ++++++++++++++++++++++++-------------------------
 2 files changed, 112 insertions(+), 105 deletions(-)

Please fix the location from where you directly pass UCRV `locale` to univention.lib.i18n.Locale(): split on `:` and only pass the first part.

FIXED: Fixed unit test.
OK: changelog
TODO: Bug #52194
Comment 4 Florian Best univentionstaff 2021-05-25 16:02:31 CEST
UCS 5.0 has been released:
 https://docs.software-univention.de/release-notes-5.0-0-en.html
 https://docs.software-univention.de/release-notes-5.0-0-de.html

If this error occurs again, please use "Clone This Bug".