Cannot assign different translations for present and past message of BatchAction

Bug #1252082 reported by Akihiro Motoki
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OpenStack Dashboard (Horizon)
Fix Released
Medium
Akihiro Motoki
Havana
Fix Released
Medium
Akihiro Motoki

Bug Description

Message strings of BatchAction (including DeleteAction) is generated in _conjugate of BatchAction in horizon/tables/actions.py. _conjugate() generates both "present" message string (which is used as table action name and confirm dialog) and "past" message strings (which is displayed as a message popup after the specified operation is completed).

Iin some languages (at least Japanese) we need to use different translated strings for "present" and "past" message strings, but The same string "%(action)s %(data_type)s" is used to generate them. As a result, either of "present" or "past" message string may become odd translation string (e.g., Havana Horizon translation in Japanese has some odd strings due to this issue).

At least it is better "present" and "past" message strings can be distinguished.

From translation perspective, it is ideal we can define "present" and "past" strings respectively for each action class rather than generating strings in _conjugate(). Translator need to use different strings based on action types. It will be filed as a separate bug.

My idea is to use contextual marker [1] to distinguish them.
I would like to hear opinions before proposing a patch.

@@ -557,8 +558,11 @@ class BatchAction(Action):
             data_type = self.data_type_singular
         else:
             data_type = self.data_type_plural
- return _("%(action)s %(data_type)s") % {'action': action,
- 'data_type': data_type}
+ if action_type == "past":
+ msgstr = pgettext_lazy("past", "%(action)s %(data_type)s")
+ else:
+ msgstr = pgettext_lazy("present", "%(action)s %(data_type)s")
+ return msgstr % {'action': action, 'data_type': data_type}

     def action(self, request, datum_id):
         """

After this, we can get the following entries in the PO file and assign different translations to "past" and "present" strings.

#: tables/actions.py:562
#, python-format
msgctxt "past"
msgid "%(action)s %(data_type)s"
msgstr ""

#: tables/actions.py:564
#, python-format
msgctxt "present"
msgid "%(action)s %(data_type)s"
msgstr ""

[1] https://docs.djangoproject.com/en/dev/topics/i18n/translation/#contextual-markers

Tags: i18n
Changed in horizon:
status: New → Confirmed
Revision history for this message
Julie Pichon (jpichon) wrote :

This looks good to me, it seems useful and quite low impact in terms of changing the current code. If it helps the dashboard have more natural sounding translations when used in other languages we should do it :-)

It may be good to also ask the i18n team for their input and the impact on other languages?

In general I worry about having a "_conjugate()" method in the code, this makes a lot of assumptions on language. Perhaps we should also work on a separate longer term solution.

Revision history for this message
Łukasz Jernaś (deejay1) wrote :

             data_type = self.data_type_singular
         else:
             data_type = self.data_type_plural

The above part also worries me, since some languages use multiple plural forms...

Revision history for this message
Akihiro Motoki (amotoki) wrote :

In general plural form problem can be handled with ungettext_lazy.
https://docs.djangoproject.com/en/dev/topics/i18n/translation/#lazy-translations-and-plural
I think we need to change all classes inherited BatchAction and DeleteAction. I haven't tested below.

IMO it is better to be fixed separately.

The following is an example of DeleteNetwork: (https://github.com/openstack/horizon/blob/master/openstack_dashboard/dashboards/project/networks/tables.py#L42)

 class DeleteNetwork(CheckNetworkEditable, tables.DeleteAction):
      data_type = ungettext_lazy("Network", "Networks", "_count")

and change horizon/tables/action.py

    data_type = self.data_type % {'_count': <num_of_items>}

Revision history for this message
Akihiro Motoki (amotoki) wrote :

> In general I worry about having a "_conjugate()" method in the code, this makes a lot of
> assumptions on language. Perhaps we should also work on a separate longer term solution.

Totally agree.

What in my mind is to add message_present and message_past attributes to BatchAction for child classes to control messages as they like. If message_(present|past) is not defined, the current mechanism (_conjugate) is used.
It is better to be done in Icehouse cycle.

Regarding this bug, I would like to backport the fix to Havana stable if possible,
so I want to minimize the change.

Akihiro Motoki (amotoki)
summary: - Message string of BatchAction is hard to translate
+ Cannot assign different translations for present and past message of
+ BatchAction
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to horizon (master)

Fix proposed to branch: master
Review: https://review.openstack.org/57634

Changed in horizon:
status: Confirmed → In Progress
Revision history for this message
Akihiro Motoki (amotoki) wrote :

I changed the title to more specific one.

In addition, I filed problems raised in comments as separate bugs.

- bug 1253678 : the problem related to _conjugate()
- bug 1253174 : the problem raised by Lukasz

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to horizon (master)

Reviewed: https://review.openstack.org/57634
Committed: http://github.com/openstack/horizon/commit/9e6d59bc8b7811622e42ebdcb5911eb6487a4f77
Submitter: Jenkins
Branch: master

commit 9e6d59bc8b7811622e42ebdcb5911eb6487a4f77
Author: Akihiro MOTOKI <email address hidden>
Date: Thu Nov 21 05:11:01 2013 +0900

    Add contextual markers to BatchAction messages

    BatchAction message is used for both present (table action menu)
    and past (completion message) and there is no way that translators
    use different texts for present and passt messages.
    This commit add contextual markers to the message strings and allows
    translators to use different texts for message in BatchAction.

    Change-Id: Ie6438730386fc2cca18704354d5cf5f5b71cd494
    Closes-Bug: #1252082

Changed in horizon:
status: In Progress → Fix Committed
Akihiro Motoki (amotoki)
tags: added: havana-backport-potential
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to horizon (stable/havana)

Fix proposed to branch: stable/havana
Review: https://review.openstack.org/58139

Akihiro Motoki (amotoki)
Changed in horizon:
importance: Undecided → Medium
milestone: none → icehouse-1
Akihiro Motoki (amotoki)
tags: removed: havana-backport-potential
Thierry Carrez (ttx)
Changed in horizon:
status: Fix Committed → Fix Released
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to horizon (stable/havana)

Reviewed: https://review.openstack.org/58139
Committed: http://github.com/openstack/horizon/commit/27d01bee4bf556e93379e718fd15bcce3f45c181
Submitter: Jenkins
Branch: stable/havana

commit 27d01bee4bf556e93379e718fd15bcce3f45c181
Author: Akihiro MOTOKI <email address hidden>
Date: Thu Nov 21 05:11:01 2013 +0900

    Add contextual markers to BatchAction messages

    BatchAction message is used for both present (table action menu)
    and past (completion message) and there is no way that translators
    use different texts for present and passt messages.
    This commit add contextual markers to the message strings and allows
    translators to use different texts for message in BatchAction.

    Change-Id: Ie6438730386fc2cca18704354d5cf5f5b71cd494
    Closes-Bug: #1252082
    (cherry picked from commit 9e6d59bc8b7811622e42ebdcb5911eb6487a4f77)

Thierry Carrez (ttx)
Changed in horizon:
milestone: icehouse-1 → 2014.1
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.