phpGroupWare is built using a multi-language support scheme. This means the pages can be translated to other languages very easily. Translations of text strings are stored in the phpGroupWare database, and can be modified by the phpGroupWare administrator.
The lang()
function is your application's interface to phpGroupWare's
internationalization support.
While developing your application, just wrap all your text output with calls to lang(), as in the following code:
$x = 42; echo lang("The counter is %1",$x)."<br>";
$x
will end up is controlled by the format string, not by
building up the string in your code. This allows your application to be translated
to languages where the actual number is not placed at the end of the string.
When a translation is not found, the original text will be returned with a * after the string. This makes it easy to develop your application, then go back and add missing translations (identified by the *) later.
Without a specific translation in the lang table, the above code will print:
The counter is 42*<br>If the current user speaks Italian, they string returned may instead be:
il contatore è 42<br>
lang($key, $m1="", $m2="", $m3="", $m4="", $m5="", $m6="", $m7="", $m8="", $m9="", $m10="")
is the string to translate and may contain replacement directives of the form %n
.
is the first replacement value or may be an array of replacement values (in which case $m2 and above are ignored).
the 2nd through 10th replacement values if $m1 is not an array.
lang.message_id
that matches $key
.
If a translation is not found, the original $key
is used. The translation engine then replaces
all tokens of the form %N
with the Nth parameter (either $m1[N]
or $mN
).
An application called Transy is being developed to make this easier, until then you can create the translation data manually.
The translation class uses the lang table for all translations. We are concerned with 4 of the columns to create a translation:
The key to identify the message (the $key
passed
to the lang()
function). This is written in English.
The application the translation applies to, or
common
if it is common across multiple applications.
The code for the language the translation is in.
The translated string.
Currently all applications, and the core phpGroupWare source tree
have a lang.sql
file. This is the place to add translation
data. Just add lines of the form:
REPLACE INTO lang (message_id, app_name, lang, content) VALUES( 'account has been deleted','common','en','Account has been deleted');
content
to reflect the message_id
string in the lang
language.
If the string is specific to your application, put your application name in for app_name
otherwise use the name common
. The message_id
should be in lower case for a small
increase in speed.
If you browse through the phpGroupWare sources, you may notice
a pattern to the return codes used in the higher-level functions.
The codes used are partially documented in the doc/developers/CODES
file.
Codes are used as a simple way to communicate common error and progress
conditions back to the user. They are mapped to a text string through the
check_code()
function, which passes the strings through
lang()
before returning.
For example, calling
echo check_code(13);
Your message has been senttranslated into the current language.