views:

34

answers:

1

I migrated from Dotclear (2.2) to WordPress (3.0) a few days ago and I have solved all my problems except one. I have not found a pluging to handle "french spacing".

WordPress is better than Dotclear, but since Dotclear is a French project, it manages this correctly.

By "french spacing", I mean replacing the space by an insecable space ( ) before the double punctuation (: ; ! and ?).

I tried "WP-typography" but it doesn't handle this specificity of French language.

+2  A: 
function my_super_awesome_french_spacer($content){
  $content = preg_replace( '/\s([:;!?])\s/', ' $1 ', $content );
  return $content;
}

foreach(array('the_content','the_title','comment_text') as $filter)
  add_filter($filter, 'my_super_awesome_french_spacer',9);

Drop that into your theme's functions.php file and it will enforce the French spacing for the double punctuation (as long as you formatted it that way in the visual editor) in post content, titles, and comments. If you want it to do it even if there's no space before or after, replace the RegEx with this:

'/\s?([:;!?])\s?/'

Basically, adding the question marks after the 's' tells it to replace a space w/ a non-breaking space if it's there, and to insert one if there's no space there to begin with.

John P Bloch
Thanks a lot! It looks ok!
Benoit Courtine