Modify

Opened 3 years ago

Last modified 2 years ago

#9192 new defect

Better i18n code for TracAnnouncer

Reported by: jun66j5 Owned by: hasienda
Priority: normal Component: AnnouncerPlugin
Severity: normal Keywords: i18n
Cc: doki_pen, jordi Trac Release: 0.12

Description

In prefs_announcer_manage_subscriptions.html, extract_messages command extracts a generic word rules. The term will be difficult to translate into Japanese. I think it should use i18n:msg in the element like the following.

  • announcer/templates/prefs_announcer_manage_subscriptions.html

    diff --git a/announcer/templates/prefs_announcer_manage_subscriptions.html b/announcer/templates/prefs_announcer_manage_subscription
    index 242bb71..e3de7bb 100644
    a b  
    1919    </p>
    2020    <div class="announcer_preference_box">
    2121      <div py:for="distributor, rules in data['rules'].iteritems()" class="ruleset">
    22           <div class="announcer_preference_title">
     22          <div class="announcer_preference_title" i18n:msg="distributor">
    2323              ${distributor} rules
    2424          </div>
    2525          <div class="announcer_preference_options">

In ticket_email_mimic.html, the template has no i18n:* derectives and it seems that the plugin always sends English notification mail. If we don't need to translate, we can use xml:lang="en" which isn't extracted from the element and the children.

  • announcer/templates/ticket_email_mimic.html

    diff --git a/announcer/templates/ticket_email_mimic.html b/announcer/templates/ticket_email_mimic.html
    index b5ed455..fd2124c 100644
    a b  
    11<html xmlns="http://www.w3.org/1999/xhtml"
    22     xmlns:py="http://genshi.edgewall.org/"
    3      xmlns:xi="http://www.w3.org/2001/XInclude">
     3     xmlns:xi="http://www.w3.org/2001/XInclude"
     4     xml:lang="en">
    45  <head>
    56    <title>#${ticket.id}: ${ticket['summary']}</title>
    67

Attachments (0)

Change History (8)

comment:1 Changed 3 years ago by jun66j5

And all text templates use NewTextTemplate syntax in the plugin. It should set genshi.template:NewTextTemplate in message_extractors parameter of setup.py.

