Localizing PHPRunner/ASPRunnerPro applications

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_ID - custom 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_ID - custom 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_ID - custom 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

  1. echo GetCustomLabel("Message1");

ASP

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

  1. //********** Send email with new data ************
  2.  
  3. $email="test@test.com";
  4. $from="admin@test.com";
  5. $msg="";
  6. $subject="New data record";
  7.  
  8. foreach($values as $field=>$value)
  9. {
  10.  
  11. if(!IsBinaryType(GetFieldType($field)))
  12. $msg.= GetFieldLabel("table_name", $field) ." : ".$value."\r\n";
  13. }
  14.  
  15. $ret=runner_mail(array('to' => $email, 'subject' => $subject, 'body' => $msg, 'from'=>$from));
  16. if(!$ret["mailed"])
  17. echo $ret["message"];
  18.  

ASP

  1. '********** Send email with new data ************
  2.  
  3. Dim dkeys, tmpDict, msg, n
  4. msg =""
  5. dkeys = values.keys
  6. For n = 0 To values.Count-1
  7. if not IsBinaryType(GetFieldType(dkeys(n),"")) then
  8. msg = msg & GetFieldLabel("table_name",dkeys(n)) & " : " & values(dkeys(n)) & vbcrlf
  9. end if
  10. Next
  11.  
  12. set tmpDict = CreateObject("Scripting.Dictionary")
  13. tmpDict("to")="--rbegin--test@test.com--rend--"
  14. tmpDict("subject")="--rbegin--Sample subject--rend--"
  15. tmpDict("body")=msg
  16. set ret=runner_mail(tmpDict)
  17. if not ret("mailed") then
  18. response.write ret("message")
  19. end if
  20.  
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

  1. if ($_SESSION["language"]=="Spanish")
  2. {
  3. header("Location: mydata_spanish_list.php");
  4. exit();
  5. }
  6. else if ($_SESSION["language"]=="French")
  7. {
  8. header("Location: mydata_french_list.php");
  9. exit();
  10. }

ASP

  1.  
  2.  
  3. if SESSION("language")="Spanish" then
  4. Response.Redirect "mydata_spanish_list.asp"
  5. else if SESSION("language")="French"
  6. Response.Redirect "mydata_french_list.asp"
  7. end if
  8.  

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

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

ASP

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

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

ASP

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

Multilanguage lookup wizard

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>