i18n strings with >1 placeholder should always use dictionary, not tuple, replacement
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
OpenStack Compute (nova) |
Fix Released
|
Low
|
Ed Leafe |
Bug Description
From Ed Leafe's explanation in a code review:
The problem is that translations are not word-for-word; a phrase in different languages may order the words differently. Probably the most common example would be adjectives coming before the noun in English ("the white house"), but after the noun in others (e.g., Spanish: "la casa blanca"). If your code looks like:
color = "white"
thing = "house"
print _("The %s %s") % (color, thing)
... it will print "The white house" in English, but the Spanish will print "La blanca casa", which is wrong. You need to use a mapping for the formatting, so that the code above would read:
color = "white"
thing = "house"
print _("The %(color)s %(thing)s") % locals()
Yeah, I know that this is a weak example, since the color and thing are still in English, but it's just designed to demonstrate how positional substitution is to be avoided in localization strings.
If you run xgettext on a file that uses tuples for multiple substitutions, it will emit the following:
"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."
Related branches
- Thierry Carrez (community): Approve
- Jay Pipes (community): Approve
-
Diff: 1614 lines (+340/-281)35 files modifiedbin/nova-api (+1/-1)
bin/nova-dhcpbridge (+3/-3)
doc/ext/nova_todo.py (+3/-2)
nova/api/ec2/__init__.py (+12/-8)
nova/api/ec2/admin.py (+23/-16)
nova/api/ec2/apirequest.py (+4/-2)
nova/api/ec2/cloud.py (+8/-6)
nova/api/openstack/servers.py (+3/-3)
nova/auth/ldapdriver.py (+2/-2)
nova/auth/manager.py (+42/-27)
nova/compute/api.py (+7/-4)
nova/compute/manager.py (+17/-15)
nova/compute/monitor.py (+6/-4)
nova/db/sqlalchemy/api.py (+13/-19)
nova/exception.py (+3/-2)
nova/fakerabbit.py (+6/-5)
nova/network/manager.py (+6/-4)
nova/objectstore/handler.py (+22/-21)
nova/rpc.py (+10/-9)
nova/scheduler/manager.py (+1/-1)
nova/service.py (+2/-2)
nova/tests/test_rpc.py (+2/-1)
nova/utils.py (+5/-3)
nova/virt/hyperv.py (+46/-39)
nova/virt/images.py (+1/-1)
nova/virt/libvirt_conn.py (+14/-12)
nova/virt/xenapi/fake.py (+5/-2)
nova/virt/xenapi/vm_utils.py (+33/-27)
nova/virt/xenapi/vmops.py (+5/-2)
nova/virt/xenapi/volume_utils.py (+9/-9)
nova/virt/xenapi/volumeops.py (+12/-13)
nova/virt/xenapi_conn.py (+4/-9)
nova/volume/api.py (+4/-3)
nova/volume/manager.py (+4/-3)
nova/wsgi.py (+2/-1)
Changed in nova: | |
assignee: | nobody → Ed Leafe (ed-leafe) |
Changed in nova: | |
status: | Confirmed → In Progress |
Changed in nova: | |
status: | In Progress → Fix Committed |
Changed in nova: | |
milestone: | none → 2011.1 |
status: | Fix Committed → Fix Released |