l10n_server avec espace insécable

Suite à cette discussion sur le groupe Drupal France, je viens de modifier le module l10n_server afin de mieux gérer les espaces insécables.
Attention c'est du quick & dirty !

export.inc ligne 482

$str = str_replace(" ", chr(0xc2) . chr(0xa0), $str);

translate.inc à partir de la ligne 307

// A toolbox which displays action icons on each string editor fieldset.
$value_str = '<div class="toolbox">'. ($string->has_suggestion ? theme('l10n_community_button', 'has-suggestion', 'l10n-has-suggestion', 'title="'. t('Has suggestions.') .'"') : theme('l10n_community_button', 'has-no-suggestion', 'l10n-has-no-suggestion', 'title="'. t('Has no suggestions.') .'"') ) ;
$value_str .= theme('l10n_community_button', 'space', 'copy', 'onclick="return l10nCommunity.insertSpace('.$string->sid.');" title="'. t('Insert unbreakable space.') .'"') ;
$value_str .= '</div><div class="messagebox"></div>';
$form[$string->sid]['toolbox'] = array(
  '#type' => 'markup',
  '#value' => $value_str
);

l10n_community.js

Ajout de la méthode insertSpace()

l10nCommunity.insertSpace = function(sid){
  $("#l10n-community-translation-" + sid).replaceSelection("&nbsp;");
}

Ajout du plugin jQuery fieldSelection - v0.1.0 (à l'arrache)
/*
 * jQuery plugin: fieldSelection - v0.1.0 - last change: 2006-12-16
 * (c) 2006 Alex Brem <alex@0xab.cd> - <a href="http://blog.0xab.cd<br />
" title="http://blog.0xab.cd<br />
">http://blog.0xab.cd<br />
</a> */
(function() {
  var fieldSelection = {
    getSelection: function() {
      var e = this.jquery ? this[0] : this;
        turn (
        /* mozilla / dom 3.0 */
        ('selectionStart' in e && function() {
          var l = e.selectionEnd - e.selectionStart;
          return { start: e.selectionStart, end: e.selectionEnd, length: l, text: e.value.substr(e.selectionStart, l) };
        }) ||
        /* exploder */
        (document.selection && function() {
          e.focus();
          var r = document.selection.createRange();
          if (r == null) {
          	return { start: 0, end: e.value.length, length: 0 }
          }
          var re = e.createTextRange();
          var rc = re.duplicate();
          re.moveToBookmark(r.getBookmark());
          rc.setEndPoint('EndToStart', re);
          return { start: rc.text.length, end: rc.text.length + r.text.length, length: r.text.length, text: r.text };
        }) ||
        /* browser not supported */
        function() {
          return { start: 0, end: e.value.length, length: 0 };
        }
      )();
    },
    replaceSelection: function() {
      var e = this.jquery ? this[0] : this;
      var text = arguments[0] || '';
      return (
        /* mozilla / dom 3.0 */
        ('selectionStart' in e && function() {
          e.value = e.value.substr(0, e.selectionStart) + text + e.value.substr(e.selectionEnd, e.value.length);
          return this;
        }) ||
        /* exploder */
        (document.selection && function() {
          e.focus();
          document.selection.createRange().text = text;
          return this;
        }) ||
        /* browser not supported */
        function() {
          e.value += text;
          return this;
        }
      )();
    }
  };
  jQuery.each(fieldSelection, function(i) { jQuery.fn[i] = this; });
})();

AttachmentSize
l10n_server-5.x-1.0-alpha3-espace-insecable.tar_.gz364.52 Ko

Commentaires

Excellent !

vgodard (non vérifié) - Dimanche, 4 mai, 2008 - 10:31

Poster un nouveau commentaire

  • Les adresses de pages web et de messagerie électronique sont transformées en liens automatiquement.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img>
  • Les lignes et les paragraphes vont à la ligne automatiquement.

Plus d'informations sur les options de formatage