gxfx 1.0.1

XML i18n module
gxfx is a Python module for i18n of XML documents.

gxfx stands for "gettext XML for XML".

* Read-only properties:

- `version`: a tuple of int values representing the version of gxfx

* Functions:

- `create_template(gxfx_infile_path, template_outfile_path)`: create a GNU portable object template file from a gxfx XML file
- `apply(gxfx_infile_path, translated_xml_outfile_path, localedir)`: create a translated XML file for the current locale

Usage:

Start
-----

1.
   a. If you don't know XML, learn it before continuing.
   b. If you don't know how Python's gettext module works, learn to use it before continuing.
   c. If you don't have lxml, install it before continuing. gxfx is known to work with lxml 2.2.4; it might or might not work with earlier versions.

Create a translatable XML document
----------------------------------

Create original-language version
````````````````````````````````

2. Create an XML file with text encoding UTF-8 as it will appear in the original language.

Create gxfx document
````````````````````

3.
   a. Create a `gxfx` element.
   b. Set the `gxfx` element's `domain` attribute to the name that your translation files will use (e.g., "foobar" for foobar.mo).
   c. Put a `header` element inside the `gxfx` element.
   d. Set the text of the `header` element to everything above the root element of your existing XML file. Change "&" to "&", "< " to "<", and " >" to ">".
   e. Put your existing XML file's root element after the `header` element inside the `gxfx` element.
   f. Put a `gettext` element around each piece of text that you want to be translatable. Only text can be contained in a `gettext` element. If you need to translate text containing XML markup, change "&" to "&", "< " to "<", and " >" to ">" in the gxfx document and reverse the changes after using `gxfx.apply`.
   g. Set the `comment` attribute of zero or more `gettext` elements. The values of `comment` attributes are extracted from `gettext` elements and placed in the POT file above the corresponding msgid.
   h. Put "< ?xml version="1.0" encoding="UTF-8" ? >" at the beginning of the file.

Extract
-------

Method A: from your Python program
``````````````````````````````````

4. Import the module: ``import gxfx``.

5. Call `gxfx.create_template` on the gxfx file. If your version of lxml is 2.3 or newer, your gxfx file will be validated against a Schematron schema; if validation fails, the module will raise an AssertionError.

Method B: running gxfx as a program
```````````````````````````````````

4. Call your python interpreter on gxfx.py with the argument `--help`. Read the help message.

5. Call your python interpreter on gxfx.py with the necessary arguments to create a POT file. If your version of lxml is 2.3 or newer, your gxfx file will be validated against a Schematron schema; if validation fails, the program will end with an AssertionError.

Translate
---------

6. Make a PO file with translations as normal.

7. Make an MO file from the PO file. Make sure that the MO file's name (not including the extension) matches the domain specified in the file to translate. Put it in the locale directory as normal.

Apply a translation
-------------------

6. In your Python program, import `locale` and call `locale.setlocale` as you would for the standard library's `gettext` module.

7. If you haven't imported `gxfx`, import it: ``import gxfx``. Call `gxfx.apply` on the path of the input file, the path of the output file, and the locale directory. If your version of lxml is 2.3 or newer, your gxfx file will be validated against a Schematron schema; if validation fails, the module will raise an AssertionError.

last updated on:
July 21st, 2010, 4:05 GMT
price:
FREE!
developed by:
Zach Harrison
license type:
LGPL (GNU Lesser General Public License) 
category:
ROOT \ Documentation

FREE!

In a hurry? Add it to your Download Basket!

user rating

UNRATED
0.0/5
 

0/5

Add your review!

SUBMIT