admin: add i18n-context to some generic option strings (#8213)

This commit is contained in:
Frédéric Péters 2015-09-08 14:48:27 +02:00
parent 50f1e431c2
commit 0d0a3ecb2f
5 changed files with 33 additions and 25 deletions

View File

@ -18,7 +18,7 @@ wcs.pot: $(PYFILES)
for file in $(PYFILES); do \
cnt=$$(expr $$cnt + 1); \
bn=$$cnt.`basename $$file`; \
xgettext --keyword=N_ -c -L Python -o tmp.$$bn.pot $$file; \
xgettext --keyword=N_ --keyword=C_ -c -L Python -o tmp.$$bn.pot $$file; \
done
msgcat tmp.*.pot > wcs.pot
rm tmp.*.pot

View File

@ -255,7 +255,7 @@ def test_forms_edit():
assert FormDef.get(1).has_captcha is True
# Publication
assert_option_display(resp, 'Online Status', 'Published')
assert_option_display(resp, 'Online Status', 'Active')
resp = resp.click('Online Status')
assert resp.forms[0]['disabled'].checked is False
resp.forms[0]['disabled'].checked = True
@ -281,7 +281,7 @@ def test_forms_edit():
resp = resp.forms[0].submit()
assert resp.location == 'http://example.net/backoffice/forms/1/'
resp = resp.follow()
assert_option_display(resp, 'Online Status', 'Disabled by date')
assert_option_display(resp, 'Online Status', 'Inactive by date')
# try changing title
resp = app.get('/backoffice/forms/1/')

View File

@ -31,6 +31,7 @@ from qommon.errors import *
from qommon.form import *
from qommon.backoffice.menu import html_top
from qommon import get_logger
from qommon.misc import C_
from qommon import tokens
from qommon.afterjobs import AfterJob
@ -357,11 +358,14 @@ class FormDefPage(Directory):
r += htmltext('<ul class="biglist optionslist">')
r += add_option_line('options/description', _('Description'),
self.formdef.description and _('On') or _('None'))
self.formdef.description and
C_('description|On') or C_('description|None'))
r += add_option_line('options/keywords', _('Keywords'),
self.formdef.keywords and self.formdef.keywords or _('None'))
self.formdef.keywords and
self.formdef.keywords or C_('keywords|None'))
r += add_option_line('options/category', _('Category'),
self.formdef.category_id and self.formdef.category.name or _('None'))
self.formdef.category_id and
self.formdef.category.name or C_('category|None'))
r += htmltext('</ul>')
r += htmltext('</div>')
@ -416,41 +420,46 @@ class FormDefPage(Directory):
r += htmltext('<ul class="biglist optionslist">')
r += add_option_line('options/confirmation', _('Confirmation Page'),
self.formdef.confirmation and _('Enabled') or _('Disabled'))
self.formdef.confirmation and
C_('confirmation page|Enabled') or C_('confirmation page|Disabled'))
r += add_option_line('options/private_status',
_('History and Status'),
self.formdef.private_status_and_history and _('Private') or _('Public'))
self.formdef.private_status_and_history and
C_('history and status|Private') or C_('history and status|Public'))
r += add_option_line('options/only_allow_one',
_('Limit to one form'),
self.formdef.only_allow_one and _('Enabled') or _('Disabled'))
self.formdef.only_allow_one and
C_('limit to one|Enabled') or C_('limit to one|Disabled'))
if self.formdef.roles:
r += add_option_line('options/always_advertise',
_('Display to unlogged users'),
self.formdef.always_advertise and _('Enabled') or _('Disabled'))
self.formdef.always_advertise and
C_('display to unlogged|Enabled') or C_('display to unlogged|Disabled'))
r += add_option_line('options/tracking_code',
_('Tracking Code'),
self.formdef.enable_tracking_codes and _('Enabled') or _('Disabled'))
self.formdef.enable_tracking_codes and
C_('tracking code|Enabled') or C_('tracking code|Disabled'))
r += add_option_line('options/captcha',
_('CAPTCHA for anonymous users'),
self.formdef.has_captcha and _('Enabled') or _('Disabled'))
self.formdef.has_captcha and
C_('captcha|Enabled') or C_('captcha|Disabled'))
online_status = _('Published')
online_status = C_('online status|Active')
if self.formdef.disabled:
# manually disabled
online_status = _('Disabled')
online_status = C_('online status|Disabled')
if self.formdef.disabled_redirection:
online_status = _('Redirected')
elif self.formdef.is_disabled():
# disabled by date
online_status = _('Disabled by date')
online_status = _('online status|Inactive by date')
r += add_option_line('options/online_status',
_('Online Status'),
online_status)
_('Online Status'), online_status)
r += htmltext('</ul>')
r += htmltext('</div>')
@ -477,7 +486,7 @@ class FormDefPage(Directory):
roles.append(_('Unknown role (%s)') % role_id)
value = htmltext(', ').join(roles)
else:
value = _('None')
value = C_('roles|None')
return value
def get_sidebar(self):

View File

@ -362,11 +362,9 @@ def get_foreground_colour(background_colour):
fg_colour = 'white'
return fg_colour
def zap_context(msg):
'''Removes translation context from message'''
return msg.split('|', 1)[1]
def C_(msg):
'''Translates and removes context from message'''
return _(msg).split('|', 1)[1]
def indent_xml(elem, level=0):
# in-place prettyprint formatter

View File

@ -26,6 +26,7 @@ import string
from quixote import get_request
import qommon.misc
from qommon.misc import C_
from qommon.storage import StorableObject
from qommon.form import *
from qommon import emails, get_cfg, get_logger
@ -390,7 +391,7 @@ class Workflow(StorableObject):
def get_list_of_roles(self, include_logged_in_users=True):
t = []
t.append(('_submitter', misc.zap_context(_('role|User'))))
t.append(('_submitter', C_('role|User')))
for workflow_role in self.roles.items():
t.append(workflow_role)
if include_logged_in_users:
@ -1068,7 +1069,7 @@ def get_role_translation_label(workflow, role_id):
if role_id == logged_users_role().id:
return logged_users_role().name
if role_id == '_submitter':
return misc.zap_context(_('role|User'))
return C_('role|User')
if str(role_id).startswith('_'):
return workflow.roles.get(role_id)
else: