Add i18n_string/i18n_field integration to markup fields, also taking into account whether the set markup text format is allowed to be translated.
The original post and first suggestions were to pass the markup text through t(), but as per the t() manual page
It is especially important never to call
t($user_text);
, where $user_text is some text that a user entered - doing that can lead to cross-site scripting and other security problems.
Original Post:
Just hook to the t() to allow translation of the markup content.
Here's my change (line #218 of markup.module, function markup_widget_process() )
else if (!empty($element['#markup'])) {
$markup = $element['#markup'];
}
To :
else if (!empty($element['#markup'])) {
$markup = t($element['#markup']);
}
Comments
Comment #1
interjinn commentedExactly what I did... should be added to module. I don't want to give PHP access to content authors just so they can translate markup content fields. This also doesn't translate the PHP code which is good since PHP code can pass it's own stuff through t(). BTW, this is similar to #714748: i18n support which appears to be stuck in a rut... although it doesn't put translation code in the right place. That said the hangup on HTML seems ridiculous. If I want translatable content I'll be careful with what HTML I include.
Comment #2
rvilarI've created a patch to use the workaround in the description for D7
Comment #3
basvredelingThis probably doesn't take into account complex html, but the patch seems to work. I'd rather use a generic field translation however. Using entity_translation for instance.
Comment #4
jurgenhaasI would also very much prefer the field translation behavior because otherwise we always have to go to ui translation and if the source markup changes, there is a new translation required.
Comment #5
basvredelingI'd also like to add that t() should only accept a natural string, no variables. So this patch should always fail testing.
Comment #6
dshields commentedI eventually had to target this particular field in a hook_form_ENTITYFORM-TYPE_entityform_edit_form_alter and wrap the markup in a t() function.
Comment #7
vbouchetI tested it with some strings containing html tags (p, span class="my_class") and it worked well.
Comment #8
mqannehComment #9
barami commentedHm.. I think use hook_i18n_field_info is better than #2 patch.
With i18n integration, field can translate via i18n field ui.
Comment #10
lendudeAs per the t() manual page
it's a big no-no to pass user supplied text through t(). So #2 is a no go for me (and should be for others).
This patch adds i18n_string/i18n_field integration to markup fields, also taking into account whether the set markup text format is allowed to be translated.
Comment #11
martijn houtman commentedPatch #10 works for me! Thanks :)
Comment #12
barami commentedComment #13
barami commented#10 does not work with filters for untranslated markup.
Comment #14
barami commentedComment #15
barami commentedThis patch fix #10 patch for untranslated markup fields.
Comment #16
barami commentedFix mis typing on #15.
Comment #17
lendudeCouple of issues with #16
I agree that using i18n_string_text() is better then what I used, but change to check for the new function you use.
Whole hook from patch in #10 is missing, so now the string can't be translated via the field translation UI.
Manually tested with token_filter as format and #16 fixes the issues with it.
Comment #18
lendudeHad the changes here, so here is patch with the changes from #17 applied.
Comment #19
bogdan.racz commentedRe-rolled the patch to latest release.
Comment #20
bogdan.racz commentedI have removed the langcode from the options array, as it always comes as LANGUAGE_NONE.
Without the langcode mentioned, it will take the current one from i18n function.
Comment #21
lendude@rbmboogie The patch in #20 appears to be an interdiff? It's not a complete patch.
Updated the issue summary to reflect the current state of the issue.
Comment #22
bogdan.racz commented@lendude thanks for the fast reply.
Re-uploaded the combined patch from #19 and #20.
Comment #23
lendudeTested it manually, and looks good to me.
Only thing I can think of would be adding some documentation, but since the module doesn't actually contain any documentation at the moment, that seems like a totally separate issue.
Comment #27
sgurlt commentedPatch #22 works good for me.
Note: This will only work for newly created fields.
Comment #28
basvredeling+1 for #22
Comment #29
joco_sp commented+1 for #22
Comment #30
mtoscano commentedPatch #22 works good for me too, also for existing fields.
Comment #31
t0xicCode commentedI had to add the i18n_string translation to the
hook_field_prepare_viewas well to get it to appear translated on the view page (not just on the edit page).Comment #32
lendudeLots of code duplication in this. Shouldn't we just put all this in an internal function that you pass the instance?
Comment #33
t0xicCode commentedIt'd be a good idea. I'll update the patch.
Comment #34
t0xicCode commentedUpdated. Also updated the help text on the settings form.
Comment #35
lendudeextra bit at the top of the patch. Applies cleanly though.
Manually tested the patch and looks good.
Comment #36
t0xicCode commentedOh, right. I tend to generate my patches using
git format-patch, which formats the patch (which is already basically a commit) into an email message.git amcan use the metadata in there to apply the patch more effectively.Comment #37
basvredeling+1 for patch from #34
Comment #38
aaronbauman#34 RTBC++
Q.
How to use patch #34?
I applied this patch, re-loaded the page in which my markup fields appear, and expected to see them available for translation via translate interface ( admin/config/regional/translate/translate ).
They are not.
How do I enter the translations?
A.
Use the field translation interface, e.g. admin/structure/types/manage/node_type/fields/field_name/translate
Comment #39
dipali.dhole commented#22 works well for me. Thank you.
Comment #40
Anonymous (not verified) commentedI am using patch #34, works ok.
Comment #41
aaronbaumanMore than a year later... still running #34, still working good.
Can we get this patched please?
Comment #42
nocean commentedUsing #34 and working like a charm. In case anyone else starts pulling their hair out after applying the patch -- remember to clear all your caches.
Comment #43
stiml commented#22 works well ! Thank you.
Comment #44
earthangelconsulting commentedi applied the patch from #34 and i am having the same question as was asked in #38. i am in the page admin/structure/types/manage/node_type/fields/field_name/translate for this field and i only see the values for the Title, not the Markup itself. i have cleared caches and it made no difference. any ideas, anyone?
Comment #46
anybodyThank you all very much - I just committed this to the latest 7.x dev version!