From 12f232699b7a1ff671ca04249b1d87cee129709d Mon Sep 17 00:00:00 2001 From: Akihiro Motoki Date: Sat, 12 Mar 2016 18:34:51 +0900 Subject: [PATCH] i18n: Use new way to define action_present/past In Kilo or Liberty cycle, the way to define action messages in horizon BatchAction was changed for better translation support (pluralization and better word order control). The previous way with data_type_singular/plural is deprecated. This commit cleans up the deprecated usage. Change-Id: Icbb75710ac7e7c9c97a6198a28d02583c37136d7 --- muranodashboard/categories/tables.py | 18 +++++- muranodashboard/environments/tables.py | 79 +++++++++++++++++++++----- muranodashboard/images/tables.py | 18 +++++- muranodashboard/packages/tables.py | 17 +++++- 4 files changed, 113 insertions(+), 19 deletions(-) diff --git a/muranodashboard/categories/tables.py b/muranodashboard/categories/tables.py index 5ce00f315..590695c2a 100644 --- a/muranodashboard/categories/tables.py +++ b/muranodashboard/categories/tables.py @@ -14,6 +14,7 @@ from django.core.urlresolvers import reverse from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import ungettext_lazy from horizon import exceptions from horizon import tables from muranoclient.common import exceptions as exc @@ -33,8 +34,21 @@ class AddCategory(tables.LinkAction): class DeleteCategory(tables.DeleteAction): - data_type_singular = _('Category') - data_type_plural = _('Categories') + @staticmethod + def action_present(count): + return ungettext_lazy( + u"Delete Category", + u"Delete Categories", + count + ) + + @staticmethod + def action_past(count): + return ungettext_lazy( + u"Deleted Category", + u"Deleted Categories", + count + ) def allowed(self, request, category=None): if category is not None: diff --git a/muranodashboard/environments/tables.py b/muranodashboard/environments/tables.py index 01e5ae5a3..75b55f86a 100644 --- a/muranodashboard/environments/tables.py +++ b/muranodashboard/environments/tables.py @@ -19,6 +19,7 @@ from django import http as django_http from django import shortcuts from django.template import defaultfilters from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import ungettext_lazy from horizon import exceptions from horizon import forms @@ -87,11 +88,24 @@ class CreateEnvironment(tables.LinkAction): class DeleteEnvironment(tables.DeleteAction): - data_type_singular = _('Environment') - data_type_plural = _('Environments') - action_past = _('Start Deleting') redirect_url = "horizon:project:murano:environments" + @staticmethod + def action_present(count): + return ungettext_lazy( + u"Delete Environment", + u"Delete Environments", + count + ) + + @staticmethod + def action_past(count): + return ungettext_lazy( + u"Start Deleting Environment", + u"Start Deleting Environments", + count + ) + def allowed(self, request, environment): if environment: return environment.status not in (consts.STATUS_ID_DEPLOYING, @@ -113,12 +127,24 @@ class AbandonEnvironment(tables.DeleteAction): help_text = _("This action cannot be undone. Any resources created by " "this environment will have to be released manually.") name = 'abandon' - action_present = _('Abandon') - action_past = _('Abandoned') - data_type_singular = _('Environment') - data_type_plural = _('Environments') redirect_url = "horizon:project:murano:environments" + @staticmethod + def action_present(count): + return ungettext_lazy( + u"Abandon Environment", + u"Abandon Environments", + count + ) + + @staticmethod + def action_past(count): + return ungettext_lazy( + u"Abandoned Environment", + u"Abandoned Environments", + count + ) + def allowed(self, request, environment): """Limit when 'Abandon Environment' button is shown @@ -143,9 +169,22 @@ class AbandonEnvironment(tables.DeleteAction): class DeleteService(tables.DeleteAction): - data_type_singular = _('Component') - data_type_plural = _('Components') - action_past = _('Start Deleting') + + @staticmethod + def action_present(count): + return ungettext_lazy( + u"Delete Component", + u"Delete Components", + count + ) + + @staticmethod + def action_past(count): + return ungettext_lazy( + u"Start Deleting Component", + u"Start Deleting Components", + count + ) def allowed(self, request, service=None): status, version = _get_environment_status_and_version(request, @@ -168,12 +207,24 @@ class DeleteService(tables.DeleteAction): class DeployEnvironment(tables.BatchAction): name = 'deploy' - action_present = _('Deploy') - action_past = _('Deployed') - data_type_singular = _('Environment') - data_type_plural = _('Environment') classes = ('btn-launch',) + @staticmethod + def action_present(count): + return ungettext_lazy( + u"Deploy Environment", + u"Deploy Environments", + count + ) + + @staticmethod + def action_past(count): + return ungettext_lazy( + u"Deployed Environment", + u"Deployed Environments", + count + ) + def allowed(self, request, environment): """Limit when 'Deploy Environment' button is shown diff --git a/muranodashboard/images/tables.py b/muranodashboard/images/tables.py index a766accea..76f304ea9 100644 --- a/muranodashboard/images/tables.py +++ b/muranodashboard/images/tables.py @@ -14,6 +14,7 @@ from django.core.urlresolvers import reverse from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import ungettext_lazy from horizon import exceptions from horizon import tables from openstack_dashboard.api import glance @@ -31,8 +32,21 @@ class MarkImage(tables.LinkAction): class RemoveImageMetadata(tables.DeleteAction): - data_type_singular = _('Metadata') - data_type_plural = _('Metadata') + @staticmethod + def action_present(count): + return ungettext_lazy( + u"Delete Metadata", + u"Delete Metadata", + count + ) + + @staticmethod + def action_past(count): + return ungettext_lazy( + u"Deleted Metadata", + u"Deleted Metadata", + count + ) def delete(self, request, obj_id): try: diff --git a/muranodashboard/packages/tables.py b/muranodashboard/packages/tables.py index 7258385db..a6f9e0f6c 100644 --- a/muranodashboard/packages/tables.py +++ b/muranodashboard/packages/tables.py @@ -175,7 +175,22 @@ class TogglePublicEnabled(tables.BatchAction): class DeletePackage(tables.DeleteAction): name = 'delete_package' - data_type_singular = _('Package') + + @staticmethod + def action_present(count): + return ungettext_lazy( + u"Delete Package", + u"Delete Packages", + count + ) + + @staticmethod + def action_past(count): + return ungettext_lazy( + u"Deleted Package", + u"Deleted Packages", + count + ) def delete(self, request, obj_id): try: