Comment utiliser pywws dans une autre langue — pywws 13.06_r1023 documentation

### Navigation

- index
- modules |
- suivant |
- précédent |
- pywws 13.06_r1023 documentation »
- Guides utilisateur »

# Comment utiliser pywws dans une autre langue

## Introduction

Certaines parties de pywws peuvent être configurées pour utiliser votre langue locale au lieu de l’Anglais Britannique. Ceci requière un fichier de langage contenant la traduction des différentes phrases utilisées par pywws. Le projet repose sur les utilisateur qui fournissent ces traductions. Ce document décrit comment créer un fichier de langage.

La documentation de pywws peut aussi être traduite dans d’autres langues. C’est beaucoup de travail, mais pourrait être très utile aux utilisateurs potentiels qui ne lisent pas très bien l’anglais.

## Dependencies

As well as the pywws software you need to install the `gettext` GNU internationalisation utilities package. This is available from the standard repositories for most Linux distributions, or you can download it from http://www.gnu.org/software/gettext/ if you need to compile it yourself.

## Choose your language code

Computers use IETF language tags (see http://en.wikipedia.org/wiki/IETF_language_tag). For example, in the UK we use `en_GB`. This has two parts: `en` for English, and `GB` for the British version of it. To find the correct code for your language, consult the list at http://www.gnu.org/software/gettext/manual/gettext.html#Language-Codes.

## Mise en route

Your pywws directory should already have a subdirectory called translations. This contains the existing set of language files, for example `translations/sv/pywws.po` contains the Swedish translations. If one of these languages is what you need, then edit your weather.ini file and add a `language` entry to the `[config]` section, for example:

    [config]
    day end hour = 21
    gnuplot encoding = iso_8859_1
    language = sv

You may still need to compile and install your chosen language file. This is done with `setup.py`:

    python setup.py msgfmt

S’il n’y a pas déjà de fichier pour votre langage, le reste de ce document vous indique comment en créer un.

## Create a language file

The first step is to create a file containing the strings you need to translate. For example, to create a source file for the French language (code `fr`):

    python setup.py xgettext
    python setup.py msgmerge --lang=fr

This will ask you to confirm your email address, then create a `pywws.po` file in the directory `translations/fr`. You should now edit `pywws.po`, filling in every `msgstr` line with a translation of the `msgid` line immediately above it. The reason for including your email address is to allow anyone who has questions about your translation to get in touch with you. Feel free to put in an invalid address if you are concerned about privacy.

After you’ve edited your new language file it needs to be compiled so that pywws can use it. This is done with the `msgfmt` command:

    python setup.py msgfmt

N’oubliez pas de faire celà à chaque fois que vous éditez un fichier de langue.

## Test the pywws translation

The `Localisation` module can be used to do a quick test of your language file installation:

    python -m pywws.Localisation -t fr

Cela devrait afficher quelque chose comme ceci:

    Locale changed from (None, None) to ('fr_FR', 'UTF-8')
    Translation set OK
    Locale
      decimal point: 23,2
      date & time: lundi, 17 décembre (17/12/2012 16:00:48)
    Translations
      'NNW' => 'NNO'
      'rising very rapidly' => 'en hausse très rapide'
      'Rain at times, very unsettled' => 'Quelques précipitations, très perturbé'

Edit the language entry in your `weather.ini` file to use your language code (e.g. `fr`), then try using `Plot` to plot a graph. The X-axis of the graph should now be labeled in your language, using the translation you provided for ‘Time’, ‘Day’ or ‘Date’.

## Translating the documentation

The system used to translate the strings used in pywws can also be used to translate the documentation. The command to extract strings from the documentation is very similar:

    python setup.py xgettext_doc

Note that this requires the sphinx package used to ‘compile’ the documentation. After extracting the strings, create source files for your language. In this example the language is French, with the two letter code `fr`:

    python setup.py msgmerge --lang=fr

This creates four files (`index.po`, `essential.po`, `guides.po` and `api.po`) that contain text strings (often whole paragraphs) extracted from the different parts of the documentation.

These files can be edited in a similar way to `pywws.po`. Fill in each `msgstr` with a translation of the `msgid` above it. Note that some strings (such as URLs and links to other parts of the documentation) should not be translated. In these cases, leave the `msgstr` blank.

Translating all of the pywws documentation is a lot of work. However, when the documentation is ‘compiled’ any untranslated strings revert to their English original. This means that a partial translation could still be useful – I suggest starting with the documentation front page, `index.po`.

## Viewing your translated documentation

First convert your newly edited language files:

    python setup.py msgfmt

Then delete the old documentation (if it exists) and rebuild using your language:

    rm -Rf doc/html/fr
    LANG=fr python setup.py build_sphinx

Note that the `build_sphinx` command doesn’t have a `--lang` option, so the language is set by a temporary environment variable.

Finally you can view the translated documentation by using a web browser to read the file `doc/html/fr/index.html`.

## Update the language files

As pywws is extended, new strings may be added which will require your translation files to be extended as well. This is fairly easy to do. First you need to re-extract the strings to be translated, then merge them into your existing language files. This is done by repeating the commands used to create the files:

    python setup.py xgettext
    python setup.py xgettext_doc
    python setup.py msgmerge --lang=fr

This should add the new strings to your language files, without changing the strings you’ve already translated.

If the English language source has changed since your last translation, some strings may be marked by gettext as `#, fuzzy`. You should check that your translation is still correct for these strings – the change may be trivial (e.g. a spelling correction) but it could be quite significant. When you’ve checked (and corrected if necessary) the translation, remove the `#, fuzzy` line.

## Send Jim the translation

I’m sure you would like others to benefit from the work you’ve done in translating pywws. Please, please, please send a copy of your language file(s) (for example `pywws.po`) to jim@jim-easterbrook.me.uk.

Commentaires ou questions? SVP, souscrivez à la liste d’envoi de pywws http://groups.google.com/group/pywws et laissez-le nous savoir.

### Navigation

- index
- modules |
- suivant |
- précédent |
- pywws 13.06_r1023 documentation »
- Guides utilisateur »