I have created a content type (pdf_form) to which I added a field_gender_languagetest with two options, male and female. I translated both the options in German using the translation tab.
Now I am generating a report of the data filled by users using that content type.
Is there any way to programmatically get that translation?
I am trying this code, but it doesn't work.
t('male', array(), array('langcode' => 'de'));
my working solution
$lang ="de";
if ($lang != "en") {
$langs = language_list();
$lang = $langs[$lang];
foreach ($val['#base']['#node'] as $k => $v) {
if (isset($v['#type']) && $v['#type'] == 'list_text') {
foreach ($val['#base']['#node'][$k]['#value'] as $k_sub => $v_sub) {
$trns_str = pdf_trans($v_sub, $lang, 'field');
$val['#base']['#node'][$k]['#value'][$k_sub] = $trns_str['trans'];
}
}
}
}
Function
function pdf_trans( $string, $lang = NULL,$group = 'default') {
$result = db_query("SELECT s.lid, s.source, s.context, s.location, t.translation, t.plid, t.plural FROM {locales_source} s LEFT JOIN {locales_target} t ON s.lid = t.lid AND t.language = :language WHERE s.textgroup = :textgroup and s.source = :string_value ORDER BY t.plid, t.plural", array(':language' => $lang->language, ':textgroup' => $group, ':string_value'=>$string));
$str= array();
if($result){
foreach ($result as $child) {
$str= array(
'trans' => isset($child->trans) ? $child->trans : '',
'trans_availabe' => '1',
);
}
}
if(count($str)==0)
{
$str= array(
'trans' => $string,
'trans_availabe' => '0',
);
}
return $str;
}
This shoudn't be the right way because drupal have must this functionality as core