|
|||||||
1. Introduction
2. Installing Karrigell 3. The Web server 4. Configuration options 5. Working with Apache, LightTPD or Xitami 6. Programming 7. Debugging 8. Python scripts 9. Karrigell Services 10. Python Inside HTML 11. HTML Inside Python 12. HTMLTags - generate HTML in Python 13. Including documents 14. Sessions 15. Authentication 16. Translation and Unicode 16.1 Introduction 16.2 Internationalization program 16.3 Unicode support |
16. Internationalization and UnicodeAs you'll have guessed by reading this documentation, I'm not from an English-speaking country (I'm French, and more precisely Breton - the name Karrigell is a Breton word). So I've included a program to facilitate internationalization of scripts 16.1 IntroductionTranslation is made using the
This text file is transformed into a binary file with a .mo extension by a Python program called msgfmt.py, written by Martin v. Löwis (it's included in Karrigell's Server Directory) In a script, every time you want a message translated into a given language, instead of writing the message as a normal string with quotes, it's written using a function called _, this way :
In order to have it translated into the requested language :
where domain is the name of the .po file, baseDir the directory in which the subdirectory language/LC_MESSAGES is stored, and language is the language used For instance, if the language is
"francais" and the .po file is called messages.po, stored in
16.2 Internationalization programThe raw use ofgettext may be difficult when writing or debugging
a program ; for each new string you want to translate you have to create the
whole .po file then the .mo file without erasing previous translations.
Karrigell provides a simple web interface to create and modify translations of
strings, hiding the underlying gettext mechanism
For security reasons, this script is reserved to the administrator. An
authentication script is run, relying on md5 digests stored in a file called
With your browser, call the script Fill in the fields and validate the form ; this creates or updates the translations
You can check the effect by calling the script you've just modified and changing the language order in the preferences Translation is held in a file which is common to all the files in the same directory. You can also edit the whole dictionary clicking on the first item in the script list
16.3 Unicode supportNew in version 2.2.2mostly written by Radovan GarabikUnicode is a normalized standard used to represent all the writing styles in the world. For each sign (a letter in any alphabet, an ideogram in an Asiatic language) Unicode defines a unique number, called a "code point". Since computers and networks can only manage bytes, a mapping between "code points" and one or several bytes must be defined ; these mappings are called "encodings" Because there are many different encodings, when a program has to print a sign (a greek letter, a math symbol, a Chinese sign) it must receive two pieces of information : the string representing the sign (a sequence of bytes) and the encoding used. If it receives only a string, the program can try to guess an encoding (this is what a web browser usually does) but with no guarantee of success Karrigell defines two parameters in the configuration file to handle Unicode :
(1) On Microsoft Internet Explorer the language preference is set by Tools/Internet Options/General/Languages ; accepted languages are chosen from a list and ordered by preference. On Netscape use Edition/Preferences/Languages |