Hello,

I hope I am posting this in the right place and in the proper way. I have read through the various issues similar to this but I have not found a solution to my problem.
Here is my issue :

What i want to achieve :

  • an exposed filter with translated taxonomy terms that are ordered in the displayed language.
  • be able to translate the taxonomy term from taxonomy term issue and not from string translation

What i've got :

  • an exposed filter with terms translated in the Translate interface section.
  • the order of elements in the exposed filter is in the alphabetical order of the elements in the original language.

The activated modules I am using :

  • Views 7.x-3.7
  • Entity Translation
  • Internationalization 7.x-1.11
  • Multilingual content 7.x-1.11
  • String translation 7.x-1.11
  • Taxonomy translation 7.x-1.11
  • Translation sets 7.x-1.11
  • Variable translation 7.x-1.11
  • Views translation

Detailed description of my problem :

There is a Content Type DOCUMENTS set to :

  • Multilingual support : Enabled, with field translation
  • Extended language support Normal - All enabled languages will be allowed.

The content type has a Term reference entitled CLASSIFICATION which is a Autocomplete term widget (tagging) type.

The Term reference refers to a taxonomy called DOCUMENT CLASSIFICATION which is set to
Localize. Terms are common for all languages, but their name and description may be localized.

When I look edit each item of the DOCUMENT CLASSIFICATION taxonomy I have a translate tab. I can also go into /admin/config/regional/translate to translate the term string.

Now I have a view that lists all the nodes of type DOCUMENTS and an exposed filter to filter according to DOCUMENT CLASSIFICATION.

This exposed filter works fine in original language FRENCH

However in ENGLISH (i.e. when user has selected ENGLISH for navigating) the exposed filter has the translated terms but in the alphabetical order of the original terms in FRENCH.

I would like to achieve one of two things :

- Use the translated content for the taxonomy list item as opposed to the translated string to populate the exposed filter.
- Have the translated strings in the alphabetical order of the display language.

Any help would be much appreciated

Comments

wishiwas’s picture

I think that I have come up with a working solution, although I'm not 100% clear as to the explanation :

  1. I de-activated entity translation for taxonomy terms in the interface here : /admin/config/regional/entity_translation
    • This means that the translation of terms is dealt with entirely by the Taxonomy translation module
    • It also means that the term can be translated directly from the term interface
  2. I added a function to a custom module in order to order things alphabetically in the exposed filter as described here : http://drupal.stackexchange.com/questions/23233/how-can-i-sort-options-i... (thanks to Derek DeRaps where-ever you are!)
wishiwas’s picture

Status: Active » Closed (works as designed)
A.Kotov’s picture

Wishiwas, thank you for pointing to the function from Derek DeRaps
It works but only with 1 level taxonomy vocabulary.
Any idea how to improve it?

mas0h’s picture

Thanks for the code from this http://drupal.stackexchange.com/questions/23233/how-can-i-sort-options-i...

But how about sorting in node add/edit form?

Thanks

morybel’s picture

Hi,

THanks to the function from Derek DeRaps I was also able to get this fixed, but I get this warning on my site:

Warning : asort() expects parameter 1 to be array, null given in sorttaxonomy_form_views_exposed_form_alter() (line 4 in /home/mysite/public_html/sites/all/modules/_custom/sorttaxonomy/sorttaxonomy.module).

line 4 is for
if($fid = $filter->options['expose']['identifier']) asort($form[$fid]['#options']);

Any idea?

morybel’s picture

Also, is there a way I can target only one filter box with this function? I have several other exposed filter that doesn't need to be sorted that way. Thanks for any help.

morybel’s picture

Well, a little search and I got my answer,

I found a solution here http://drupal.stackexchange.com/questions/149015/7-sorting-a-views-expos...

This is my adapted code :

function sorttaxonomy_form_views_exposed_form_alter(&$form, &$form_state){
if ($form['#id'] == 'views-exposed-form-search-profile-page') {
    $form['#after_build'][] = '_sort_alphabetically';
  }
}
function _sort_alphabetically($form, $form_state) {
        foreach ($form_state['view']->filter as $field => $filter) {
            if ($filter->options['exposed']  && $filter->options['id'] == 'tid_i18n_4' ) {
                $field_id = $form['#info']["filter-tid_i18n_4"]['value'];
                asort($form[$field_id]['#options']);
            }
        }
        return $form;
}

views-exposed-form-search-profile-page is the name of my views
tid_i18n_4 is the name of my filter

Hope it helps someone.