Edgewall Software

Changes between Version 25 and Version 26 of CookBook/PluginL10N


Ignore:
Timestamp:
Sep 26, 2012, 12:32:53 AM (12 years ago)
Author:
Christian Boos
Comment:

#Option-i18n: mention the doc_domain keyword

Legend:

Unmodified
Added
Removed
Modified
  • CookBook/PluginL10N

    v25 v26  
    409409== Advanced stuff
    410410
    411 === Translating `Option*` documentation
     411=== Translating `Option*` documentation  #Option-i18n
    412412
    413413Trac 1.0 added support for a special kind of `N_` marker, `cleandoc_`, which can be used to reformat multiline messages in a compact form. There's also support to apply this "cleandoc" transformation to the documentation of instances of `trac.config.Option` and its subclasses. However, this support is coming from a special Python extractor which has to be used instead of the default Python extractor from Babel.
     
    431431}}}
    432432
    433 The default `cleanup_keywords` (the `Option` subclasses) are not automatically `keywords` however. The corresponding option for the `extract_messages` section of the `setup.cfg` file should therefore contain the `cleandoc_` token, or the various `Config` subclasses together with the position of the doc argument in that subclass.
    434 As a (somewhat complex) example, see the following excerpt from Trac's [source:tags/trac-1.0/setup.cfg setup.cfg] file:
     433The default `cleanup_keywords` (the `Option` subclasses) are not automatically `keywords` however. The corresponding option for the `[extract_messages]` section of the `setup.cfg` file should therefore contain the `cleandoc_` token, or the various `Config` subclasses together with the position of the doc argument in that subclass.
     434As an example, see the following excerpt from the SpamFilter plugin [source:plugins/1.0/spam-filter/setup.cfg setup.cfg] file:
    435435{{{#!python
    436 [extract_messages_tracini]
     436[extract_messages]
    437437add_comments = TRANSLATOR:
    438 copyright_holder = Edgewall Software
    439 msgid_bugs_address = trac-dev@googlegroups.com
    440 output_file = trac/locale/tracini.pot
    441 keywords = ConfigSection:2 Option:4 BoolOption:4 IntOption:4 FloatOption:4 ListOption:6 ChoiceOption:4 PathOption:4 ExtensionOption:5 OrderedExtensionsOption:6
    442 no-default-keywords = yes
    443 mapping_file = tracini.cfg
    444 }}}
    445 
     438msgid_bugs_address = [...]
     439output_file = tracspamfilter/locale/messages.pot
     440keywords = _ ngettext:1,2 N_ tag_ Option:4 BoolOption:4 IntOption:4 ListOption:6 ExtensionOption:5
     441width = 72
     442}}}
     443This makes it possible for the extractor to get the doc strings from those options automatically. For example, in [source:plugins/1.0/spam-filter/tracspamfilter/adapters.py#?IntOption adapters.py]:
     444{{{#!python
     445class AttachmentFilterAdapter(Component):
     446    """Interface to check attachment uploads for spam.
     447    """
     448    implements(IAttachmentManipulator)
     449
     450    sample_size = IntOption('spam-filter', 'attachment_sample_size', 16384,
     451        """The number of bytes from an attachment to pass through the spam
     452        filters.""", doc_domain='tracspamfilter')
     453}}}
     454as you can see, it's also necessary to specify the //domain//, otherwise the lookup of the translated message at runtime (within the ![[TracIni]] macro, typically) will fail.
    446455
    447456=== About 'true' l10n