Skip to content
Get Free Trial

Multi Language Support

Websites may be enabled in multiple languages like English, Spanish, Chinese etc. Sahi Pro'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 resource files. These translations are normally kept in resource files. Eg. en.properties (english), de.properties (german), Resources.de.resx (german), resources.fr.xaml (french), etc. Since Sahi Pro 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 resource files. For example, 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.

Since
Sahi Pro 6.2.0
Desktop Engine 7.0.0
Mobile Engine 7.5.0
SAP Engine 9.0.0

Modes BrowserWindowsJavaAndroidiOSSAP

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

Arguments

NameTypeDescription
$translateTostringPath to resource file for language to translate to. For example, to translate from English to German, specify here the resource file path for German language. Paths are relative to script.
$translateFromstringPath to resource file for language to translate from. For example, to translate from English to German, specify here the resource file path for English language. Paths are relative to script.
$appendbooleanoptionalIf 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

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

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"));

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

Section titled “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.