See trac:changeset:8999, http://genshi.edgewall.org/browser/branches/stable/0.6.x/genshi/template/text.py#L16.

  • setup.py

    diff --git a/setup.py b/setup.py
    index 7289849..02608b2 100644
    a b try: 
    4444        ('**.py',                'python', None),
    4545        ('**/templates/**.html', 'genshi', None),
    4646        ('**/templates/**.txt',  'genshi', {
    47             'template_class': 'genshi.template:TextTemplate'
     47            'template_class': 'genshi.template:NewTextTemplate'
    4848        }),
    4949    ]
    5050    extra['message_extractors'] = {

comment:2 Changed 3 years ago by jun66j5

This plugin passes formatted string to gettext method. I think that codes should be as the following patch.

  • announcer/distributors/mail.py

    diff --git a/announcer/distributors/mail.py b/announcer/distributors/mail.py
    index 3a9f6d6..122ad92 100644
    a b class EmailDistributor(Component): 
    408408            self._charset.input_codec = None
    409409            self._charset.output_charset = 'ascii'
    410410        else:
    411             raise TracError(_('Invalid email encoding setting: %s'%pref))
     411            raise TracError(_("Invalid email encoding setting: %(encoding)s",
     412                              encoding=pref))
    412413
    413414    def _message_id(self, realm):
    414415        """Generate a predictable, but sufficiently unique message ID."""
  • announcer/locale/de/LC_MESSAGES/announcer.po

    diff --git a/announcer/locale/de/LC_MESSAGES/announcer.po b/announcer/locale/de/LC_MESSAGES/announcer.po
    index a850ce7..eaa0158 100644
    a b msgstr "Ticket-Abonnement basierend auf Komponenten" 
    7777
    7878#: announcer/subscribers.py:526
    7979#, python-format
    80 msgid "notify me when I'm listed in any of the (%s) fields"
     80msgid "notify me when I'm listed in any of the (%(fields)s) fields"
    8181msgstr ""
    82 "Benachrichtigung an mich, wenn ich in einem der (%s) Felder eingetragen "
    83 "bin"
     82"Benachrichtigung an mich, wenn ich in einem der (%(fields)s) Felder "
     83"eingetragen bin"
    8484
    8585#: announcer/subscribers.py:583
    8686msgid "notify me on ticket changes in one of my subscribed groups"
    msgstr "Allgemeine Wiki-Abonnements" 
    132132
    133133#: announcer/distributors/mail.py:411
    134134#, python-format
    135 msgid "Invalid email encoding setting: %s"
    136 msgstr "Ungültige Einstellung der E-Mail-Codierung: %s"
     135msgid "Invalid email encoding setting: %(encoding)s"
     136msgstr "Ungültige Einstellung der E-Mail-Codierung: %(encoding)s"
    137137
    138138#: announcer/distributors/mail.py:444
    139139msgid "EmailDistributor crypto operaton successful."
  • announcer/locale/ru/LC_MESSAGES/announcer.po

    diff --git a/announcer/locale/ru/LC_MESSAGES/announcer.po b/announcer/locale/ru/LC_MESSAGES/announcer.po
    index 75725ec..2869d78 100644
    a b msgstr "Подписки по компонентам" 
    7575
    7676#: announcer/subscribers.py:526
    7777#, python-format
    78 msgid "notify me when I'm listed in any of the (%s) fields"
     78msgid "notify me when I'm listed in any of the (%(fields)s) fields"
    7979msgstr ""
    8080
    8181#: announcer/subscribers.py:583
    msgstr "Общие извещения Wiki" 
    118118
    119119#: announcer/distributors/mail.py:411
    120120#, python-format
    121 msgid "Invalid email encoding setting: %s"
    122 msgstr "Неправильный выбор почтовой кодировки: %s"
     121msgid "Invalid email encoding setting: %(encoding)s"
     122msgstr "Неправильный выбор почтовой кодировки: %(encoding)s"
    123123
    124124#: announcer/distributors/mail.py:444
    125125msgid "EmailDistributor crypto operaton successful."
  • announcer/locale/zh_CN/LC_MESSAGES/announcer.po

    diff --git a/announcer/locale/zh_CN/LC_MESSAGES/announcer.po b/announcer/locale/zh_CN/LC_MESSAGES/announcer.po
    index fe120dd..735e2bd 100644
    a b msgstr "" 
    7575
    7676#: announcer/subscribers.py:526
    7777#, python-format
    78 msgid "notify me when I'm listed in any of the (%s) fields"
     78msgid "notify me when I'm listed in any of the (%(fields)s) fields"
    7979msgstr ""
    8080
    8181#: announcer/subscribers.py:583
    msgstr "高级Wiki订阅" 
    118118
    119119#: announcer/distributors/mail.py:411
    120120#, python-format
    121 msgid "Invalid email encoding setting: %s"
    122 msgstr "无效的邮件编码设置: %s"
     121msgid "Invalid email encoding setting: %(encoding)s"
     122msgstr "无效的邮件编码设置: %(encoding)s"
    123123
    124124#: announcer/distributors/mail.py:444
    125125msgid "EmailDistributor crypto operaton successful."
  • announcer/subscribers.py

    diff --git a/announcer/subscribers.py b/announcer/subscribers.py
    index 67f4918..7050913 100644
    a b class TicketCustomFieldSubscriber(Component): 
    522522
    523523    def description(self):
    524524        if self.custom_cc_fields:
    525             return _("notify me when I'm listed in any of the (%s) "
    526                      "fields"%(','.join(self.custom_cc_fields),))
     525            return _("notify me when I'm listed in any of the (%(fields)s) "
     526                     "fields",
     527                     fields=','.join(self.custom_cc_fields))
    527528
    528529    def default_subscriptions(self):
    529530        if self.custom_cc_fields:

comment:3 Changed 3 years ago by jordi

  • Cc jordi added

comment:4 follow-up: Changed 3 years ago by hasienda

(In [10920]) AnnouncerPlugin: Refactor i18n in a more compatible way, refs #7314, #7666, #7380, #8062 and #9192.

Lessons learned meanwhile with other plugins, so the code applied here has actually been tested and proven to work. This reverts [8409] effectively, but let's keep proper Babel and Trac versions for i18n explicitly as an extra.

After these changes the plugin finally loads cleanly in Trac 0.11 again.

comment:5 Changed 3 years ago by rjollos

I've switched from running the 0.11 branch to the Announcer trunk @ r10920. I'll report if I find any issues on 0.11.7 (though I'll be upgrading to 0.12.2 soon).

comment:6 in reply to: ↑ 4 Changed 3 years ago by rjollos

Replying to hasienda:

After these changes the plugin finally loads cleanly in Trac 0.11 again.

I think I didn't read your message carefully enough. I was seeing some error about environment object not having attribute with_transaction so I had to roll-back. Since I'm moving to 0.12.2 soon, I might just wait to upgrade.

comment:7 follow-up: Changed 3 years ago by hasienda

Sorry, I'm still in the process of sorting out code for 0.11 and 0.13 . I.e. to get the most out of the new decorator-based connections, we should really use read-only with_query(db) as much as possible.

comment:8 in reply to: ↑ 7 Changed 2 years ago by hasienda

  • Cc doki_pen added; hasienda removed
  • Keywords i18n added
  • Owner changed from doki_pen to hasienda

Replying to hasienda:

Sorry, I'm still in the process of sorting out code for 0.11 and 0.13 . I.e. to get the most out of the new decorator-based connections, we should really use read-only with_query(db) as much as possible.

I'll really have to deal with this first, because it even blocks use with Trac-1.0 right now. I18n will be next, thanks for your patience.

Add Comment

Modify Ticket

Action
as new The owner will remain hasienda.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.