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.

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.

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

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']);
    }
  }
}

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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