Edgewall Software

Changes between Version 18 and Version 19 of CookBook/PluginL10N


Ignore:
Timestamp:
Jun 12, 2010, 8:55:45 PM (14 years ago)
Author:
Christian Boos
Comment:

Talk about translation of Genshi templates, updated code to use get_l10n_cmdclass and some more review. Javascript translation follows.

Legend:

Unmodified
Added
Removed
Modified
  • CookBook/PluginL10N

    v18 v19  
    4040=== Prepare plugin code ===
    4141==== Import i18n/l10n helper programs ====
    42 Pick a reasonably unique name for the catalog, e.g. ** 'foo' **
     42Pick a reasonably unique name for the domain, e.g. ** 'foo' **
    4343
    4444This will be the basename for the various translation catalog files
     
    6464 - `'add_domain'`: register the catalog file for the bound domain
    6565
    66 To inform Trac about where the plugin's message catalogs can be found, you'll have to call the `'add_domain'` obtained via `domain_functions`. One place to do this is in the `__init__` function of your plugin's main component, like this:
     66To inform Trac about where the plugin's message catalogs can be found, you'll have to call the `add_domain` function obtained via `domain_functions` as shown above. One place to do this is in the `__init__` function of your plugin's main component, like this:
    6767{{{#!python
    6868    def __init__(self):
     
    118118In the `extract_messages` section there is just one more lines you may like to change: `msgid_bugs_address`. To allow for direct feedback regarding your i18n work add a valid e-mail address or a mailing list dedicated to translation issues there.
    119119
    120 The `add_comments` line simply lists the tags in the comments surrounding the calls to the translation functions in the source code that have to be propagated to the catalogs (see Babel:wiki:Documentation/0.9/setup.html#extract-messages). So you will want to leave that one untouched.
     120The `add_comments` line simply lists the tags in the comments surrounding the calls to the translation functions in the source code that have to be propagated to the catalogs (see [Babel:wiki:Documentation/0.9/setup.html#extract-messages extract_messages] in Babel's documentation). So you will want to leave that one untouched.
    121121
    122122==== Mark text for extraction ====
     
    136136
    137137==== Text extraction from Genshi templates ====
    138 Message extraction for Genshi templates should be done auto-magically. However there is the markup `i18n:msg` available to ensure extraction even from less common tags. For a real-world example have a look at [changeset:9542/trunk/trac/ticket/templates/ Trac SVN changeset r9542] for marking previously undetected text in templates. But there are not all issues settled with some special cases for message extraction from Genshi templates, i.e. see [g:ticket:385 Genshi ticket 385]. You should search for similar issues you may encounter while trying to handle plugin templates.
    139 
    140 But Babel only does extract from Python scripts by default. To extract messages from Genshi templates as well, you'll have to declare the needed extractors in `setup.py`:
     138Message extraction for Genshi templates should be done auto-magically. However there is the markup `i18n:msg` available to ensure extraction even from less common tags. For a real-world example have a look at [changeset:9542/trunk/trac/ticket/templates/ Trac SVN changeset r9542] for marking previously undetected text in templates.
     139
     140See Genshi documentation on this topic, [http://genshi.edgewall.org/wiki/Documentation/0.6.x/i18n.html Internationalization and Localization].
     141
     142 //But there are not all issues settled with some special cases for message extraction from Genshi templates, i.e. see [g:ticket:385 Genshi ticket 385]. You should search for similar issues you may encounter while trying to handle plugin templates.
     143
     144===== Extraction
     145
     146Babel only does extract from Python scripts by default. To extract messages from Genshi templates as well, you'll have to declare the needed extractors in `setup.py`:
    141147{{{#!diff
    142148diff --git a/setup.py b/setup.py
     
    148154
    149155+extra = {}
    150 +try:
     156+from trac.util.dist import get_l10n_cmdclass
     157+cmdclass = get_l10n_cmdclass()
     158+if cmdclass: # Yay, Babel is there, we've got something to do!
     159+    extra['cmdclass'] = cmdclass
    151160+    extractors = [
    152161+        ('**.py',                'python', None),
     
    184193{{{#!comment
    185194This is taken largely from studying code in http://trac-hacks.org/wiki/TracTicketTemplatePlugin. Some conclusions may be plain wrong, since I had not time to carefully investigate and verify this.
    186 }}}
    187 Note 1: This section has some preliminary content. Please handle with care and contribute your/any better knowledge on the subject. And look at #6353 please, since it seems to prepare a official solution for Trac and Trac plugins reducing the code changes to almost the same level as for file types mentioned before.[[BR]]
     195
     196Indeed, I suspect the final version of this section will be quite different...
     197}}}
     198Note 1: This section had some preliminary content. Please handle with care and contribute your/any better knowledge on the subject. And look at #6353 please, since it seems to prepare a official solution for Trac and Trac plugins reducing the code changes to almost the same level as for file types mentioned before.[[BR]]
    188199Note 2: Dedicated helper functions were introduced to Trac trunk recently (see r9758, '''r9763''' and r9764). Following content needs to be revised to make use of this new native support for Trac plugins as well.
    189200
    190 You'll have to start with marking text to get it handled by translation helper programs, so a line that was
    191 {{{
    192     var answer = confirm("Submit ticket?");
    193 }}}
    194 before, will read like
    195 {{{
    196     var answer = confirm("${_('Submit ticket?')}");
    197 }}}
    198 afterwards.
    199 
    200 Wrap whole code containing marked text with a text replacement function like
    201 {{{
    202 $.fn.extend({
    203         foo: function() {
    204         function _(message){ return message; }
    205         messages = [
    206             _('Submit ticket?'),
    207         ]
    208 
    209         ...
    210 
    211         function onFormSubmit(evt) {
    212             if (evt.type == "submit"){
    213                 // confirm to save
    214                 if ($("#ticket_status").length == 0 || $.trim($("#ticket_status$
    215                     var answer = confirm("${_('Submit ticket?')}");
    216                     if (!answer) {
    217                         return false;
    218                     }
    219                 }
    220             }
    221         }
    222 
    223         ...
    224 
    225 });
    226 
    227 }}}
    228 
    229 To extract messages from Java scripts, you'll have to extend  `setup.py` like shown in previous chapter for Genshi templates, but declare yet another extractor by listing it within the `extractors` list:
    230 {{{
    231         ('**/templates/**.js',   'javascript', None),
    232 }}}
    233201
    234202==== Register message catalog files for packaging ====
     
    325293since good l10n has more of a transcription than pure translation word by word.
    326294It's encouraging to see the raise of native words for such terms like changeset, ticket and repository in different languages.
    327 This will help Trac to not only fulfill it's promise to help project teams focusing on their work but even extend it's use to project management in general, where use of native language is much more common or even required in contrast to the traditional software development.
     295This will help Trac to not only fulfill its promise to help project teams focusing on their work but even extend its use to project management in general, where use of native language is much more common or even required in contrast to the traditional software development.
    328296
    329297Details on that matter tend to become religious, so let's stop here.
    330298
    331299== Related resources ==
     300
     301See TracL10N and more specifically TracL10N#ForDevelopers, which contains general tips that are also valid for plugin translation.
    332302
    333303[=#a1 ^1^] http://en.wikipedia.org/wiki/Internationalization_and_localization - Internationalization and localization[[BR]]