Use % formatting for new workflow / audit log translation strings

See #5548 - Transifex recognises % formatting, and will guard against translators introducing errors by attempting to translate the embedded variable names.
pull/6257/head
Matt Westcott 2020-07-17 22:04:18 +01:00 zatwierdzone przez Matt Westcott
rodzic 441bcde1ad
commit 6f85bca664
3 zmienionych plików z 66 dodań i 87 usunięć

Wyświetl plik

@ -1059,7 +1059,6 @@ Audit log
.. code-block:: python .. code-block:: python
from django.utils.text import format_lazy
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from wagtail.core import hooks from wagtail.core import hooks
@ -1069,8 +1068,7 @@ Audit log
actions.register_action('wagtail_package.echo', _('Echo'), _('Sent an echo')) actions.register_action('wagtail_package.echo', _('Echo'), _('Sent an echo'))
def callback_message(data): def callback_message(data):
return format_lazy( return _('Hello {audience}') % {
_('Hello {audience}'), 'audience': data['audience'],
audience=data['audience'], }
)
actions.register_action('wagtail_package.with_callback', _('Callback'), callback_message) actions.register_action('wagtail_package.with_callback', _('Callback'), callback_message)

Wyświetl plik

@ -5,7 +5,6 @@ from django.forms import Media, MediaDefiningClass
from django.template.loader import render_to_string from django.template.loader import render_to_string
from django.urls import reverse from django.urls import reverse
from django.utils.functional import cached_property from django.utils.functional import cached_property
from django.utils.text import format_lazy
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from wagtail.core import hooks from wagtail.core import hooks
@ -316,7 +315,7 @@ class PageActionMenu:
icon_name = 'edit' icon_name = 'edit'
if name == "approve": if name == "approve":
if is_final_task: if is_final_task:
label = format_lazy(_("{label} and Publish"), label=label) label = _("%(label)s and Publish") % {'label': label}
icon_name = 'success' icon_name = 'success'
item = WorkflowMenuItem(name, label, launch_modal, icon_name=icon_name) item = WorkflowMenuItem(name, label, launch_modal, icon_name=icon_name)

Wyświetl plik

