comparison doc/developers.txt @ 2832:47766d279878

Web UI i18n
author Alexander Smishlajev <a1s@users.sourceforge.net>
date Tue, 26 Oct 2004 10:38:25 +0000
parents 6e9bd67fefa9
children ad4fb8a14a97
comparison
equal deleted inserted replaced
2830:9ab32261216b 2832:47766d279878
1 ================== 1 ==================
2 Developing Roundup 2 Developing Roundup
3 ================== 3 ==================
4 4
5 :Version: $Revision: 1.12 $ 5 :Version: $Revision: 1.13 $
6 6
7 .. note:: 7 .. note::
8 The intended audience of this document is the developers of the core 8 The intended audience of this document is the developers of the core
9 Roundup code. If you just wish to alter some behaviour of your Roundup 9 Roundup code. If you just wish to alter some behaviour of your Roundup
10 installation, see `customising roundup`_. 10 installation, see `customising roundup`_.
198 to always use *named* format specifiers:: 198 to always use *named* format specifiers::
199 199
200 _('Index of %(classname)s') % locals() 200 _('Index of %(classname)s') % locals()
201 201
202 This helps translators to better understand the context of the 202 This helps translators to better understand the context of the
203 message and, in Python, remove format specifier altogether (which 203 message and, with Python formatting, remove format specifier altogether
204 is sometimes useful, especially in singular cases of `Plural Forms`_). 204 (which is sometimes useful, especially in singular cases of `Plural Forms`_).
205 205
206 When there is more than one format specifier in the translatable 206 When there is more than one format specifier in the translatable
207 format string, named format specifiers *must* be used almost always, 207 format string, named format specifiers **must** be used almost always,
208 because translation may require different order of items. 208 because translation may require different order of items.
209 209
210 It is better to *not* mark for translation strings that are not 210 It is better to *not* mark for translation strings that are not
211 locale-dependent, as this makes it more difficult to keep track 211 locale-dependent, as this makes it more difficult to keep track
212 of translation completeness. For example, string ``</ol></body></html>`` 212 of translation completeness. For example, string ``</ol></body></html>``
213 (in ``index()`` method of the request handler in ``roundup_server`` 213 (in ``index()`` method of the request handler in ``roundup_server``
214 script) has no human readable parts at all, and needs no translations. 214 script) has no human readable parts at all, and needs no translations.
215 Such strings are left untranslated in PO files, and are reported 215 Such strings are left untranslated in PO files, and are reported
216 as such by PO status checkers (e.g. ``msgfmt --statistics``). 216 as such by PO status checkers (e.g. ``msgfmt --statistics``).
217 217
218 Need some note about i18n in TAL here... this link has good info:
219
220 http://plone.org/documentation/howto/I18nForDevelopers
221
222
223 Command Line Interfaces 218 Command Line Interfaces
224 ~~~~~~~~~~~~~~~~~~~~~~~ 219 ~~~~~~~~~~~~~~~~~~~~~~~
225 220
226 Scripts and routines run from the command line use "static" language 221 Scripts and routines run from the command line use "static" language
227 defined by environment variables recognized by ``gettext`` module 222 defined by environment variables recognized by ``gettext`` module
243 238
244 Translations for messages whose grammatical depends on a number 239 Translations for messages whose grammatical depends on a number
245 must be done by ``ngettext()`` function:: 240 must be done by ``ngettext()`` function::
246 241
247 print ngettext("Nuked %i file", "Nuked %i files", number_of_files_nuked) 242 print ngettext("Nuked %i file", "Nuked %i files", number_of_files_nuked)
248
249 User Interfaces
250 ~~~~~~~~~~~~~~~
251
252 *(not yet)*
253
254 This includes Mail Gateway and Web User Interfaces, where translation
255 depends on the language of current Roundup User. These translations
256 will be done by the tracker configuration object. Translatable strings
257 will be automatically marked by calls to the ``_()`` and ``ngettext()``
258 methods of that object::
259
260 self.config._("This message is translated")
261 self.config.ngettext("Nuked %i file", "Nuked %i files",
262 number_of_files_nuked)
263 243
264 Deferred Translations 244 Deferred Translations
265 ~~~~~~~~~~~~~~~~~~~~~ 245 ~~~~~~~~~~~~~~~~~~~~~
266 246
267 Sometimes translatable strings appear in the source code in untranslated 247 Sometimes translatable strings appear in the source code in untranslated
286 266
287 .. [#note_admin.py] In current Roundup sources, this feature is 267 .. [#note_admin.py] In current Roundup sources, this feature is
288 extensively used in the ``admin`` module using method docstrings 268 extensively used in the ``admin`` module using method docstrings
289 as help messages. 269 as help messages.
290 270
271 Web User Interface
272 ~~~~~~~~~~~~~~~~~~
273
274 For Web User Interface, translation services are provided by Client
275 object. Action classes have methods ``_()`` and ``gettext()``,
276 delegating translation to the Client instance. In HTML templates,
277 translator object is available as context variable ``i18n``.
278
279 HTML templates have special markup for translatable strings.
280 The syntax for this markup is defined on `ZPTInternationalizationSupport`_
281 page. Roundup translation service currently ignores values for
282 ``i18n:domain``, ``i18n:source`` and ``i18n:target``.
283
284 Template markup examples:
285
286 * simplest case::
287
288 <div i18n:translate="">
289 Say
290 no
291 more!
292 </div>
293
294 this will result in msgid ``"Say no more!"``, with all leading and
295 trailing whitespace stripped, and inner blanks replaced with single
296 space character.
297
298 * using variable slots::
299
300 <div i18n:translate="">
301 And now...<br/>
302 No.<span tal:replace="number" i18n:name="slideNo" /><br/>
303 THE LARCH
304 </div>
305
306 Msgid will be: ``"And now...<br /> No.${slideNo}<br /> THE LARCH"``.
307 Template rendering will use context variable ``number`` (you may use
308 any expression) to put instead of ``${slideNo}`` in translation.
309
310 * attribute translation::
311
312 <button name="btn_wink" value=" Wink " i18n:attributes="value" />
313
314 will translate the caption (and return value) for the "wink" button.
315
316 * explicit msgids. Sometimes it may be useful to specify msgid
317 for the element translation explicitely, like this::
318
319 <span i18n:translate="know what i mean?">this text is ignored</span>
320
321 When rendered, element contents will be replaced by translation
322 of the string specified in ``i18n:translate`` attribute.
323
324 * ``i18n`` in `TALES`_. You may translate strings in `TALES`_ python
325 expressions::
326
327 <span tal:replace="python: i18n.gettext('Oh, wicked.')" />
328
329 * plural forms. There is no markup for plural forms in `TAL`_ i18n.
330 You must use python expression for that::
331
332 <span tal:replace="python: i18n.ngettext(
333 'Oh but it\'s only %i shilling.',
334 'Oh but it\'s only %i shillings.',
335 fine) % fine"
336 />
337
291 Extracting Translatable Messages 338 Extracting Translatable Messages
292 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 339 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
293 340
294 The most common tool for message extraction is ``xgettext`` utility 341 The most common tool for message extraction is ``xgettext`` utility
295 from `GNU gettext package`_. Unfortunately, this utility has no means 342 from `GNU gettext package`_. Unfortunately, this utility has no means
304 Latest Message Template File is kept in `Roundup CVS`_ and distributed 351 Latest Message Template File is kept in `Roundup CVS`_ and distributed
305 with `Roundup Source`_. If you wish to rebuild the template yourself, 352 with `Roundup Source`_. If you wish to rebuild the template yourself,
306 make sure that you have both ``xpot`` and ``xgettext`` installed and 353 make sure that you have both ``xpot`` and ``xgettext`` installed and
307 just run ``gmake`` (or ``make``, if you are on a `GNU`_ system like 354 just run ``gmake`` (or ``make``, if you are on a `GNU`_ system like
308 `linux`_ or `cygwin`_) in the ``locale`` directory. 355 `linux`_ or `cygwin`_) in the ``locale`` directory.
356
357 For on-site i18n, Roundup provides command-line utility::
358
359 roundup-gettext <tracker_home>
360
361 extracting translatable messages from tracker's html templates.
362 This utility creates message template file ``messages.pot`` in
363 ``locale`` subdirectory of the tracker home directory. Translated
364 messages may be put in *locale*.po files (where *locale* is selected
365 locale name) in the same directory, e.g.: ``locale/ru.po``.
366 These message catalogs are searched prior to system-wide translations
367 kept in the ``share`` directory.
309 368
310 Translating Messages 369 Translating Messages
311 ^^^^^^^^^^^^^^^^^^^^ 370 ^^^^^^^^^^^^^^^^^^^^
312 371
313 Gettext Message File (`PO`_ file) is a plain text file, that can be created 372 Gettext Message File (`PO`_ file) is a plain text file, that can be created
368 427
369 This way, message translators can check their `PO`_ files without 428 This way, message translators can check their `PO`_ files without
370 extracting strings from source. (Note: String extraction requires 429 extracting strings from source. (Note: String extraction requires
371 additional utility that is not part of `GNU gettext`_. See `Extracting 430 additional utility that is not part of `GNU gettext`_. See `Extracting
372 Translatable Messages`_.) 431 Translatable Messages`_.)
432
433 At run time, Roundup automatically compiles message catalogs whenever
434 `PO`_ file is changed.
373 435
374 ----------------- 436 -----------------
375 437
376 Back to `Table of Contents`_ 438 Back to `Table of Contents`_
377 439
403 .. _Roundup CVS: http://sourceforge.net/cvs/?group_id=31577 465 .. _Roundup CVS: http://sourceforge.net/cvs/?group_id=31577
404 .. _Roundup Source: 466 .. _Roundup Source:
405 .. _Roundup source distribution: 467 .. _Roundup source distribution:
406 .. _Roundup binary distribution: 468 .. _Roundup binary distribution:
407 http://sourceforge.net/project/showfiles.php?group_id=31577 469 http://sourceforge.net/project/showfiles.php?group_id=31577
470 .. _TAL:
471 .. _Template Attribute Language:
472 http://dev.zope.org/Wikis/DevSite/Projects/ZPT/TAL%20Specification%201.4
473 .. _TALES:
474 .. _Template Attribute Language Expression Syntax:
475 http://dev.zope.org/Wikis/DevSite/Projects/ZPT/TALES%20Specification%201.3
408 .. _vim: http://www.vim.org/ 476 .. _vim: http://www.vim.org/
477 .. _ZPTInternationalizationSupport: http://dev.zope.org/Wikis/DevSite/Projects/ComponentArchitecture/ZPTInternationalizationSupport

Roundup Issue Tracker: http://roundup-tracker.org/