Closed (fixed)
Project:
Double Field
Version:
7.x-2.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
14 Oct 2014 at 20:50 UTC
Updated:
2 Oct 2015 at 12:44 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
petermallett commentedAnd 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).
Comment #2
petermallett commentedUpdated the patch from #1 with better / more standards compliant docblocks for the helper/wrapper functions.
Comment #3
chi commentedThe patch works for me, but we have got some other strings to translate (prefixes, suffixes, checkbox label). Let's fix it as well.
Comment #4
rodrigoaguileraAdded support for prefix and suffix following the same strategy.
Updated the issue to reflect the extended goal.
Comment #5
rodrigoaguileraUps posted the same twice.
Comment #9
rodrigoaguileraWrong array key
Comment #10
rodrigoaguileraComment #12
chi commentedI just realized that there are more user defined strings to translate:
At this point updating string sources in hook_field_update_instance() looks as more generic solution.
Comment #13
chi commentedComment #15
chi commentedI have added i18n support for all double field settings. It works for me but needs more testing before release. Thanks for the help!
Comment #16
chi commentedComment #17
chi commentedComment #18
colanDoesn'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:
...not:
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.
Comment #19
chi commentedThat 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.
Comment #20
colan@Chi: Not sure what you mean by "pure"?
Comment #21
chi commented@colan it is not useful for our case
Comment #22
maxlife58 commentedI use double field with select option + textfield widgets and the two patch #1 and #9 does note work for me.
Some help?
Comment #23
chi commentedmaxlife58 what are you trying to translate? Have you tried dev version of the module?
Comment #24
maxlife58 commentedHi 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??
Comment #25
chi commentedField labels for any kind of fields can be translated with i18n module.
Comment #26
maxlife58 commentedHi 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!
Comment #27
rodrigoaguileraI 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.
Comment #28
rodrigoaguileraups, forgot the "-" separator between the bundle and the field_name
Comment #29
chi commented@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.
Comment #30
rodrigoaguileraYes, 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?
Comment #31
chi commentedYes, lets make it unique.
Comment #32
rodrigoaguileraHere 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.
Comment #34
rodrigoaguileraLet's get that new hook to do only what we want it to do.
Comment #35
rodrigoaguileraComment #36
rodrigoaguileraI 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.
Comment #38
chi commentedCommited. Thanks.