- Timestamp:
- Apr 19, 2010, 1:45:40 PM (13 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
-
doc/i18n.txt (modified) (3 diffs)
-
genshi/filters/i18n.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/doc/i18n.txt
r1110 r1111 223 223 single message ineffective. 224 224 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 --------------------------------------------------- 250 227 251 228 Translatable strings that vary based on some number of objects, such as “You … … 253 230 in particular when you consider that different languages have different rules 254 231 for pluralization. For example, while English and most western languages have 255 two plural forms (one for ``n=1`` and onefor ``n<>1``), Welsh has five232 two plural forms (one for ``n=1`` and an other for ``n<>1``), Welsh has five 256 233 different plural forms, while Hungarian only has one. 257 234 … … 264 241 265 242 Genshi 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 ------------------- 243 allows choosing the proper plural form based on the numeric value of a given 244 variable. The pluralization support is implemented in a set of three 245 directives that must be used together: ``i18n:choose``, ``i18n:singular``, and 246 ``i18n:plural``. 247 248 The ``i18n:choose`` directive is used to set up the context of the message: it 249 simply wraps the singular and plural variants. 250 251 The 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 253 plural form should be chosen. The second part, separated by a semicolon, lists 254 the parameter names. This part is equivalent to the value of the ``i18n:msg`` 255 directive. 256 257 For 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 266 All three directives can be used either as elements or attribute. So the above 267 example 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 276 When used as an element, the two parts of the ``i18n:choose`` value are split 277 into two different attributes: ``numeral`` and ``params``. The 278 ``i18n:singular`` and ``i18n:plural`` directives do not require or support any 279 value (or any extra attributes). 280 281 -------------------- 282 Comments and Domains 283 -------------------- 284 285 ``i18n:comment`` 286 ---------------- 287 288 The ``i18n:comment`` directive can be used to supply a comment for the 289 translator. For example, if a template snippet is not easily understood 290 outside of its context, you can add a translator comment to help the 291 translator 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 299 This comment will be extracted together with the message itself, and will 300 commonly be placed along the message in the message catalog, so that it is 301 easily visible to the person doing the translation. 302 303 This directive has no impact on how the template is rendered, and is ignored 304 outside of the extraction process. 276 305 277 306 ``i18n:domain`` 278 307 --------------- 279 308 280 TODO 309 In larger projects, message catalogs are commonly split up into different 310 *domains*. For example, you might have a core application domain, and then 311 separate domains for extensions or libraries. 312 313 Genshi provides a directive called ``i18n:domain`` that lets you choose the 314 translation 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 281 322 282 323 Extraction -
trunk/genshi/filters/i18n.py
r1105 r1111 294 294 </html> 295 295 296 When used as a directiveand not as an attribute:296 When used as a element and not as an attribute: 297 297 298 298 >>> tmpl = MarkupTemplate('''\
Note: See TracChangeset
for help on using the changeset viewer.
