Country Locale
From QNAPedia
or How I taught my QNAP to speak my language
By AdNovea – Dec 2008 – version 1.0
Contents |
Introduction and current status
By default, on QNAP servers, there is ONLY one language "en_US" and one character map "UTF-8" but it is possible to add any other languages as with any Linux system.
This Wiki will explain How To create a locale database (locale here means a set of data such as collation, date and time formats, and character properties that are specific to a language/country).
First, lets have a look under the "mnt/ext/usr/share/i18n" directory. We find 2 subdirectories:
- locales - with the en_US locale file ONLYand some other files translit_xxxxxx
- charmaps - with UTF-8.gz character map file ONLY
- locales - with the en_US locale file ONLYand some other files translit_xxxxxx
Moreover, the QNAP OS provides the localedef command.
With these files and command, we are able to create a locale database using en_US encoded into the UTF-8 format. This locale database will be named en_US.utf8 and exists already on the server.
Preparation to support new locale database
You shall copy on your system the files required to create your new locale database.
1- Download the posix-locales file below. It contains all the files for all languages supported by Linux systems. These files (locale and character map) are available from any Linux distribution but not on the QNAP server.
2- Copy into the "/usr/share/i18n/locales"directory the following files:
3- Copy into the "/usr/share/i18n/charmaps" directory the required charmaps. E.g. for Europe:
- translit_cjk_variants
- translit_combining
- xx_XX that you want to use
- ANSI_X3.4-1968.gz
- ISO-8859-1.gz
- ISO-8859-15.gz
Download the full set of locales and charmaps http://wiki.qnap.com/w/images/7/77/Posix-locales.rar
Set new locales on the server
In order to create new locale database such as xx_XX.iso-8859-15 for example,
1 -We must put into the charmap directory the corresponding ISO-8859-15 character map.
2- We need to put into the locales directory the xx_XX locale (e.g. fr_FR or fr_FR@Euro to support the Euro symbol)
3- From a console, compile the new locale database using:# localedef -i <locale> -f <character map> <database> (e.g. localedef -i fr_FR -f UTF-8 fr_FR.utf8)
4- To check that your new locale database has been added# locale -a
5- To make this new locale available to PHP (restart Apache) MANDATORY
# /etc/init.d/Qthttpd.sh restart
Others commands:
If you want this new locale database to become your default for your QNAP (not recommanded)# export LANG="fr_FR.utf8"
If want to return to default locale database# unset LANG
To list configuration# locale
To set a variable (eg. time variable in French)# setlocale (LC_TIME, 'fr_FR.utf8')
To clear back to default use# unset LANG
To remove one locale database from archive# localedef --delete-from-archive fr_FR.utf8
How to use the locale
Let say that you have created a PHP website with several languages and you display some information such as the time using the PHP gmstrftime function. You can use the locale to display the time with the selected language format.
You must have previously compiled the corresponding locale database as describe above and restarted the Apache server.
EXAMPLE: display the date on one page where the user has selected French.
In the PHP code of the page use the PHP setlocale function such as:setlocale(LC_TIME, "fr_FR.ISO-8859-15"); // For time only, or LC_ALL if you use other specificities too echo dgmstrftime("%A %e %B %Y",time());It will display : jeudi 25 décembre 2008
whereasecho gmstrftime("%A %e %B %Y",time());will display : Thursday 25 December 2008
Notes for TS-x39 (TS-509)
On the TS-639 NAS, there is no /usr/share/i18n directory neither /usr/share/i18n/locales nor /usr/share/i18n/charmaps. You must first create these directories before following the here above instructions.
NOTE: ignore /mnt/ext and use directly /usr/share/i18n.