3

I've imported a .po file having Spanish translations. The import was successful but some translation strings were skipped because they contain disallowed HTML.

From UI, I found that some translations were not translated. So I tried them adding those via the translate admin interface (Administration » Configuration » Regional and language » Translate interface)

I could see the original text having inline style like following.

enter image description here

But when I tried to add a Spanish (Latin American) Translation and hit 'Save translations' getting the following error.

The submitted string contains disallowed HTML:<span style="color:#0098CF">Hola</span>

I've enabled Translatable all HTML text formats under multilingual settings (Administration » Configuration » Regional and language » Multilingual settings)

enter image description here

It's working when I remove inline style add translation like the following. So I guess it's not supporting inline styles and classes.

<span> Hola </span>

What could be the problem? I found a function in function locale_string_is_safe($string) under includes/locale.inc file. Do I need to do any tweaks with that?

Any suggestions would be much appreciated.

2 Answers 2

1

Yes your guess is correct,locale_string_is_safe "Check that a string is safe to be added or imported as a translation." if you want to ignore your job you should patch it for a while , change it to

function locale_string_is_safe($string) {
  return TRUE:
}

after your job revert it.

5
  • 1
    Awesome! that works!! thanks zhilevan you saved my day:) Sep 29, 2014 at 10:42
  • @KrishnaMohan your welcome my friend :) . we are here to help each others ;)
    – Yuseferi
    Sep 29, 2014 at 11:04
  • 1
    Is there not any other solution since this is hacking core?thanks
    – Dion
    May 16, 2015 at 16:46
  • @sokratis I dont spend more time on it maybe there is but I dont know it
    – Yuseferi
    May 17, 2015 at 5:33
  • @sokratis – Added no-hacking answer.
    – leymannx
    Jan 26, 2016 at 13:51
2

Here's an alternative without hacking the core. You simply could unset the validation for the translation interface form:

/**
 * Implements hook_form_alter().
 */
function MYMODULE_form_alter(&$form, &$form_state, $form_id) {

  // That's the form ID of the translation interface.
  if ($form_id == 'i18n_string_locale_translate_edit_form') {

    // Let's check at least for a user's role first.
    global $user;
    if (in_array('administrator', $user->roles)) {

      // Simply unset the validation. Done.
      unset($form['#validate']);
    }
  }
}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.