Changes between Version 18 and Version 19 of CookBook/PluginL10N
- Timestamp:
- Jun 12, 2010, 8:55:45 PM (14 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
CookBook/PluginL10N
v18 v19 40 40 === Prepare plugin code === 41 41 ==== Import i18n/l10n helper programs ==== 42 Pick a reasonably unique name for the catalog, e.g. ** 'foo' **42 Pick a reasonably unique name for the domain, e.g. ** 'foo' ** 43 43 44 44 This will be the basename for the various translation catalog files … … 64 64 - `'add_domain'`: register the catalog file for the bound domain 65 65 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:66 To 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: 67 67 {{{#!python 68 68 def __init__(self): … … 118 118 In 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. 119 119 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.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 extract_messages] in Babel's documentation). So you will want to leave that one untouched. 121 121 122 122 ==== Mark text for extraction ==== … … 136 136 137 137 ==== 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`: 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. 139 140 See 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 146 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`: 141 147 {{{#!diff 142 148 diff --git a/setup.py b/setup.py … … 148 154 149 155 +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 151 160 + extractors = [ 152 161 + ('**.py', 'python', None), … … 184 193 {{{#!comment 185 194 This 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 196 Indeed, I suspect the final version of this section will be quite different... 197 }}} 198 Note 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]] 188 199 Note 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. 189 200 190 You'll have to start with marking text to get it handled by translation helper programs, so a line that was191 {{{192 var answer = confirm("Submit ticket?");193 }}}194 before, will read like195 {{{196 var answer = confirm("${_('Submit ticket?')}");197 }}}198 afterwards.199 200 Wrap whole code containing marked text with a text replacement function like201 {{{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 save214 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 }}}233 201 234 202 ==== Register message catalog files for packaging ==== … … 325 293 since good l10n has more of a transcription than pure translation word by word. 326 294 It'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.295 This 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. 328 296 329 297 Details on that matter tend to become religious, so let's stop here. 330 298 331 299 == Related resources == 300 301 See TracL10N and more specifically TracL10N#ForDevelopers, which contains general tips that are also valid for plugin translation. 332 302 333 303 [=#a1 ^1^] http://en.wikipedia.org/wiki/Internationalization_and_localization - Internationalization and localization[[BR]]