use named substitutions in i18n strings
authorAdrien Di Mascio <Adrien.DiMascio@logilab.fr>
Thu, 13 Nov 2008 12:34:36 +0100
changeset 62 ef06f71533d9
parent 61 081078d5b422
child 63 805a9f3ac748
use named substitutions in i18n strings
common/mixins.py
server/hooks.py
web/views/baseforms.py
web/widgets.py
--- a/common/mixins.py	Thu Nov 13 12:33:18 2008 +0100
+++ b/common/mixins.py	Thu Nov 13 12:34:36 2008 +0100
@@ -289,8 +289,10 @@
         done = set()
     entity = view.entity(row, col)
     if entity.eid in done:
-        msg = entity.req._('loop in %s relation (%s)'
-                           % (entity.tree_attribute, entity.eid))
+        msg = entity.req._('loop in %(rel)s relation (%(eid)s)') % {
+            'rel': entity.tree_attribute,
+            'eid': entity.eid
+            }
         return None, msg
     done.add(entity.eid)
     return done, entity
--- a/server/hooks.py	Thu Nov 13 12:33:18 2008 +0100
+++ b/server/hooks.py	Thu Nov 13 12:34:36 2008 +0100
@@ -245,9 +245,10 @@
             return
         if self.session.unsafe_execute(*self._rql()).rowcount < 1:
             etype = self.session.describe(self.eid)[0]
-            msg = self.session._('at least one relation %s is required on %s(%s)')
-            raise ValidationError(self.eid, {self.rtype: msg % (self.rtype,
-                                                                etype, self.eid)})
+            msg = self.session._('at least one relation %(rtype)s is required on %(etype)s (%(eid)s)')
+            raise ValidationError(self.eid, {self.rtype: msg % {'rtype': self.rtype,
+                                                                'etype': etype,
+                                                                'eid': self.eid}})
     
     def commit_event(self):
         pass
--- a/web/views/baseforms.py	Thu Nov 13 12:33:18 2008 +0100
+++ b/web/views/baseforms.py	Thu Nov 13 12:34:36 2008 +0100
@@ -101,8 +101,10 @@
         _ = self.req._
         self.w(self.error_message())
         self.w(u'<h4>%s %s</h4>\n' % (_(transition.name), entity.view('oneline')))
-        self.w(u'<p>%s</p>\n' % (_('status will change from %s to %s')
-                               % (_(state.name), _(dest.name))))
+        msg = _('status will change from %(st1)s to %(st2)s') % {
+            'st1': _(state.name),
+            'st2': _(dest.name)}
+        self.w(u'<p>%s</p>\n' % msg)
         self.w(u'<form action="%s" onsubmit="return freezeFormButtons(\'entityForm\');" method="post" id="entityForm">\n'
                % self.build_url('edit'))
         self.w(u'<div id="progress">%s</div>' % _('validating...'))
--- a/web/widgets.py	Thu Nov 13 12:33:18 2008 +0100
+++ b/web/widgets.py	Thu Nov 13 12:34:36 2008 +0100
@@ -783,8 +783,10 @@
     def render_example(self, req):
         formatstr1 = req.property_value('ui.datetime-format')
         formatstr2 = req.property_value('ui.date-format')
-        return req._('%s, or without time: %s') % (now().strftime(formatstr1),
-                                                   now().strftime(formatstr2))
+        return req._('%(fmt1)s, or without time: %(fmt2)s') % {
+            'fmt1': now().strftime(formatstr1),
+            'fmt2': now().strftime(formatstr2),
+            }