Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By amin.m-1 on
Hi,
I would like to translate taxonomy terms within my own PHP code snippets (embedded in custom blocks). Translations for the terms are provided by the "translation table"-module, i.e. I filled out the translation table for the corresponding taxonomy.
However, a call of
t($term->name)
where $term is a valid term object does not translate the term. It remains unchanged in the source language.
Should this work? Does it need additional steps to use the t-function on taxonomy terms?
Current version is Drupal 6.13 with all modules up to date.
Thanks,
Amin
Comments
Solution: tt() instead of t()
Finally, I have found a solution to get the translated name of a taxonomy term. The tt()-function instead of the t()-function does the job because taxonomy terms are treated as "user defined strings".
It has slightly more complicated arguments. A call looks like this:
$name=tt("taxonomy:term:$term->tid:name", $term->name);
In order to find out how to build the first argument ("taxonomy:term..."), it is useful to have a look at the search results shown under http://yourhostname/admin/build/translate/search (Menu: Site Building -> Translate interface -> Search). You have to concat the text group of column 1 with a colon (":") and the details shown in column 2.
Greetings,
Amin
Thanks, this was helpful for
Thanks, this was helpful for me.
maybe stupid question, I'm
maybe stupid question, I'm not fully understand.. is it translatable without any patching? can't find the strings..
i18n
needs i18ntaxonomy module which comes with http://drupal.org/project/i18n
you save my day!
Thanks! it was just waht I needed.
user defined strings are in po files like this:
#: term:321:name
msgid "apple"
msgstr "poma"
Actually you just need the term id and term name and build de string for the first argument of tt(). It's true you need i18n taxonomy module
Nice
Thanks