Drupal 7 get localized taxonomy data in custom php code
I'm working on a drupal site, and I need to have an information page for taxonomy data.
The taxonomy data has some extra fields that are displayed, including a custom link.
The default taxonomy page does not allow a custom link开发者_JS百科, and it will show the content assiociated to the term, I don't want that.
I made a module that outputs a block, and I'm basicly using this code
$term = taxonomy_term_load($termId);
This works fine, but I can't get the translated version of the taxonomy! I'm using the i18n module.
How can I get the localized version of the taxonomy?
Thanks in advance,
Jorik
The langcode parameter of taxonomy_term_view()
is used to filter by the language of associated nodes. it is (unfortunately?) not related to the language of the term itself.
You can get the i18n-localized term with
$term = taxonomy_term_load($tid);
if (module_exists('i18n_taxonomy')) {
module_load_include('inc', 'i18n', 'i18n_taxonomy.pages');
$term = i18n_taxonomy_localize_terms($term);
}
print render(taxonomy_term_view($term, 'full'), $language->language);
You need to run your term object through taxonomy_term_view()
, that will build the view for you with a particular language code. You can get the 'current' language for the page using the global $language
object:
global $language;
$term = taxonomy_term_load($termId);
$view = taxonomy_term_view($term, 'full', $language->language);
$html_output = render($view);
Just a tip, as of writing the Views module doesn't fully support localized terms, as the default taxonomy pages do. You could check out http://drupal.org/project/i18nviews
精彩评论