Edgewall Software

Changes between Initial Version and Version 1 of CookBook/PluginL10N


Ignore:
Timestamp:
May 5, 2010, 2:59:33 PM (14 years ago)
Author:
hasienda <hoff.st@…>
Comment:

initial design and content

Legend:

Unmodified
Added
Removed
Modified
  • CookBook/PluginL10N

    v1 v1  
     1= Adding l10n support to Trac plugins (Trac >= 0.12) =
     2== Motivation ==
     3[FIXME: content needed, especially address the intended audience (plugin maintainers and developers in general) here - who should read on (and who shouldn't care at all)]
     4
     5== i18n vs. l10n (again) ==
     6[FIXME: is this needed?, well consider this is nice to the reader allowing to focus on i18n after coming from the greater scope of l10n, but be as short as possible when]
     7
     8
     9== Background and basics of i18n support ==
     10The evolution of native support for Trac plugins is documented in [comment:11:ticket:7497 ticket 7497]. The final implementation as documented there in [comment:12:ticket:7497 comment 12] was introduced to Trac trunk in [changeset: changeset r7705] and finally done with [changeset: changeset r7714]. Adding the needed i18n helper functions is as easy as adding
     11{{{
     12from trac.util.translation import domain_functions
     13
     14_, tag_, N_, add_domain = domain_functions('tracmercurial',
     15    '_', 'tag_', 'N_', 'add_domain')
     16}}}
     17at the beginning of the main python script file of an existing or new plugin. To bring in the compiled message catalog for actually using the translated texts one will have to extend the `__init__` function of plugins main class too. For a fictional plugin Foo this would be done like this:
     18{{{
     19    def __init__(self):
     20        self._version = None
     21        self.ui = None
     22        # bind the 'foo' catalog to the specified locale directory
     23        locale_dir = pkg_resources.resource_filename(__name__, 'locale')
     24        add_domain(self.env.path, locale_dir)
     25}}}
     26assuming that folder `locale` will reside in `./foo/locale/` within the directory structure (of the Python egg).
     27
     28[FIXME: explain what _version and ui are used for or leave them out, if unnecessary here]
     29
     30== Required minimal workflow ==
     31a walk-through
     32
     33General advice of [wiki:TracL10N TracL10N] on making good translation for Trac in general applies here too.
     34
     35=== Preparing the pluging code ===
     36=== Translation work ===
     37=== Compilation and testing ===
     38=== Advanced stuff ===
     39==== Finally l10n ====
     40
     41== Related resources ==