# HG changeset patch # User cmlenz # Date 1182332935 0 # Node ID f38ce008ab0afc1815de7debc16153685388b5bd # Parent bd13c96cbfe4a8caeb4731e759e87f97d2f3aa85 Integrated [http://babel.edgewall.org/ Babel] message extraction plugin, and added I18n doc page. diff --git a/ChangeLog b/ChangeLog --- a/ChangeLog +++ b/ChangeLog @@ -13,7 +13,7 @@ Version 0.4.2 http://svn.edgewall.org/repos/genshi/tags/0.4.2/ -(?, from branches/stable/0.4.x) +(Jun 20, from branches/stable/0.4.x) * The `doctype` parameter of the markup serializers now also accepts the "name" of the doctype as string, in addition to the `(name, pubid, sysid)` tuple. @@ -25,6 +25,7 @@ * The I18n filter now skips the content of elements that have an `xml:lang` attribute with a fixed string value. Basically, `xml:lang` can now be used as a flag to mark specific sections as not needing localization. + * Added plugin for message extraction via Babel (http://babel.edgewall.org/). Version 0.4.1 diff --git a/doc/conf/docutils.ini b/doc/conf/docutils.ini new file mode 100644 --- /dev/null +++ b/doc/conf/docutils.ini @@ -0,0 +1,9 @@ +[general] +input_encoding = utf-8 +strip_comments = yes +toc_backlinks = none + +[html4css1 writer] +embed_stylesheet = no +stylesheet = style/edgewall.css +xml_declaration = no diff --git a/doc/conf/epydoc.ini b/doc/conf/epydoc.ini new file mode 100644 --- /dev/null +++ b/doc/conf/epydoc.ini @@ -0,0 +1,24 @@ +[epydoc] + +name: Documentation Index +url: ../index.html +modules: genshi +verbosity: 1 + +# Extraction +docformat: restructuredtext +parse: yes +introspect: yes +exclude: .*\.tests.* +inheritance: listed +private: no +imports: no +include-log: no + +# HTML output +output: html +target: doc/api/ +css: doc/style/epydoc.css +top: genshi +frames: no +sourcecode: no diff --git a/doc/docutils.conf b/doc/docutils.conf deleted file mode 100644 --- a/doc/docutils.conf +++ /dev/null @@ -1,9 +0,0 @@ -[general] -input_encoding = utf-8 -strip_comments = yes -toc_backlinks = none - -[html4css1 writer] -embed_stylesheet = no -stylesheet = style/edgewall.css -xml_declaration = no diff --git a/doc/epydoc.conf b/doc/epydoc.conf deleted file mode 100644 --- a/doc/epydoc.conf +++ /dev/null @@ -1,24 +0,0 @@ -[epydoc] - -name: Documentation Index -url: ../index.html -modules: genshi -verbosity: 1 - -# Extraction -docformat: restructuredtext -parse: yes -introspect: yes -exclude: .*\.tests.* -inheritance: listed -private: no -imports: no -include-log: no - -# HTML output -output: html -target: doc/api/ -css: doc/style/epydoc.css -top: genshi -frames: no -sourcecode: no diff --git a/doc/i18n.txt b/doc/i18n.txt new file mode 100644 --- /dev/null +++ b/doc/i18n.txt @@ -0,0 +1,237 @@ +.. -*- mode: rst; encoding: utf-8 -*- + +===================================== +Internationalization and Localization +===================================== + +Genshi provides basic supporting infrastructure for internationalizing +and localizing templates. That includes functionality for extracting localizable +strings from templates, as well as a template filter that can apply translations +to templates as they get rendered. + +This support is based on `gettext`_ message catalogs and the `gettext Python +module`_. The extraction process can be used from the API level, or through the +front-ends implemented by the `Babel`_ project, for which Genshi provides a +plugin. + +.. _`gettext`: http://www.gnu.org/software/gettext/ +.. _`gettext python module`: http://docs.python.org/lib/module-gettext.html +.. _`babel`: http://babel.edgewall.org/ + + +.. contents:: Contents + :depth: 2 +.. sectnum:: + + +Basics +====== + +The simplest way to internationalize and translate templates would be to wrap +all localizable strings in a ``gettext()`` function call (which is often aliased +to ``_()`` for brevity). In that case, no extra template filter is required. + +.. code-block:: genshi + +

${_("Hello, world!")}

+ +However, this approach results in significant “character noise” in templates, +making them harder to read and preview. + +The ``genshi.filters.Translator`` filter allows you to get rid of the +explicit `gettext`_ function calls, so you can continue to just write: + +.. code-block:: genshi + +

Hello, world!

+ +This text will still be extracted and translated as if you had wrapped it in a +``_()`` call. + +.. note:: For parameterized or pluralizable messages, you need to continue using + the appropriate ``gettext`` functions. + +You can control which tags should be ignored by this process; for example, it +doesn't really make sense to translate the content of the HTML +```` element. Both ``