Neo Posted August 31, 2016 Share Posted August 31, 2016 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 More sharing options...
BitPoet Posted August 31, 2016 Share Posted August 31, 2016 foreach($all_options as $option) { $title = $language->isDefault() ? $option->title : $option->get("title$language"); echo "<option value='$title'>$title</option>"."\n"; } ?> Link to comment Share on other sites More sharing options...
Neo Posted August 31, 2016 Author Share Posted August 31, 2016 That will always display the foreign language version, also for the default language. Link to comment Share on other sites More sharing options...
BitPoet Posted August 31, 2016 Share Posted August 31, 2016 Did you try it? The translated contents of an option are in its properties title$languageid and value$languageid. Link to comment Share on other sites More sharing options...
Neo Posted August 31, 2016 Author Share Posted August 31, 2016 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 More sharing options...
Cybermano Posted November 2, 2020 Share Posted November 2, 2020 Hi everybody. I refresh this old thread because I had also the same issue. For the solution I have found (don't remember where*): echo $option->getTitle(); For me it works fine, hope to be helpful. *found here, thanks @schwarzdesign : 2 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now