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.

Comments

kfritsche’s picture

Status: Active » Needs review
StatusFileSize
new859 bytes

Two 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:

$element['#description'] = filter_xss_admin(token_replace($element['#description']));

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.

m_angel’s picture

StatusFileSize
new3.31 KB
new879 bytes

Thanks @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!

m_angel’s picture

Status: Needs review » Needs work

The last submitted patch, 2: translation_of_field-2474403-2.patch, failed testing.

penyaskito’s picture

+++ b/token.module
@@ -274,7 +274,14 @@ function token_form_block_admin_configure_alter(&$form, $form_state) {
+    if (module_enable(array('i18n_field'))) {
+      $instance = i18n_string_object_translate('field_instance', $context['instance']);
+    }

Do we really want this or module_exists instead?

kfritsche’s picture

StatusFileSize
new857 bytes

Fuck, yes module_exists.... Thx @pennyaskito

New patch attached.

penyaskito’s picture

Status: Needs work » Needs review

Back to Needs review.

wanjee’s picture

Patch #6 worked like a charm for me !

zekvyrin’s picture

Status: Needs review » Reviewed & tested by the community

Also works for me and i think it's ok.. shall we commit it?

dave reid’s picture

Would #2367721: Token prevents display of i18n field submodule translations also work to solve this in a more cleaner way?

zekvyrin’s picture

Status: Reviewed & tested by the community » Needs review

@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.

zekvyrin’s picture

I'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)

anybody’s picture

Priority: Normal » Major

WHAO!! 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!

jygastaud’s picture

Status: Needs review » Reviewed & tested by the community

Patch 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.

eugene.ilyin’s picture

#12 works fine for me. Thanks

idebr’s picture

#12 saved my Friday, thanks!

weri’s picture

We had the same problem with the translation of field descriptions. Patch #12 resolves the problem.

aryser’s picture

#12 worked for me as well Thanks a lot!

neilzusman’s picture

#12 worked for me too!

  • Dave Reid committed 0a620c8 on 7.x-1.x authored by Zekvyrin
    Issue #2474403 by kfritsche, mariamania, Zekvyrin, B-Prod: Fixed token...
dave reid’s picture

Version: 7.x-1.x-dev » 8.x-1.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)

Committed 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.

rodrigoaguilera’s picture

Version: 8.x-1.x-dev » 7.x-1.x-dev
Status: Patch (to be ported) » Closed (fixed)

This 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?

anybody’s picture

What 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.

gngn’s picture

I am using #12 for half a year now, it's working fine.
I agree with Anybody about having a new stable release.

tomrog’s picture

Thanks for patch #12. I am really surprised that this didn't go to official version :O

dernetzjaeger’s picture

Thanks for #12 . Works fine :)

indigoxela’s picture

Same 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.