Formulize

Forms, workflows, and reporting. 100% free and open source.

Version 7.3 out now!How to installHow to update

Download .zip View on GitHub Join us on Slack Follow on Twitter

trans( (string) $string, (string) $lang = null )

Location

/modules/formulize/include/functions.php

Description

Removes the language tags from a string, and leaves only the active language text, or the specified language text if one is specified.

Users generally have some mechanism to control which language is active at the time. There is some browser language detection in effect also, which can make an initial determination automatically sometimes.

Users can force a certain language to be active by appending &lang=fr for example to the URL.

Parameters

$string - The string containing the language text, ie: [en]English text[/en][fr]texte français[/fr]
$lang - Optional. The langauge tag of the language you wish to keep in the text.

Return Values

Returns the string with the text for the other language(s) removed.

Examples

// convert the string to the currently active language
$string = trans("[en]English text[/en][fr]texte français[/fr]");
// convert the string to the French, regardless of the active language
$string = trans("[en]English text[/en][fr]texte français[/fr]", "fr");
// convert the string to the currently active language, then truncate it to five characters
$string = trans("[en]English text[/en][fr]texte français[/fr]");
$string = printSmart($string, 5);