Follow-up to #1450618: i18 support

Hello,
Since the above referenced issue is closed & very old, I'm just opening a new one.
Also this specific issue is different from the other i18n issue discussing sub-field string translation; I don't know how to address that right now.

I needed to get the select list sub-field option strings into the i18n_string translation interface though, so I have a patch to get that working forthcoming..

Comments

petermallett’s picture

Assigned: petermallett » Unassigned
Status: Active » Needs review
StatusFileSize
new3.02 KB
new77.47 KB

And here's the patch.

This is using i18n_strings to translate the available options. I think it would probably be preferable to use the field translation options like core select fields, but I couldn't figure that out for this & thought maybe this would be useful to someone else.

For this to work, you first have to save the double field with the select options, that runs them through i18n_strings_update. Then they will appear in the Translate interface under the 'Double field' group. (screenshot example attached).

petermallett’s picture

Updated the patch from #1 with better / more standards compliant docblocks for the helper/wrapper functions.

chi’s picture

Status: Needs review » Needs work

The patch works for me, but we have got some other strings to translate (prefixes, suffixes, checkbox label). Let's fix it as well.

rodrigoaguilera’s picture

Title: i18n strings support for select list sub-field » i18n strings support for select list sub-field, prefix and suffix
Status: Needs work » Needs review
StatusFileSize
new3.49 KB
new3.49 KB

Added support for prefix and suffix following the same strategy.

Updated the issue to reflect the extended goal.

rodrigoaguilera’s picture

StatusFileSize
new6.85 KB

Ups posted the same twice.

The last submitted patch, 4: double_field-i18n-2356639-4.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 5: double_field-i18n-2356639-5.patch, failed testing.

rodrigoaguilera’s picture

StatusFileSize
new6.83 KB

Wrong array key

rodrigoaguilera’s picture

Status: Needs work » Needs review

  • Chi committed 7d2252b on 7.x-2.x authored by petermallett
    Issue #2356639: i18n strings support for select list sub-field.
    
  • Chi committed 9e92a14 on 7.x-2.x authored by rodrigoaguilera
    Issue #2356639: i18n strings support for prefixes and suffixes.
    
chi’s picture

I just realized that there are more user defined strings to translate:

  • Widget: checkbox label
  • Widget: placeholder for textfield and textarea
  • Formatter: prefix and suffix
  • Formatter: table columns labels

At this point updating string sources in hook_field_update_instance() looks as more generic solution.

chi’s picture

Status: Needs review » Needs work

  • Chi committed c086ace on 7.x-2.x
    Issue #2356639: i18n strings support.
    
chi’s picture

I have added i18n support for all double field settings. It works for me but needs more testing before release. Thanks for the help!

chi’s picture

Title: i18n strings support for select list sub-field, prefix and suffix » i18n strings support
Status: Needs work » Fixed
colan’s picture

Status: Fixed » Needs work

Doesn't work for me, but I'm not even sure it's the right approach. This was mentioned in #1.

Field properties, such as prefixes and suffixes in this case, are user-entered data. The string translation interface, though, is for strings within code. As far as I know, field properties should be translated via the Field Translation module (i18n_field). There is some API info, but it's lacking a good example implementation, and I couldn't find one anywhere else.

So properties should be translatable via:

  • Administration » Structure » Content types » (content type) » Manage fields » (field) » Translate » (some language) translate.

...not:

  • Administration » Configuration » Regional and language » Translate interface » Translate (admin/config/regional/translate/translate)

So right now I see Label, Description, and Default Value, but no Prefix, Suffix, etc. which are specific to this module.

In spite of that, for the purposes of testing the above commits, my prefix does show up in the interface translation section, but when I add a translation to it, it doesn't show up. The prefix is always that of the original language. What's strange, possibly due to my configuration, is that the prefix text is crossed out for the target language (as though it's already been translated). Then , when I really do add a translation, it gets uncrossed. So it looks like it still needs to be translated. Not sure why this is backwards.

chi’s picture

As far as I know, field properties should be translated via the Field Translation module (i18n_field). There is some API info.

That API is very pure. Check out the documentation of hook_i18n_field_info(). As the issue subject suggests, we are using i18n_string module not i18n_field module. So the field properties should be searched on admin/config/regional/translate/translate page.

colan’s picture

@Chi: Not sure what you mean by "pure"?

chi’s picture

@colan it is not useful for our case

maxlife58’s picture

I use double field with select option + textfield widgets and the two patch #1 and #9 does note work for me.

Some help?

chi’s picture

maxlife58 what are you trying to translate? Have you tried dev version of the module?

maxlife58’s picture

Hi Chi, i'm tring to translate the double field label.
I tried the new dev version today but does not work.

It's possible to solve??

chi’s picture

Field labels for any kind of fields can be translated with i18n module.

maxlife58’s picture

Hi Chi, thanks for your fast reply, I translate the field label by two way:

1) using the translate tab on edit field page
2) using the string tranlsation interface

but in any case the translated labels are not displayed!

Obviously all the other labels who do not use double field are translated properly!

rodrigoaguilera’s picture

Status: Needs work » Needs review
StatusFileSize
new2.16 KB

I just noticed something that can be improved.

We use
i18n_string_update('double_field:' . $instance['id'] . ':' . $i18n_key, $value);

But using numeric id is a bad as they might change as the site gets rebuild by features and other circumstances.
Let's use bundle + field_name like the i18n_module does.

Attached a patch with my suggested change.

Related with the discussion I think is good that we use i18n_string instead of the i18n_field module. for this translations.

rodrigoaguilera’s picture

StatusFileSize
new2.18 KB

ups, forgot the "-" separator between the bundle and the field_name

chi’s picture

Status: Needs review » Needs work

@rodrigoaguilera, it appears to me that conjunction of bundle and field name does not guarantee uniqueness of the field. We should take into account entity type as well. See field_name_bundle key in field_schema.

rodrigoaguilera’s picture

Yes, I know is not unique. I don't know why i18n_field does it that way. I guess not to make the string super long.

So let's make it [entity type]-[bundle]-[field_name]. the info is already in the instance. Do you agree?

chi’s picture

Yes, lets make it unique.

rodrigoaguilera’s picture

Status: Needs work » Needs review
StatusFileSize
new2.94 KB
new3.08 KB

Here is the patch.

I consolidated the generation of the prefix based on the instance in one function and added hook_create_instance because I'm developing install profiles with features and the strings are not created if you don't implement that hook.

Status: Needs review » Needs work

The last submitted patch, 32: double_field-i18n-2356639-32.patch, failed testing.

rodrigoaguilera’s picture

StatusFileSize
new2.97 KB
new511 bytes

Let's get that new hook to do only what we want it to do.

rodrigoaguilera’s picture

Status: Needs work » Needs review
rodrigoaguilera’s picture

StatusFileSize
new4.01 KB
new1.25 KB

I had to add one more check to avoid warnings:

with features when you create an instance of the field you have all the info available like widgets and displays.
If you create the instance using the interface it doesn't have all the information double_field expects for generating translations.

  • Chi committed 0749a99 on 7.x-2.x authored by rodrigoaguilera
    Issue #2356639 by rodrigoaguilera, petermallett: i18n strings support
    
chi’s picture

Status: Needs review » Fixed

Commited. Thanks.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.