I have a File field with the title attribute enabled and I'm trying to figure out how to make the title attribute field translatable using entity translations without affecting the actual file field itself. I'd prefer to allow users to upload one file with a title attribute that can be translated.
1 Answer
What I ended up doing was I used hook_i18n_string_info
to define a new "Captions" text group, hook_field_widget_form_alter
to attach a new process function to the desired upload widgets, and my callback for hook_field_widget_form_alter
cloned the title field (into title_fr for me), then also checked to see if #default_value was a string and used i18n_string_translate
to update title_fr's default_value.
What I did and wouldn't recommend doing was I put the translation handling in the submit function for my form. In there I constructed my translation "name" using caption:$field_key::$nid::$field_delta
and then calling i18n_string_translation_update($name, $french_caption, 'fr', $english_caption)
.
-
Nice solution, I did the same and just exchanged the submit function for hook_entity_presave().– user35398Commented Aug 22, 2014 at 17:49