Localizing PHPRunner/ASPRunnerPro applications

PHP, PHP Code Generator, Tutorials

In this article we will cover all the aspects of creating multilingual websites with the help of PHPRunner. 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 includes translations of system messages into the following languages:

Afrikaans

Arabic

Bosnian

Catalan

Chinese

Croatian

Czech

Danish

Dutch

DutchB

English

Farsi

French

German

Greek

Hebrew

Hongkong

Hungarian

Indonesian

Italian

Japanese

Malay

Norwegian

Phillipines

Polish

Portugal

Portuguese

Romanian

Russian

Slovak

Spanish

Swedish

Taiwan

Thai

Turkish

Urdu

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

Language files (*.lng)

 

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.

Label editor - custom labels

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

PHP

Method

Description

GetTableCaption($table)

Returns table caption.

GetFieldLabel($table, $field)

Returns field label.

GetCustomLabel(“LABEL_ID”)

Returns custom label.

LABEL_IDcustom label identifier.

GetFieldToolTip($table, $field)

Returns field edit tooltip.

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).

ASP

Method

Description

GetTableCaption(table)

Returns table caption.

GetFieldLabel(table, field)

Returns field label.

GetCustomLabel("LABEL_ID")

Returns custom label.

LABEL_IDcustom label identifier.

GetFieldToolTip(table, field)

Returns field edit tooltip.

mlang_message(tag)

Returns standard message. You can find the list of message tags in the file English.lng (C:\Program Files\ASPRunnerPro6.3\lang\English.lng).

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

Method

Description

GetCustomLabel(“LABEL_ID”)

Returns custom label.

LABEL_IDcustom label identifier.

Runner.lang.constants.CONSTANT_ID

Returns 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).

Example 1. Use of custom label in ASP/PHP 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 PHP code snippet to the page and use the following code in it:

PHP

echo GetCustomLabel("Message1");

ASP

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.

PHP

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

$email="test@test.com";
$from="admin@test.com";
$msg="";
$subject="New data record";


foreach($values as $field=>$value)
{

if(!IsBinaryType(GetFieldType($field)))
  $msg.= GetFieldLabel("table_name", $field) ." : ".$value."\r\n";
}
 
$ret=runner_mail(array('to' => $email, 'subject' => $subject, 'body' => $msg, 'from'=>$from));
if(!$ret["mailed"])
 echo $ret["message"];

ASP

'**********  Send email with new data  ************

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
    Next

set tmpDict = CreateObject("Scripting.Dictionary")
tmpDict("to")="--rbegin--test@test.com--rend--"
tmpDict("subject")="--rbegin--Sample subject--rend--"
tmpDict("body")=msg
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:

PHP

if ($_SESSION["language"]=="Spanish")
 {
  header("Location: mydata_spanish_list.php");
  exit();
 }
else if ($_SESSION["language"]=="French")
   {
    header("Location: mydata_french_list.php");
    exit();
   }

ASP


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:

PHP

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

ASP

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:

PHP

" language='". $_SESSION["language"] ."'"

ASP

"language='" & SESSION("language") & "'"

Multilanguage lookup wizard

Leave a Reply

Your email address will not be published. Required fields are marked *