Replace recurring strings. In this example I needed to translate languages from a radio button in ACF manually.
$lang = get_field('language_in_english');
<p> <?php translate_other_lang($lang); ?> </p>
function translate_other_lang($lang) {
// if current language is dutch replace string and return new one
if(qtrans_getLanguage() == "nl") {
$searchReplaceArray = array(
'Arabic' => 'Arabisch',
'Portuguese' => 'Portugees',
'Lithuanian' => 'Litouws',
'Turkish' => 'Turks',
'Russian' => 'Russisch',
'Bosnian' => 'Bosnisch',
'Serbian' => 'Servisch',
'Croatian' => 'Kroatisch',
'Japanese' => 'Japans',
'Romanian' => 'Roemeens',
'Latvian' => 'Lets',
'Mandarin' => 'Mandarijns',
'Spanish' => 'Spaans'
);
$result = str_replace(
array_keys($searchReplaceArray),
array_values($searchReplaceArray),
$lang
);
echo $result;
}
// if current language is english just return $lang again
else if(qtrans_getLanguage() == "en") {
echo $lang;
}
}