Bug 40339 - Univention Management Console - simplify localization by using named arguments in msgs
Univention Management Console - simplify localization by using named argument...
Status: CLOSED FIXED
Product: UCS
Classification: Unclassified
Component: UMC (Generic)
UCS 4.1
Other Linux
: P5 enhancement (vote)
: UCS 4.1-0-errata
Assigned To: Florian Best
Daniel Tröder
:
Depends on: 38155 40341
Blocks:
  Show dependency treegraph
 
Reported: 2015-12-23 18:26 CET by Daniel Orrego
Modified: 2016-02-04 14:04 CET (History)
6 users (show)

See Also:
What kind of report is it?: ---
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): Internationalization, Usability
Max CVSS v3 score:


Attachments
Errors from univention-ucs-translation-build-package.py UCS4.1 (29.59 KB, text/plain)
2015-12-23 18:26 CET, Daniel Orrego
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Orrego univentionstaff 2015-12-23 18:26:32 CET
Created attachment 7385 [details]
Errors from univention-ucs-translation-build-package.py UCS4.1

+++ This bug was initially created as a clone of Bug #38155 +++

UCS 4.1-0 errata44

== The issue

I had multiple warning on UMC files that use msgs syntax with unnamed arguments (eg: %s).
Standardizing the use to named arguments like: %(variableName)s will easy the translation to new languages.

* Message:

<Source-file.py:line>
  warning: 'msgid' format string with unnamed arguments cannot be properly localized.

----
umc/python/diagnostic/plugins/nameserver.py:43:
    warning: 'msgid' format string with unnamed arguments cannot be properly localized:
        The translator cannot reorder the arguments.
        Please consider using a format string with named arguments,
        and a mapping instead of a tuple for the arguments.
----

See attachment for all files with those warnings

== Fix

* The first warning can be solved by using named arguments (see example below). The recommendation is to use %(varname)s format instead of %s. (See link [1])

For example to get rid of the warning for nameserver.py:43, we need to replace this line:
msgs = ['\n', _('The nameserver %s (UCR variable %r) is not responsive:') % (ucr[nameserver], nameserver)]
For this one:
msgs = ['\n', _('The nameserver %(ucr[nameserver])s (UCR variable %(nameserver)r) is not responsive:') % (ucr[nameserver], nameserver)]

[1] https://code.djangoproject.com/ticket/3410#comment:5
Comment 1 Florian Best univentionstaff 2016-01-14 13:12:46 CET
Rewrote all format strings with multiple arguments in all UMC modules.

univention-quota (10.0.1-2):
r66794 | Bug #40339: format string with multiple unnamed arguments
r66787 | Bug #40339: fix PO metadata

univention-system-setup (9.0.2-27):
r66793 | Bug #40339: format string with multiple unnamed arguments
r66787 | Bug #40339: fix PO metadata

univention-appcenter.yaml:
r66796 | YAML Bug #40339

univention-management-console.yaml:
r66796 | YAML Bug #40339

univention-join.yaml:
r66796 | YAML Bug #40339

univention-management-console-module-top.yaml:
r66796 | YAML Bug #40339

univention-appcenter (5.0.19-42):
r66789 | Bug #40339: format string with multiple unnamed arguments
r66787 | Bug #40339: fix PO metadata

univention-quota.yaml:
r66796 | YAML Bug #40339

univention-management-console-module-adtakeover.yaml:
r66796 | YAML Bug #40339
Comment 2 Florian Best univentionstaff 2016-01-18 12:44:13 CET
And fixed the last occurrences. No errors anymore against UCS 4.1.

univention-management-console (8.0.28-5):
r66841 | Bug #40339: fix format string with multiple unnamed arguments

univention-directory-manager-modules (11.0.2-13):
r66843 | Bug #40339: fix format string with multiple unnamed arguments

univention-management-console-frontend (5.0.63-11):
r66842 | Bug #40339: fix format string with multiple unnamed arguments
r66844 | Bug #40339: fixup

r66845 | YAML Bug #40339
Comment 3 Daniel Tröder univentionstaff 2016-01-27 09:14:37 CET
OK: checked that modifications in PO files are reflected in js/py code
OK: ran some modules (random sample) to check functionality at runtime
OK: searched complete 4.1 source code (not just UMC) for format strings with multiple unnamed arguments:

~/svn/dev/branches/ucs-4.1/ucs-4.1-0$ find -name '*.po' -exec egrep '_\(.*%.*%\w' {} +
~/svn/dev/branches/ucs-4.1/ucs-4.1-0$ find -name '*.js' -exec egrep '_\(.*%.*%\w' {} +
~/svn/dev/branches/ucs-4.1/ucs-4.1-0$ find -name '*.py' -exec egrep '_\(.*%.*%\w' {} +

~/svn/dev/branches/ucs-4.1/ucs-4.1-0$ find -name '*.po' -exec egrep '%s.*%s' {} +
~/svn/dev/branches/ucs-4.1/ucs-4.1-0$ find -name '*.py' -exec egrep '_\(.*%s.*%s' {} +
~/svn/dev/branches/ucs-4.1/ucs-4.1-0$ find -name '*.js' -exec egrep '_\(.*%s.*%s' {} +

OK: checked output of univention-ucs-translation-build-package:

root@ucs26:~# cd ~/sync/ucs-4.1-0
root@ucs26:~/sync/ucs-4.1-0# svn up
Password: 
Revision 66985.
root@ucs26:~/sync/ucs-4.1-0# univention-ucs-translation-build-package.py -s ~/sync/ucs-4.1-0 -c de_DE -l de_DE.UTF-8:UTF-8 -n "Deutsch" 2>&1 | grep unnamed
[keine Ausgabe]
Comment 4 Daniel Tröder univentionstaff 2016-01-27 09:21:21 CET
PS:
* typo, must be: >> ~/svn/dev/branches/ucs-4.1/ucs-4.1-0$ find -name '*.po' -exec egrep '.*%.*%\w' {} + <<, but doesn't reveal problems (only in unused translations)
* OK: advisories