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.
As soon as I enable Token module the field widget descriptions are not translated any more with the I18N module.
Problem here is that I18N doesn't translate the original field instance and in widget_form_alter the untranslated instance is used.
How to reproduce:
* Enable I18N and i18n_fields
* Create two languages
* Translate the description of a field
* Check the form with the field - Depending on the language the description should be translated.
Comment | File | Size | Author |
---|
Comments
Comment #1
kfritscheTwo solutions here:
1. Attached as patch, which is the nearest to the current solution in my mind.
2. Using just the following in the same function:
But I thought there was maybe an intention behind this why the description of the instance was used here?
Using $element here would also allow to add tokens to the description with an hook_widget_form_alter before tokens alter.
Comment #2
m_angel CreditAttribution: m_angel commentedThanks @kfritsche for the patch, but it doesn't work propely for me. After review it, I attach a new patch that works fine for me.
Regards!
Comment #3
m_angel CreditAttribution: m_angel commentedComment #5
penyaskitoDo we really want this or module_exists instead?
Comment #6
kfritscheFuck, yes module_exists.... Thx @pennyaskito
New patch attached.
Comment #7
penyaskitoBack to Needs review.
Comment #8
wanjee CreditAttribution: wanjee commentedPatch #6 worked like a charm for me !
Comment #9
Zekvyrin CreditAttribution: Zekvyrin commentedAlso works for me and i think it's ok.. shall we commit it?
Comment #10
Dave ReidWould #2367721: Token prevents display of i18n field submodule translations also work to solve this in a more cleaner way?
Comment #11
Zekvyrin CreditAttribution: Zekvyrin commented@Dave Reid:
hm.. I can confirm that both patches solves my issue (and I can understand why).
After some searching, I came across this issue which is included in 1.6 release:
#1938672: Field help token replacement should run on the original field description, not the already filtered string
In that issue, it is stated that $context['instance']['description'] should be used instead of $element['#description'] , because the later has already been xss filtered earlier, and there are some issues with that.
That's why $element['#description'] is replaced by $context['instance']['description'] as the argument of token_replace.
Patch in issue #2367721: Token prevents display of i18n field submodule translations actually reverts that by using $element['#description'] again.
So if the patch in #2367721 will be committed, the issue in #1938672 will return again.
I'm marking it as review again, but I believe this solution is better than the solution in #2367721: Token prevents display of i18n field submodule translations.
Comment #12
Zekvyrin CreditAttribution: Zekvyrin commentedI'm uploading a new patch, cleaner imo, plus I've replaced filter_xss_admin with field_filter_xss
as it's more strict and it is the one supposed to be used in field descriptions as a filter.
Still, someone needs to review it as logic, not only as functionality (see #11)
Comment #13
AnybodyWHAO!! This bug is really really (small but) heavy! It was very hard to find the reason when field descriptions were not properly translated. Because of this and the functionality break for all i18n sites I'll set up the priority to major. I hope you'll agree.
Furthermore I think we should set #2367721: Token prevents display of i18n field submodule translations a duplicate of this (I'll do this now and hope it's OK) and yes, #12 is the better logic, I think!
It fixes the problems for me and seems logically correct to me, but someone else should have a look.
Last note: I'd suggest to create a new stable release when this was fixed because of the huge impact it has on i18n sites!
Comment #14
jygastaud CreditAttribution: jygastaud commentedPatch in #12 works for me too.
Mark it as RTBC.
I also agree with Anybody suggestion to create a new release which include that patch.
Comment #15
eugene.ilyin CreditAttribution: eugene.ilyin commented#12 works fine for me. Thanks
Comment #16
idebr CreditAttribution: idebr at One Shoe commented#12 saved my Friday, thanks!
Comment #17
weri CreditAttribution: weri at Previon Plus AG commentedWe had the same problem with the translation of field descriptions. Patch #12 resolves the problem.
Comment #18
aryser CreditAttribution: aryser as a volunteer commented#12 worked for me as well Thanks a lot!
Comment #19
neilzusman CreditAttribution: neilzusman commented#12 worked for me too!
Comment #21
Dave ReidCommitted and pushed #12 to 7.x-1.x. Going to mark this as need checking for D8 as well, but doubtful it needs to be fixed there too.
Comment #22
rodrigoaguileraThis functionality is in core now and I checked that It works as expected:
config translation module enabled and I configured field description with text and tokens I can translate perfectly fine without overwrites.
I don't know if it's worth it to open an issue to add a test for this in core. What do you think?
Comment #23
AnybodyWhat about a new stable release containing this fix? This issue is still open for the stable version. Only the .dev version has been fixed. Could you please plan this because of the "major" priority?
Thank you very very much.
Comment #24
gngn CreditAttribution: gngn at Computer Manufaktur GmbH commentedI am using #12 for half a year now, it's working fine.
I agree with Anybody about having a new stable release.
Comment #25
tomrogThanks for patch #12. I am really surprised that this didn't go to official version :O
Comment #26
dernetzjaeger CreditAttribution: dernetzjaeger as a volunteer commentedThanks for #12 . Works fine :)
Comment #27
indigoxela CreditAttribution: indigoxela commentedSame issue here with drupal 7.51, token 7.x-1.6, and i18n 7.x-1.13.
I can confirm that patch #12 fixes the issue.
Token 7.x-1.6 is rather old, it really needs a new stable release.