Multi Language Support

abstract Websites may be enabled in multiple languages like English, Spanish, Chinese etc. Sahi's multi-language support allows testing of websites in any language using the same scripts as long as translations are available.

In most applications, Internationalization (I18N) and Localization (L10N) are done by specifying constant keys in web application code, and then having another layer substitute these constant keys with the correct language translations provided via property files. These translations are normally kept in properties files. Eg. en.properties (english), de.properties (german) etc.

Since Sahi's scripts rely on visible text, the scripts may be recorded with English text. To play it on the German version, the script needs to be passed the English and German property files. When Sahi encounters an English string, it will look up the corresponding key in en.properties, then lookup the German value for that key in de.properties file and then use that value during execution.
info _setLanguage needs the translation properties files. However, note that these need not be created by the tester. These should already be available with your web development team.

Set Language

    infoNOTE: $append was added Since Sahi Pro: 6.2.1. For old document Refer here
Sets the language in which the script will be executed.

Example: Assume a web application with a button which shows up as "Thank You" in English and "Danke" in German.

If the script was recorded on the English version, it would look like:

Parameters
$translateTostring Path to properties file for language to translate to (eg. for English to German, this may be de.properties). Paths are relative to script.
$translateFromstring Path to properties file for language to translate from (eg. for English to German, this may be en.properties). Paths are relative to script.
$appendboolean optionalIf true, appends the properties. Default is false. Sometimes translations may be split across multiple files. In such cases, multiple calls to _setLanguage may be needed.
Return Value

Modes Supported :
Raw Script
_click(_button("Thank You"));

Sahi Pro Classic API :_setLanguage


Multiple Translation Files

Sometimes translations may be split across multiple files. In such cases, multiple calls to _setLanguage may be needed. For example, say we have german_admin.properties and en_admin.properties for translations in admin module we have german_user.properties and en_user.properties for translations in user module For a script that spans both such modules, translations from both files will be needed. The usage is:
_setLanguage("german_admin.properties", "en_admin.properties");
_setLanguage("german_user.properties", "en_user.properties", true); // append is set to true so that both translation files are available.
_click(_button("Thank You"));


Controlling Translation

Do NOT Translate. Use String Literal (L:)

If a string should not be translated, it can be prefixed with "L:" Eg.
_setLanguage("german.properties", "en.properties");
_log("L:Hi there!"); // will print "Hi there!"
Use this when you use strings in your script which are not visible text on the application and you want to ensure that those strings will NOT be translated.

Provide the Key itself, instead of reverse look up (K:)

Eg.
_setLanguage("german.properties", "en.properties");
_log("K:THANK_YOU"); // will print "Danke"


Use this when the same English word has two translations in German.

info Sample script setLanguageGoogle.sah and translation files are available in userdata/scripts/sahitests/mls/sample folder.