Digging into the api looking for methods to translate a property of a category term I could only find methods that take a string as the param, but what happens when I have the id of the object which property I want to translate? I'd like to be able to just pass this id and get the translated string (if exists). I achieved this with a relatively simple query:
function translate_term_description($tid) {
$result = db_query('SELECT term_data.tid, term_data.description, locales_target.translation
FROM {term_data}
left join ({i18n_strings}, {locales_target})
on (term_data.tid = i18n_strings.objectid and i18n_strings.lid = locales_target.lid)
where term_data.tid = %d', $tid);
$term_data = db_fetch_object($result);
// If a translated string is available return that, otherwise return back the untranslated description
return !is_null($term_data->translation) ? $term_data->translation : $term_data->description;
}
I just needed the description and I'm just using this function in a context where's it's assumed that the target language is the non-default. Still, it can be expanded to take both the target language and the term property as params.
So what do you think? Should something like this exist on Drupal, or does it have it already (if so, please point me where) ?