Jump to content

Translate Select Options Fieldtype when getting all available options


Neo
 Share

Recommended Posts

I have a select options field, which needs to be translated.

The translation works fine as long as you echo the available options page-specific.

Now, according to the documentation, when you need to display all possible options (independently of any page), you would do something like this:

<?php
  // Get all category options
  $field = $fields->get('project_category');
  $all_options = $field->type->getOptions($field);

  foreach($all_options as $option) {
      echo "<option value='.{$option->title}'>{$option->title}</option>"."\n";
  } ?>

 

The problem is that this does not pass the translated language values for each option.

It will display always in the default language.

 

Any idea how to get the translations in this situation?

 

Link to comment
Share on other sites

I had to change the default language check to get it working:

 

foreach($all_options as $option) {

       $title = $user->language->name == 'default' ? $option->title : $option->get("title$language");
       echo "<li><a href='#' class='filter-category' data-filter='.$title'>$title</a></li>"."\n";

} ?>

 

Don't know why $language->isDefault() always fails...

Link to comment
Share on other sites

  • 4 years later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...