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.

_setLanguage

Since: Sahi ProSahi OSSahi Pro StarterDesktop Add-OnMobile Add-On
6.2.0NANA7.0.07.5.0

Available for modes: Browser | Windows | Java | Android | iOS

_setLanguage($translateTo, $translateFrom[, $append])

Arguments
$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.

Returns
null

Details

    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:

_click(_button("Thank You"));


If the code was to be executed on the German site, it would fail because the button there says "Danke".

If this application had been internationalized, it would have property files with the correct translations. Eg.

# en.properties
...
THANK_YOU=Thank You
... other keys


# german.properties
...
THANK_YOU=Danke
... other keys


Modify the Sahi script and provide these translation files:
_setLanguage("german.properties", "en.properties");
_click(_button("Thank You"));


This will actually execute
_click(_button("Danke"));
on the browser.


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/demo/mls/sample folder.