We are working on an application with custom content types using fields in core. The site is supposed to be translated to German, and most fields in our content types are translatable, but we have a couple of "checkbox" fields (boolean, "simple on/off checkbox"), which do not seem to translatable, either the label or "help text".
I believe this issue applies to the HEAD version of D7, but we are using v. 7.0 (I can't find any issue which seems to directly relate to what we are seeing with the labels/help text for checkboxes). In fact I just tried to reproduce the issue in HEAD, and found that when I do a default install, turn on the locale module, add German as a site language and turn it on as "default", no German shows up on the site at all. So it seems you need to manually add the translation files in HEAD and I'm not sure what to do there. In the 7.0 version, this seems to be automatic; I think with just the core "Locale" module on and turning on German as the default language (it downloads files, then the site is in German and we can add our own custom translations for our extra fields).
I'll send a link to this issue to my colleague who was actually struggling with this issue today since he can likely add a bit more detail, but apparently this is not an isolated case. In my Google search, I found some discussion related to this issue on a German site:
http://www.drupalcenter.de/node/32639
But as far as I can tell, this issue is new to the queue here.
| Comment | File | Size | Author |
|---|---|---|---|
| #18 | 1061438-5.patch | 1.99 KB | xdong |
| #4 | 1061438-4_118n-boolean-fields.patch | 2.84 KB | mikeker |
| #4 | boolean-custom-text.png | 12.62 KB | mikeker |
| #3 | translate-bool-field-settings.png | 29.2 KB | mikeker |
Comments
Comment #1
franzThis applies to 8.x as well.
IMO, options labels - for radios and checkboxes - should be translated on _options_prepare_options()
Comment #2
nwom commentedThe option and label is translated only when selecting "Default translated" instead of "Default" under "Manage Display." However the help text does not show as translated no matter what is chosen. Even if the string has been translated, it shows only the source. At least this is the case in the most recent version of Drupal 7.
Comment #3
mikeker commentedI just verified this with the latest 8.0.x. The label and help text are available for translation but the "On" and "Off" labels are not.
Adjusted the title to match the issue in 8.x. That'll need to change if/when this gets tagged for backporting to 7.x.
Comment #4
mikeker commentedTurns out the Custom text field is not translatable either.
The attached patch fixes that issue.
However, I wasn't able to get the On/Off values to show on
admin/structure/types/manage/article/fields/<node-type>.<field_machine_name>/translate/<language>/edit. I tried adding a@FieldTypeannotation similar to that forImageItem, but that only allowed a translation when the content is being edited. I was trying to get it to show like the default value for ImageItem.Any pointers would be appreciated.
Comment #5
mikeker commentedOh, the above patch also adds a
settingsSummaryfunction which is missing for this formatter. Technically out of scope for this issue -- let me know if that needs a new issue instead.Comment #7
mikeker commentedTestbots were having problems and terminating part-way through, according to IRC. Retrying...
Comment #9
mercepedraza commentedI'm working on this in the mentored sprint in the Drupalcon Barcelona. I'll try to apply the patch and submit again the test.
Comment #11
sutharsan commentedI mentored @mercepedraza during DrupalCon Barcelona. Our discussion concluded that the patch in #4 uses a wrong approach.
Wrapping a t() around a method call is D7 style of translating a configuration value. As far as I know, we can allow the default configuration to be translated by adding a schema for this form.
Comment #12
lomo commentedIn IRC, Sutharsan agreed that this should have been set back to "Needs work". If the issue has not been fixed or nobody else has assigned it to themselves by next week (when I hope to have some more sprinting time) and if someone has some tips for what the "right approach" would look like, perhaps I can make a patch that conforms to that.
Comment #13
sutharsan commentedThis is a partial solution that adds modifies the core data type to make the on- and off-labels translatable.
Some faults that needs to be addressed:
Notice: Undefined index: field.storage.node.field_boolean in Drupal\config_translation\Form\ConfigTranslationFormBase->submitForm()Todo:
Comment #14
badrange commentedA colleague tipped me about this issue:
https://www.drupal.org/node/2609874
Are these duplicate of one another?
Comment #15
mikeker commented@badrange, I think you're right. And, as #11 points out there are better ways to do this, which are being used in the issue you linked to. I'll open a followup for the missing setSummary().
Comment #16
mikeker commentedOpened #2671446: The Boolean field formatter does not provide a settings summary to handle the missing settingsSummary.
Comment #17
proweb.ua commented/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/BooleanFormatter.php
change
'@true_label' => t($this->getSetting('format_custom_true')),
'@false_label' => t($this->getSetting('format_custom_false')),
Comment #18
xdong commented