pywws.localisation
Provide translations of strings into local language
usage: python -m pywws.localisation [options]
options are:
-h or --help display this help
-t code or --test code test use of a language code
Introduction
Some of the pywws modules, such as pywws.windrose, can automatically use your local language for such things as wind directions. The pywws.localisation module, mostly copied from examples in the Python documentation, enables this.
Localisation of pywws is done in two parts - translating strings such as ‘rising very rapidly’, and changing the ‘locale’ which controls things like month names and number representation (e.g. ‘23,2’ instead of ‘23.2’). On some computers it may not be possible to set the locale, but translated strings can still be used.
Using a different language
The language used by pywws is set in the [config]
section of the
weather.ini
file. This can be a two-letter language code, such as
en
(English), or can specify a national variant, such as fr_CA
(Canadian French). It could also include a character set, for example
de_DE.UTF-8
.
The choice of language is very system dependant, so pywws.localisation
can be run as a standalone program to test language codes. A good
starting point might be your system’s LANG
environment variable, for
example:
jim@brains:~/Documents/weather/pywws/code$ echo $LANG
en_GB.UTF-8
jim@brains:~/Documents/weather/pywws/code$ python -m pywws.localisation -t en_GB.UTF-8
Locale changed from (None, None) to ('en_GB', 'UTF8')
Translation set OK
Locale
decimal point: 23.2
date & time: Friday, 14 October (14/10/11 13:02:00)
Translations
'NNW' => 'NNW'
'rising very rapidly' => 'rising very rapidly'
'Rain at times, very unsettled' => 'Rain at times, very unsettled'
jim@brains:~/Documents/weather/pywws/code$
In most cases no more than a two-letter code is required:
jim@brains:~/Documents/weather/pywws/code$ python -m pywws.localisation -t fr
Locale changed from (None, None) to ('fr_FR', 'UTF8')
Translation set OK
Locale
decimal point: 23,2
date & time: vendredi, 14 octobre (14/10/2011 13:04:44)
Translations
'NNW' => 'NNO'
'rising very rapidly' => 'en hausse très rapide'
'Rain at times, very unsettled' => 'Quelques précipitations, très perturbé'
jim@brains:~/Documents/weather/pywws/code$
If you try an unsupported language, pywws falls back to English:
jim@brains:~/Documents/weather/pywws/code$ python -m pywws.localisation -t ja
Failed to set locale: ja
No translation file found for: ja
Locale
decimal point: 23.2
date & time: Friday, 14 October (10/14/11 13:08:49)
Translations
'NNW' => 'NNW'
'rising very rapidly' => 'rising very rapidly'
'Rain at times, very unsettled' => 'Rain at times, very unsettled'
jim@brains:~/Documents/weather/pywws/code$
Once you’ve found a suitable language code that works, you can
configure pywws to use it by editing your weather.ini
file:
[config]
language = fr
Creating a new translation
If there is no translation file for your preferred language then you need to create one. See How to use pywws in another language for detailed instructions.
Functions
|
|
|
Set the locale and translation for a pywws program. |
|
Set the 'locale' used by a program. |
|
Set the translation used by (some) pywws modules. |
Comments or questions? Please subscribe to the pywws mailing list http://groups.google.com/group/pywws and let us know.