Need to display Transalted (Localized) Vocabulary Name in Views field.



rondev’s picture

NIKS_Artreaktor’s picture

No it is not the same!

I have this setting already on. (Set Translation method to " Internationalization Views ")

In Views field we choose taxonomy term.
In the same time we have taxonomy term (translated)

What about Vocabluary name to display?
we have not it translated.

NoRiSs’s picture


I've got the same problem.
I've got the i18n and i18n_views moduls turned on and I have translated the all vocabulary names and the terms as well.
Then I wanted to make a list that is contains the terms grouped by the vocabulary names. So I made a block view. The list is displaying correctly in the original English language, but when I switch to French I have got the terms looking correct but the vocabulary names still appearing in the original English language.
The taxonomy vocabulary multilingual setting is the follows: "Localize. Terms are common for all languages, but their name and description may be localized."

In the block view I could chose the "taxonomy term name(translated)" field and it is displaying correctly in every language. But for the vocabulary name there is no option to chose translated verison even it has already translated to other languages.

Is there any solution for this issue?


nadav’s picture


decibel.places’s picture

Issue summary:View changes

I couldn't find a solution either, so I am using a custom template for the Vocabulary Name field.

I have a view that uses the Relationship: Taxonomy term: Entity translation: translations

Then I can display the fields:
Taxonomy vocabulary: Name
Taxonomy term: Rendered Taxonomy term

I copied the Views template views-view-field.tpl.php to my theme templates, and renamed it views-view-field--topics--page--name.tpl.php
(my View display is "page" and don't forget to rescan your templates!)

Another thing I like to do is group my custom Views templates by sub-folder "View Name" in the templates folder. I have a few of them for translated Views.
For example using Zen, sites/all/themes/{theme name)/templates/{view name}/views-view-field--topics--page--name.tpl.php

here is the code that returns the i18n_taxonomy_vocabulary_name for the vocabulary.

assuming that the Vocabulary machine name is the same as the Display name, but lowercase and with spaces replaced by underscores; if not, you need to do more lookups ;)

also, I could not find the vocabulary vid value in the $view, so I am looking it up by the machine name in the array returned by taxonomy_vocabulary_get_names()

  $vocabname = $row->taxonomy_vocabulary_name;
  $vocabname = strtolower(str_ireplace(" ","_",$vocabname));
  $vocabnames = taxonomy_vocabulary_get_names();
  $vocabvid = $vocabnames[$vocabname]->vid;
  $vocabulary = taxonomy_vocabulary_load($vocabvid);
  $langcode = i18n_langcode();
  $i18nvocab = i18n_taxonomy_vocabulary_name($vocabulary, $langcode);
  print $i18nvocab;
Wtower’s picture

@decibel.places (#5) excellent workaround. Finally a breakthrough for such a miserable problem. In case anyone wonders there is also a function i18n_taxonomy_term_name (although a views field exists).

mourad2011’s picture

modified code (#5)

  $vocabname = $row->taxonomy_vocabulary_machine_name;
  $vocabnames = taxonomy_vocabulary_get_names();
  $vocabvid = $vocabnames[$vocabname]->vid;
  $vocabulary = taxonomy_vocabulary_load($vocabvid);
  $langcode = i18n_langcode();
  $i18nvocab = i18n_taxonomy_vocabulary_name($vocabulary, $langcode);
  print $i18nvocab;
devad’s picture

Hi. Thanx for help! #6 works nice.

I had to translate exposed form vocabulary names as well.

I have managed to do that as follows:

 * Implementation of hook_form_FORM_ID_ater()
function MY_MODULE_form_views_exposed_form_alter(&$form, &$form_state){
  if($form['#theme'][0] == 'views_exposed_form__VIEW_NAME__VIEW_ID'){
    $langcode = i18n_langcode();
    foreach ($form['vid']['#options'] as $vid=>$name) {
      if (is_numeric($vid)) {
        $vocabulary = taxonomy_vocabulary_load($vid);
        $i18nvocab = i18n_taxonomy_vocabulary_name($vocabulary, $langcode);
        $form['vid']['#options'][$vid] = $i18nvocab;

In my case, VIEW_NAME is "find_terms" and VIEW_ID (machine name) is "page_1".

Thanx sydneyshan for help: #364859: How to alter filter in exposed filters form trough form_alter hook (#11)

seekerakos’s picture

I achieved to make it work with the hook_views_pre_render(&$views).
I found the results and I had already passed the vocabulary machine name as parameter and was easier to translate them.

$i = 0;
  foreach($views->result as $vocabulary){
    $vocabulary =  taxonomy_vocabulary_machine_name_load($vocabulary->taxonomy_vocabulary_machine_name);
    $i18n_voc = i18n_taxonomy_vocabulary_name($vocabulary);
    $views->result[$i]->taxonomy_vocabulary_name = $i18n_voc;

When I tried to change vocabulary name without the pointer($i) ex($vocabulary->taxonomy_vocabulary_name = $i18n_voc;) it didn't work. I am not sure, but i believe something happened with the views reference(&$views).