« Back to Product

Documentation

IPS_Translate

 string IPS_Translate (int $InstanceID, string $Text) 

Parameters

InstanceID

ID of the instance whose module provides the translations

Text

Text to translate (usually the original English text)

Returns

Translated text, or Text unchanged if no translation exists

Description

The function translates Text with the translations of the module of the instance with the ID InstanceID into the system language (IPS_GetSystemLanguage). It corresponds to calling Translate inside a module, but can be used from outside, e.g. to output texts of a module in a script in the same language.

It looks for an entry whose key matches Text exactly. For PHP modules, the translations come from the locale.json of the module, for built-in modules from the translations shipped with the module. For the system language, the full locale (e.g. de_AT) is searched first, then the language code used as country code (de_DE) and finally only the language code (de).

If there is no locale.json, no translation for the system language or no matching entry, Text is returned unchanged. If the locale.json of a PHP module is not valid JSON, the function fails with "Cannot parse locale.json". Placeholders like %s are not replaced; this can be done after the translation, e.g. with sprintf.

Example

echo IPS_Translate(12345, "Users");
// e.g. returns: Benutzer (on a German system)
// (without a matching translation, "Users" is returned unchanged)

printf(IPS_Translate(12345, "The current time is %s"), date("H:i"));
Any questions?