Localizing web site

In this article we will cover all the aspects of creating multilingual websites with the help of PHPRunner/ASPRunnerPro. This process includes the following steps:

Translation of system messages

First of all, you need to define the language(s) of standard texts in the website interface or "system messages".
On the Miscellaneous page you can choose one or more languages which your website will support. Use the Language drop-down box if you like to choose one language. By clicking Multiple languages button you can select several languages and give the user ability to choose language while logging in.
PHPRunner/ASPRunnerPro includes translations of system messages into the following languages:


Translations of system messages are stored in the language files (*.lng) located in the lang directory (C:\Program Files\PHPRunner5.3\lang or C:\Program Files\ASPRunnerPro6.3\lang). For example, system messages in English language is stored in the English.lng file:


To change the translation of system messages in some language, modify the corresponding language file (*.lng).

To add translation of system messages in new language, create a copy of file English.lng and translate all phrases there. Then modify the file languages.cfg that is also located in the lang directory by adding this line (change the values listed in red to match your specific needs):

<language filename="YourLanguageFile.lng" name="YourLanguageName" lcid="YourLocaleID" codepage="YourCodepage" charset="YourCharset" />

, where

Translation of table/field names and custom labels

Use Label Editor on the Miscellaneous page to translate table and field names/labels (Table labels tab). Also you can add and translate custom labels there (Custom labels tab) and add tooltips to the Edit forms (Edit form tooltips tab).
Use custom labels to translate menu items, tab/section names, error messages in regular expressions and your own validation plugins etc. When creating menu item, new tab/section or regular expression, use the Multilanguage... button to create and translate custom label. Use Label Editor (Custom labels tab) to create custom labels for error messages in your own validation plugins. In Label Editor you can also create your own custom labels to display some messages to a user.


Use the methods listed below to access labels from the PHP/ASP code:

PHP methodASP methodDescription
GetTableCaption($table)GetTableCaption(table)Returns table caption.
GetFieldLabel($table, $field)GetFieldLabel(table, field)Returns field label.
GetCustomLabel("LABEL_ID")GetCustomLabel("LABEL_ID")Returns custom label. LABEL_ID - custom label identifier.
GetFieldToolTip($table, $field)GetFieldToolTip(table, field)Returns field edit tooltip.
mlang_message($tag)mlang_message(tag)Returns standard message. You can find the list of message tags in the file English.lng (C:\Program Files\PHPRunner5.3\lang\English.lng or C:\Program Files\ASPRunnerPro6.3\lang\English.lng).

Use the methods listed below to access labels from the Javascript code:

GetCustomLabel("LABEL_ID")Returns custom label. LABEL_ID - custom label identifier.
Runner.lang.constants.CONSTANT_IDReturns standard message. CONSTANT_ID - message constant identifier. You can find the list of constants in the file RunnerLang.js (C:\Program Files\PHPRunner5.3\source\include\common\runnerJS\constants\language\RunnerLang.js or C:\Program Files\ASPRunnerPro6.3\source\include\common\runnerJS\constants\language\RunnerLang.js).

Example 1. Use of custom label in PHP/ASP code
If you have created custom label Message1 and want to place this message on a page, which will vary depending on the selected language, add code snippet to the page and use the following code in it:

echo GetCustomLabel ("Message1");
Response.Write GetCustomLabel("Message1")

Example 2. Use of custom label in Javascript code
If you have created custom label Error_Message_1 for your validation plugin, use GetCustomLabel("Error_Message_1") code in your javascript function. Note that GetCustomLabel function is applicable only for editing fields like Add/Edit/Register/List with inline add/edit.

Example 3. Use of field label instead of field name
In this code snippet that sends email with new data we use GetFieldLabel method to get field label. Don't forget to replace table_name with the correct name of the table.

//**********  Send email with new data  ************

$subject="New data record";

foreach($values as $field=>$value)
    $msg.= GetFieldLabel("table_name", $field) ." : ".$value."\r\n";

$ret=runner_mail(array('to' => $email, 'subject' => $subject, 'body' => $msg, 'from'=>$from));
  echo $ret["message"];
'**********  Send email with new data  ************
' do not forget to setup email parameters like From, SMTP server etc
' on 'Security->User login settings' dialog
Dim dkeys, tmpDict, msg, n
msg =""
    dkeys = values.keys
    For n = 0 To values.Count-1
        if not IsBinaryType(GetFieldType(dkeys(n),"")) then
            msg = msg & GetFieldLabel("table_name",dkeys(n)) & " : " & values(dkeys(n)) & vbcrlf
        end if
set tmpDict = CreateObject("Scripting.Dictionary")
tmpDict("subject")="--rbegin--Sample subject--rend--"
set ret=runner_mail(tmpDict)
if not ret("mailed") then
    response.write ret("message")
end if

Translation of data from the database

We can propose two approaches to the translation data from the database:

1. To store data for each language in a separate table and redirect users to the page, depending on the selected language.
Example. To implement this approach we use the following code in the BeforeProcessList event of mydata_english table:

if ($_SESSION["language"]=="Spanish")
    header("Location: mydata_spanish_list.php");
  else if ($_SESSION["language"]=="French")
      header("Location: mydata_french_list.php");
if SESSION("language")="Spanish" then
   Response.Redirect "mydata_spanish_list.asp"
else if SESSION("language")="French"
   Response.Redirect "mydata_french_list.asp"
end if

2. To store data for all languages ??in one table by adding new field for storing language. This approach is easier to configure.
To implement this approach, you can use the method described in the Dynamic SQL query topic and the following code in the Before SQL Query event of the List page:

$strWhereClause = whereAdd($strWhereClause, "language='". $_SESSION["language"] ."'");
strWhereClause = whereAdd(strWhereClause,"language='" & SESSION("language") & "'"

If you have lookup table were data is stored on multiple languages, use the following code in the WHERE clause in the Lookup wizard to display the data only for the currently selected language:

"language='". $_SESSION["language"] ."'"
"language='" & SESSION("language") & "'"