Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By rantebi on
Hi,
I've added some CCK seleclist fields to my site.
They have the following allowed values:
0|Attorney
1|Associate
2|Intern
How can I translate the textual values?
In drupal 6 you had the option to write PHP code for allowed values, so in that way translation was available (For more details see http://drupal.org/node/182884#comment-280925).
But I don't see an equivalent field in drupal 7...
Neither can i find any other issues that solves this problem.
Does anybody have a clue?
Comments
I created a new formatter for the field...
After searching and posting in many blogs i found no answers. this is the solution I found:
This is copied almost exactly from the list core module, I just added the t function.
Usually you better not translate with t dynamic expressions but I was a bit lazy -> does anybody have a better way?
Instructions:
1. Add this code to any of your enabled modules.
2. You would then have to select the "Default with localization" in your content-type's manage display section.
3. The terms you support in your field should be translated and imported to the translation interface under "Built-in interface".
cool.
good post.
hook_form_alter would let you
hook_form_alter would let you adjust #options values less invasively. You might instead store a list of "translatable" content types as a variable, with eventual configuration with a setting on the content type itself. Then the fields could remain untouched.
The D7 version of cck module
The D7 version of cck module lets you write PHP code for allowed_values, just like in D6.
Where
"D7 version of cck module lets you write PHP code for allowed_values"
- where/how do you see that ?!?
Custom module
You have to implement a hook in a custom module.
in case anyone up to this,
in case anyone up to this, there are two methods to provide:
1. install D7 cck module, and you have new textarea for PHP code, and also a textfield to supply a function name for that array.
2. use hook_field_info_alter, there is a allowed_values_function, you can supply that function name also
p.s. I am using first method, on cck 7.x dev 2011-Aug-23
Here it is
Took me hours to find. Though it's for Fields, it might work with CCK.
First you need to translate the values in the field form (/admin/structure/types/manage/MYNODETYPE/fields/MYFIELD/translate). Then go to "Manage display" (/admin/structure/types/manage/MYNODETYPE/display) and set the format of MYFIELD to "Default translated".
See http://drupal.org/node/1218880
Thank you
... it worked like a charm. I was wondering why field names showed up correctly, while the values didn't.
Perfect
That made the trick. thanks!
Yul63: excellent! Simple and
Yul63: excellent! Simple and elegant. Many thanks.
Thanks a lot
It works perfect.
Thanks
Thank you so much! You saved my day. Was going crazy over this one.....
Thanks, for this trick...
Thanks, for this trick...
Thanks !!
That's exactly what i need, thanks my savior !!
Thank you so much!
Thank you so much! it works really well...
You are my hero. Thank you so
You are my hero. Thank you so much.
help
guys i did every thing but still not working !!! the list still in english !!
any idea ?
by the way the select list in search views ,,,,
worked great for me. Thanks!
worked great for me. Thanks!
views
wow thanks. but don't work for translate dropdowns in the exposed filters in the views. any further idea? tks
This is what you need:https:/
This is what you need:
https://www.drupal.org/project/i18nviews
big thanks
Even years later this article still does a wonderful job of giving someone new to Drupal Translations a good overview of the pro's con's between these two approaches!
Thank you!!
steps for how to translate the select list
hello guys i found the solution for how to translate a select list in a views after a lot of searching follow this steps and i hope that's will work
step 1: translate the select list in (structure/content types/Manage fields) and translate the options there.
step 2: go to (structure/content types/Manage display)and change the format for the select list from default to default translated .
step 3: go to the view and change the old content in FILTER CRITERIA to the new content the translated one .
by this steps the select list will be translate ;)
Thank you
Thank you very much)
U welcome my friend ;)
U welcome my friend ;)
Do not use t() for dynamic strings, use i18n module
Look at how i18n_field_field_formatter_view() checks if there is a translation function available before falling back to printing out the untranslated list. (This function first checks to see if the 'Default Translated" formatter has been selected. If you always want translated strings, skip that part.)
For facets you could use the
For facets you could use the hook_facet_items_alter.
Goto your facet configuration, check the box "Rewrite facet items via callback function" as active filter and in the filter settings.
Then implement the hook in your module:
Freelance Drupal developer, contact me if you want help on your Drupal project.
allowed values translation
I have a content type set to French but the allowed values on the field select lists are actually English. I'd like to define the field to be French and translate the field values (it's not important that the original values are in English, they will never be displayed). But in the translate interface the English field values are assumed to be French. Any way of setting the field language to English so the French values can be created?