@ -1,7 +1,6 @@
from django.contrib.auth.models import Permission from django.contrib.auth.models import Permission
from django.urls import reverse from django.urls import reverse
from django.utils.http import urlencode from django.utils.http import urlencode
from django.utils.text import format_lazy
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from django.utils.translation import gettext from django.utils.translation import gettext
from draftjs_exporter.dom import DOM from draftjs_exporter.dom import DOM
@ -816,101 +815,90 @@ def register_core_log_actions(actions):
def revert_message(data): def revert_message(data):
try: try:
return format_lazy( return _('Reverted to previous revision with id %(revision_id)s from %(created_at)s') % {
_('Reverted to previous revision with id {revision_id} from {created_at}'), 'revision_id': data['revision']['id'],
revision_id=data['revision']['id'], 'created_at': data['revision']['created'],
created_at=data['revision']['created'] }
)
except KeyError: except KeyError:
return _('Reverted to previous revision') return _('Reverted to previous revision')
def copy_message(data): def copy_message(data):
try: try:
return format_lazy( return _('Copied from %(title)s') % {
_('Copied from {title}'), 'title': data['source']['title'],
title=data['source']['title'] }
)
except KeyError: except KeyError:
return _("Copied") return _("Copied")
def move_message(data): def move_message(data):
try: try:
return format_lazy( return _("Moved from '%(old_parent)s' to '%(new_parent)s'") % {
_("Moved from '{old_parent}' to '{new_parent}'"), 'old_parent': data['source']['title'],
old_parent=data['source']['title'], 'new_parent': data['destination']['title'],
new_parent=data['destination']['title'] }
)
except KeyError: except KeyError:
return _('Moved') return _('Moved')
def schedule_publish_message(data): def schedule_publish_message(data):
try: try:
if data['revision']['has_live_version']: if data['revision']['has_live_version']:
return format_lazy( return _('Revision %(revision_id)s from %(created_at)s scheduled for publishing at %(go_live_at)s.') % {
_('Revision {revision_id} from {created_at} scheduled for publishing at {go_live_at}.'), 'revision_id': data['revision']['id'],
revision_id=data['revision']['id'], 'created_at': data['revision']['created'],
created_at=data['revision']['created'], 'go_live_at': data['revision']['go_live_at'],
go_live_at=data['revision']['go_live_at'] }
)
else: else:
return format_lazy( return _('Page scheduled for publishing at %(go_live_at)s') % {
_('Page scheduled for publishing at {go_live_at}'), 'go_live_at': data['revision']['go_live_at'],
go_live_at=data['revision']['go_live_at'] }
)
except KeyError: except KeyError:
return _('Page scheduled for publishing') return _('Page scheduled for publishing')
def unschedule_publish_message(data): def unschedule_publish_message(data):
try: try:
if data['revision']['has_live_version']: if data['revision']['has_live_version']:
return format_lazy( return _('Revision %(revision_id)s from %(created_at)s unscheduled from publishing at %(go_live_at)s.') % {
_('Revision {revision_id} from {created_at} unscheduled from publishing at {go_live_at}.'), 'revision_id': data['revision']['id'],
revision_id=data['revision']['id'], 'created_at': data['revision']['created'],
created_at=data['revision']['created'], 'go_live_at': data['revision']['go_live_at'],
go_live_at=data['revision']['go_live_at'] }
)
else: else:
return format_lazy( return _('Page unscheduled for publishing at %(go_live_at)s') % {
_('Page unscheduled for publishing at {go_live_at}'), 'go_live_at': data['revision']['go_live_at'],
go_live_at=data['revision']['go_live_at'] }
)
except KeyError: except KeyError:
return _('Page unscheduled from publishing') return _('Page unscheduled from publishing')
def add_view_restriction(data): def add_view_restriction(data):
try: try:
return format_lazy( return _("Added the '%(restriction)s' view restriction") % {
_("Added the '{restriction}' view restriction"), 'restriction': data['restriction']['title'],
restriction=data['restriction']['title'] }
)
except KeyError: except KeyError:
return _('Added view restriction') return _('Added view restriction')
def edit_view_restriction(data): def edit_view_restriction(data):
try: try:
return format_lazy( return _("Updated the view restriction to '%(restriction)s'") % {
_("Updated the view restriction to '{restriction}'"), 'restriction': data['restriction']['title'],
restriction=data['restriction']['title'] }
)
except KeyError: except KeyError:
return _('Updated view restriction') return _('Updated view restriction')
def delete_view_restriction(data): def delete_view_restriction(data):
try: try:
return format_lazy( return _("Removed the '%(restriction)s' view restriction") % {
_("Removed the '{restriction}' view restriction"), 'restriction': data['restriction']['title'],
restriction=data['restriction']['title'] }
)
except KeyError: except KeyError:
return _('Removed view restriction') return _('Removed view restriction')
def rename_message(data): def rename_message(data):
try: try:
return format_lazy( return _("Renamed from '%(old)s' to '%(new)s'") % {
_("Renamed from '{old}' to '{new}'"), 'old': data['title']['old'],
old=data['title']['old'], 'new': data['title']['new'],
new=data['title']['new'], }
)
except KeyError: except KeyError:
return _('Renamed') return _('Renamed')
@ -929,56 +917,50 @@ def register_core_log_actions(actions):
def register_workflow_log_actions(actions): def register_workflow_log_actions(actions):
def workflow_start_message(data): def workflow_start_message(data):
try: try:
return format_lazy( return _("'%(workflow)s' started. Next step '%(task)s'") % {
_("'{workflow}' started. Next step '{task}'"), 'workflow': data['workflow']['title'],
workflow=data['workflow']['title'], 'task': data['workflow']['next']['title'],
task=data['workflow']['next']['title'], }
)
except (KeyError, TypeError): except (KeyError, TypeError):
return _('Workflow started') return _('Workflow started')
def workflow_approve_message(data): def workflow_approve_message(data):
try: try:
if data['workflow']['next']: if data['workflow']['next']:
return format_lazy( return _("Approved at '%(task)s'. Next step '%(next_task)s'") % {
_("Approved at '{task}'. Next step '{next_task}'"), 'task': data['workflow']['task']['title'],
task=data['workflow']['task']['title'], 'next_task': data['workflow']['next']['title'],
next_task=data['workflow']['next']['title'] }
)
else: else:
return format_lazy( return _("Approved at '%(task)s'. '%(workflow)s' complete") % {
_("Approved at '{task}'. '{workflow}' complete"), 'task': data['workflow']['task']['title'],
task=data['workflow']['task']['title'], 'workflow': data['workflow']['title'],
workflow=data['workflow']['title'] }
)
except (KeyError, TypeError): except (KeyError, TypeError):
return _('Workflow task approved') return _('Workflow task approved')
def workflow_reject_message(data): def workflow_reject_message(data):
try: try:
return format_lazy( return _("Rejected at '%(task)s'. Changes requested") % {
_("Rejected at '{task}'. Changes requested"), 'task': data['workflow']['task']['title'],
task=data['workflow']['task']['title'], }
)
except (KeyError, TypeError): except (KeyError, TypeError):
return _('Workflow task rejected. Workflow complete') return _('Workflow task rejected. Workflow complete')
def workflow_resume_message(data): def workflow_resume_message(data):
try: try:
return format_lazy( return _("Resubmitted '%(task)s'. Workflow resumed'") % {
_("Resubmitted '{task}'. Workflow resumed'"), 'task': data['workflow']['task']['title'],
task=data['workflow']['task']['title'], }
)
except (KeyError, TypeError): except (KeyError, TypeError):
return _('Workflow task resubmitted. Workflow resumed') return _('Workflow task resubmitted. Workflow resumed')
def workflow_cancel_message(data): def workflow_cancel_message(data):
try: try:
return format_lazy( return _("Cancelled '%(workflow)s' at '%(task)s'") % {
_("Cancelled '{workflow}' at '{task}'"), 'workflow': data['workflow']['title'],
workflow=data['workflow']['title'], 'task': data['workflow']['task']['title'],
task=data['workflow']['task']['title'], }
)
except (KeyError, TypeError): except (KeyError, TypeError):
return _('Workflow cancelled') return _('Workflow cancelled')