Edgewall Software

Changeset 1111 for trunk


Ignore:
Timestamp:
Apr 19, 2010, 1:45:40 PM (13 years ago)
Author:
cmlenz
Message:

More i18n doc improvements.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/doc/i18n.txt

    r1110 r1111  
    223223             single message ineffective.
    224224
    225 ``i18n:comment``
    226 ----------------
    227 
    228 The ``i18n:comment`` directive can be used to supply a comment for the
    229 translator. For example, if a template snippet is not easily understood
    230 outside of its context, you can add a translator comment to help the
    231 translator understand in what context the message will be used:
    232 
    233 .. code-block:: genshi
    234 
    235   <p i18n:msg="name" i18n:comment="Link to the relevant support site">
    236     Please visit <a href="${site.url}">${site.name}</a> for help.
    237   </p>
    238 
    239 This comment will be extracted together with the message itself, and will
    240 commonly be placed along the message in the message catalog, so that it is
    241 easily visible to the person doing the translation.
    242 
    243 This directive has no impact on how the template is rendered, and is ignored
    244 outside of the extraction process.
    245 
    246 
    247 -------------
    248 Pluralization
    249 -------------
     225``i18n:choose``, ``i18n:singular``, ``i18n:plural``
     226---------------------------------------------------
    250227
    251228Translatable strings that vary based on some number of objects, such as “You
     
    253230in particular when you consider that different languages have different rules
    254231for pluralization. For example, while English and most western languages have
    255 two plural forms (one for ``n=1`` and one for ``n<>1``), Welsh has five
     232two plural forms (one for ``n=1`` and an other for ``n<>1``), Welsh has five
    256233different plural forms, while Hungarian only has one.
    257234
     
    264241
    265242Genshi provides a variant of the ``i18n:msg`` directive described above that
    266 allows choosing the proper plural form based on some variable.
    267 
    268 ``i18n:choose``, ``i18n:singular``, ``i18n:plural``
    269 ---------------------------------------------------
    270 
    271 TODO
    272 
    273 -------------------
    274 Translation Domains
    275 -------------------
     243allows choosing the proper plural form based on the numeric value of a given
     244variable. The pluralization support is implemented in a set of three
     245directives that must be used together: ``i18n:choose``, ``i18n:singular``, and
     246``i18n:plural``.
     247
     248The ``i18n:choose`` directive is used to set up the context of the message: it
     249simply wraps the singular and plural variants.
     250
     251The value of this directive is split into two parts: the first is the
     252*numeral*, a Python expression that evaluates to a number to determine which
     253plural form should be chosen. The second part, separated by a semicolon, lists
     254the parameter names. This part is equivalent to the value of the ``i18n:msg``
     255directive.
     256
     257For example:
     258
     259.. code-block:: genshi
     260
     261  <p i18n:choose="len(messages); num">
     262    <i18n:singular>You have <b>${len(messages)}</b> new message.</i18n:singular>
     263    <i18n:plural>You have <b>${len(messages)}</b> new messages.</i18n:plural>
     264  </p>
     265
     266All three directives can be used either as elements or attribute. So the above
     267example could also be written as follows:
     268
     269.. code-block:: genshi
     270
     271  <i18n:choose numeral="len(messages)" params="num">
     272    <p i18n:singular="">You have <b>${len(messages)}</b> new message.</p>
     273    <p i18n:plural="">You have <b>${len(messages)}</b> new messages.</p>
     274  </i18n:choose>
     275
     276When used as an element, the two parts of the ``i18n:choose`` value are split
     277into two different attributes: ``numeral`` and ``params``. The
     278``i18n:singular`` and ``i18n:plural`` directives do not require or support any
     279value (or any extra attributes).
     280
     281--------------------
     282Comments and Domains
     283--------------------
     284
     285``i18n:comment``
     286----------------
     287
     288The ``i18n:comment`` directive can be used to supply a comment for the
     289translator. For example, if a template snippet is not easily understood
     290outside of its context, you can add a translator comment to help the
     291translator understand in what context the message will be used:
     292
     293.. code-block:: genshi
     294
     295  <p i18n:msg="name" i18n:comment="Link to the relevant support site">
     296    Please visit <a href="${site.url}">${site.name}</a> for help.
     297  </p>
     298
     299This comment will be extracted together with the message itself, and will
     300commonly be placed along the message in the message catalog, so that it is
     301easily visible to the person doing the translation.
     302
     303This directive has no impact on how the template is rendered, and is ignored
     304outside of the extraction process.
    276305
    277306``i18n:domain``
    278307---------------
    279308
    280 TODO
     309In larger projects, message catalogs are commonly split up into different
     310*domains*. For example, you might have a core application domain, and then
     311separate domains for extensions or libraries.
     312
     313Genshi provides a directive called ``i18n:domain`` that lets you choose the
     314translation domain for a particular scope. For example:
     315
     316.. code-block:: genshi
     317
     318  <div i18n:domain="examples">
     319    <p>Hello, world!</p>
     320  </div>
     321
    281322
    282323Extraction
  • trunk/genshi/filters/i18n.py

    r1105 r1111  
    294294    </html>
    295295
    296     When used as a directive and not as an attribute:
     296    When used as a element and not as an attribute:
    297297
    298298    >>> tmpl = MarkupTemplate('''\
Note: See TracChangeset for help on using the changeset viewer.