Closed (outdated)
Project:
Select (or other)
Version:
7.x-3.x-dev
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
14 Nov 2011 at 21:38 UTC
Updated:
24 Apr 2025 at 05:15 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
danielb commentedAre 'allowed values' in normal select list fields translatable?
Comment #2
danielb commentedComment #3
danielb commentedWell it sounds like you know more about this than me, so if you can contribute any code please reopen.
I know in Drupal 7 there is a 'hook_field_prepare_translation' but I don't even get how to use it, and the field modules I'm looking at aren't giving me any clues.
Comment #4
ipwa commentedI really need the options to be translatable like regular check boxes/radio buttons from core. I am willing to sponsor a patch. Any takers?
Comment #5
ptmkenny commentedTo get a feature like this with options translated, I ended up using a core select field and the Form API/Conditional Fields module, which allows you to use the core and i18n translation features. This is a bit more involved to set up, but the translation works.
Comment #6
Drave Robber commentedI took a quick look at this and here's my tuppence.
The reason
i18n_fielddoes not pick up / translate options forselect_or_otheris that it looks by the type of the field (not widget!) and processes only list fields with finite sets of allowed values - see code here and here.Select_or_other, on the other hand, uses simpletextfield (ornumber, which is not relevant to the case at hand) which does not have an allowed values set at all.While it might be possible (not sure) to torture
i18n_fieldinto making some exceptions, I doubt if it's possible to do so in a not-too-hackish manner to get the patch accepted. Hence, an eventual solution would need to be coded from scratch (relying oni18n_string) on this end, and probably in a submodule (as only a small part of users need it).Comment #7
haydeniv commentedMarked #1922712: Make select or other translatable as a duplicate of this issue.
Comment #8
sergiu.popa commentedI also need to translate the options for select/radio buttons. Drave Robber it's right, because this module it's implemented as a widget for the Text field type, the i18n_field module doesn't register the strings to be localized.
I don't know why the creator of the module chose when coding it to provide the widget for the text field type (maybe he has a good reason). I changed the module to provide the widget for the list_text field.
select_or_other.field_widget.inc
line #13
This way you'll have the option to translate the allowed values in the interface and will use the i18n_field module (although there's a little issue with this: http://drupal.org/node/1971714). It's just a start and some more modifications are needed (because when editing the field, Allowed values appears twice). See the screenshots attached.
Comment #9
haydeniv commentedThis is a little tricker than just changing to text_list. If you do that, everyone's site who is currently using this on a text list field will break because the formatter will no longer be available. I don't know the logic behind doing this on a text field other than back in D6 and CCK it may have been easier to do this with a text field storage wise but now that fields are in core that does not seem to be the case.
If we are going to convert to a list field, we will need to adjust for integers, decimals, and floats as well. Also we are going to need an upgrade path. Really this should probably be a new major release for this feature to so people know big things are changing. Changing a field type is no small process either apparently. See http://stackoverflow.com/questions/7811840/convert-field-text-to-list-text-drupal-7.
Comment #10
Drave Robber commentedI might be wrong but methinks
text_listwon't work as it presumes a fixed set of allowed values which sort of defies the whole purpose of '...or other'.Comment #11
sergiu.popa commented@Drave Robber The functionality I think it's the same.
@haydeniv Yes, it would be the case for a major release with upgrade path. But choosing this way fewer lines of code will be necessarily. If not, custom code using i18n_string/field API.
Comment #12
haydeniv commented@sergiu.popa Makes sense to me. I actually created a new dev release for 3.x so we can get started on this.
You can track the status of the 3.x release here #1972166: META Select (or other) 3.x release
Also I marked #1832396: Internationalization Support as a duplicate of this.
Of course patches are always welcome.
Comment #13
haydeniv commentedCorrect version now that we have a release created.
Comment #14
lbainbridge commentedHere is a patch to provide some translation for Select (or other) fields. I needed this for a very specific use case, hence I didn't spend a lot of time trying to make all options work, however I think this is a step in the right direction. The only bit I am unsatisfied with is the use of hook_entity_view to show translations on the front end, however, as this module is providing a widget for the text module, I couldn't immediately think of a better way to hook in and attempt translations, suggestions and feedback are welcome.
Comment #15
miiimoooThanks for this patch. Tried it and so far works against 2.x and 3.x. Only slight problem I found is that it stores the key with the value when you enter the available options in the key|value format.
So you end up with this in the translation interface
I've added a check for this to split up the key and value and only store the value for translation.
Also a minor issue there is a ddl() call left in the code (ever tried dsm() or is ddl even better?). I've re-rolled the patch (against 3.x) and removed that.
Comment #16
stefank commentedHi @miiimooo ,
I would suggest to include "Select (or other) check boxes/radio buttons" as well. Something like:
if (isset($field['widget']['type'])) {
if($field['widget']['type'] == 'select_or_other' || $field['widget']['type'] == 'select_or_other_buttons') {
Tested the patch and it seems to be working OK.
Thanks
Comment #17
shi99 commentedThe patch in #15 worked for most things for me.
The only issues were for two lines
Line 88 was using the key for the translation string.
So it my case
for the key|value set : friends_or_family|Friends or Family
it would use
select_or_other:field_how_did_you_find_us:#allowed_values:family_or_friendsinstead of
select_or_other:field_how_did_you_find_us:#allowed_values:Family or friendsSo the translation string would not be found
I also added an isset condition on a if statement at line 494 to remove a warning that was being shown depending on my display mode settings.
I have added an updated version of the patch that worked for me.
Thanks for the help.
Comment #18
jacktonkin commentedThe attached updates #17 with the following:
htmlentities(trim())- this fixes an issue I was having with non-ascii characters in the english strings causing translations to fail.This patch is against 7.x-2.20, but I'll re-roll and follow-up.
Comment #19
jacktonkin commentedAs promised, see attached patch against 7.x-3.x.
Comment #20
umakart commentedDid I something wrong? I take the #18 patch against select_or_other-7.x-2.22., but nothing happens.
My Fields with "Select (or other) Check boxes" - Widget show not the "Available options" for translation under
Field => Translate => Fieldsettings.
Have someone a hint?
Comment #21
CalebD commented@umakart,
After applying the patch, go to the field settings page and save the field settings for each field to make sure the strings are in the translation system. From there, head to the Translation interface and search for one of the available options. They should appear and have a context like "field_example:#allowed_values:Possible Option". The patches do not address the issue of having the available options show up under the Translate tab.
Comment #22
CalebD commentedAttached is the patch from #19 rerolled against the 7.x-3.x branch and tweaked a bit.
select_or_other_field_formatter_view()to translate the option when outputting the field value. This removes the need forselect_or_other_entity_view()but means that using the "Select or other" field display formatter is required if translation is needed. This allows translation to work for any location where the field is displayed, e.g. Views in my case.Comment #23
umakart commented@CalebD
Now i got it! Thanks a lot for your guidance. My mistake to search under the Translate tab caused from this image: 3-translated-string.png
Comment #24
geek-merlinThanks everyone for the work on this patch!
#22 applied cleanly but a string refresh only refreshed "other", not the other options.
It turned out that select_or_other_i18n_string_refresh() needed some fixes.
Attached patch exposes all options on my box - please test.
Comment #25
geek-merlinNote: strange that on string refresh i get "refreshed 1 string" but all options are translatable now... Is this a "feature" of i18n?
Comment #26
agrozyme commentedI write another solution.
I18N List
need PHP 5.4+
requirement modules:
It can use Field Translation UI to help more easy to translate. (Use filed textgroup)
But I found a litte problem.
When you input 'label' as key in Available options then see a translated node page, you will see the translated value which has the 'label' key replace the field label text.
I have no idea to debug the problem, please help me.
label bug is fixed
2015/08/31: support Views Filter
Comment #27
elektrorl commentedThe patch at #24 works great, but the available options are not translated if you use a token for the 'select or other' field (eg: in DS field code).
Comment #28
rodrigoaguilera#27
I think we can get this patch in and work on follow-ups after for that use case.
I made two changes:
This was giving me a warning while creating fields using the interface not every step has the widget in the instance array.
Also Implemented hook_field_create_instance because creating select_or other fields using features the update hook is not called when you install the feature for the first time and the strings never translated until you update the instance.
Comment #30
rodrigoaguileraAdded one more check to avoid warnings when the field instance is not complete.
Comment #31
rodrigoaguileraSorry I mixed in another patch from another issue.
Forget about #30
Now I'm adding one more check to avoid warnings when the field instance is not complete.
Comment #33
rodrigoaguileraMmm I guess the settings had to be checked separately
Comment #34
legolasboThe following is just a review of the patch, no functional testing has been done.
I am all for fixing translation issues and think this should be resolved, but I don't want to add such an extensive patch without proper test coverage.
Also, I'd like the issue summary to be updated to reflect the current status quo. Which problem are we trying to solve and how do we want to solve it.
This changes nothing?
I removed available_options_php in favour of an alter hook in commit
affbee. There should be no more use of that key.This needs documentation.
Why run select_or_other_tt if the output is not used?
If we're doing this, create a helper function and call it from both
hook_field_create_instanceandhook_field_update_instanceextraneous whitespace
Needs a better, more descriptive function name.
Needs more extensive documentation
This seems like a really expensive operation. How often is this called, can't this be done in a simpler, less expensive manner?
$options is populated but never returned or used. Why?
Always return TRUE?
Comment #35
tobiasbNext round.
I replaced the hook i18n_string_refresh with hook_i18n_string_list().
Comment #37
tobiasbSmall bugfix + basic tests.
Comment #39
tobiasbDrupalCore/ CI do not understand project:module format in info files. :(
Comment #41
tobiasbI forgot the tests in the patch file. Still waiting for #2860017.
Comment #42
ikeigenwijs commentedI got the latest 7.3.x dev version
error: patch failed: select_or_other.info:6
error: select_or_other.info: patch does not apply
diff --git a/select_or_other.info b/select_or_other.info
index 51b4688..9e1bcc4 100644
--- a/select_or_other.info
+++ b/select_or_other.info
@@ -6,4 +6,7 @@ package = Fields
files[] = tests/select_or_other_admin.test
files[] = tests/select_or_other_number.test
files[] = tests/select_or_other_text.test
+files[] = tests/select_or_other_i18n.test
files[] = tests/SelectOrOtherTestBase.test
+
+test_dependencies[] = i18n
i could not find anything wrong with the patch on its self
but
+files[] = tests/select_or_other_i18n.test file does not exist
files[] = tests/select_or_other_admin.test file does not exist
files[] = tests/SelectOrOtherTestBase.test file does not exist
Comment #43
ikeigenwijs commentedTried it again from new dev download.
Now the patch works
except for the requirement line
patching file select_or_other.info
Hunk #1 FAILED at 6.
1 out of 1 hunk FAILED -- saving rejects to file select_or_other.info.rej
I have no idea why it did not take, added the line manual
Comment #44
ikeigenwijs commentedextra issue with special caracters like ' gets translated to '
solution from here kind of same issue: https://www.drupal.org/files/issues/2018-03-21/auto_nodetitle-dont_doubl...
Comment #45
tobiasbReroll.
Comment #47
philyHello Drupalers,
Patch #45 seems to be working fine using select_or_other 7.x-3.0-alpha3 and Drupal 7.63
Only the 'value' can be translated, not the 'key' (which is not a problem for my current project).
Thanks
Comment #48
tobiasbMove the part to add the test_dependencies into an own issue. #3028600: Add i18n as test_dependencies
As long as 3028600 is not commited, the testbot can not tests the patch.
Comment #49
tobiasbComment #50
daften commentedClosing as outdated because no activity in a long time and Drupal 7 goes EOL soon. Feel free to re-open if needed.
Comment #51
leducdubleuet commentedPatch in #48 is still working well against current 7.x-3.x-dev.
Thank you very much!
Comment #52
leducdubleuet commentedComment #53
ivnishAutomatically closed because Drupal 7 security and bugfix support has ended as of 5 January 2025. If the issue verifiably applies to later versions, please reopen with details and update the version.