[fr] Une mise à jour de mon plugin "Basic Bilingual" qui permet de rendre WordPress bilingue. Modification majeure: il n'y a plus besoin de bidouiller son template pour faire apparaître l'extrait du billet dans "l'autre langue". Par contre, c'est toujours nécessaire pour rajouter les attributs lang.
Long overdue, an upgrade of my plugin Basic Bilingual. Grab the [tgz archive](/code/basic-bilingual.tgz) or [check out the code](/code/basic-bilingual.phps).
Some explanations. First, you all know of my [long-standing interest in all things multilingual](/focus/multilingual) and in [multilingual blogging](http://climbtothestars.org/archives/2007/03/25/blogcamp-multilingual-blogging-session/) in particular.
Years ago, I switched to [Movable Type](http://climbtothestars.org/archives/2004/01/03/switch-to-movable-type/) and then to [Wordpress](http://climbtothestars.org/archives/2004/06/23/switch-to-wordpress/) because I was blogging in two languages. Movable Type allowed me to assign more than one category to each post — so I used two huge categories, fr and en, to indicate what language I was blogging in. This soon made the rebuilds a real pain in the neck, and WordPress allowed me first of all to [happily hack it into being multilingual](http://climbtothestars.org/archives/2004/07/11/multilingual-weblog/), and then actually [write a plugin to do it in a cleaner way](http://climbtothestars.org/archives/2005/01/23/basic-bilingual-plugin/). The plugin hasn’t changed much since, and this upgrade isn’t a major one, but it’s a step in the right direction.
Ideally, I’d like people to be able to use the plugin without having to modify their templates at all. I’d also like the plugin to allow filtering out one language if that is what the reader desires. I still hope that [Wordpress will one day “see the light” and let us define language at post-level](http://wordpress.org/extend/ideas/topic.php?id=1007 “Please vote!”) (Matt [saw the light for tagging](http://climbtothestars.org/archives/2007/09/22/wordpress-finally-has-tags/) ;-), so I do have hope). By the way, I stumbled upon this [Ajax Language Switcher for Basic Bilingual](http://www.freshlabs.de/journal/archives/2006/05/ajax-language-switcher-for-basic-bilingual/) earlier today, and it will probably greatly interest those courageous ones of you who tend to have translations of each post or page.
Back to the plugin. It installs normally (unzip everything in the /plugins directory). If you’re using other languages than French and English, you’ll have to manually change the language codes in the plugin file (not very difficult, you don’t have to know PHP to do it; just look for “en” and “fr” and put the language codes for your languages instead).
I’ve fixed an annoying problem with slashes that popped up at some point (somebody else gave me the fix, but I can’t remember who — let me know!).
But most of all, I’ve made the “other language excerpt” appear automatically in the post content. Yes, you hear me: no need to add <php bb_the_other_excerpt(); ?>
in your templates anymore. Yay! Added bonus: it will show up in the feeds, too — for that reason, I’ve added a text separator between the excerpt and the post so that there is a separation between the languages.
Obviously, you’ll want to hide these separators and style your posts a little. Here is roughly what I’m using right now:
.other-excerpt {
font-style: italic;
background: #fff;
padding-left: 1em;
padding-right: 1em;
border: 1px solid #ccc;
}
.other-excerpt:lang(fr) p.oe-first-child:before {
content: “[fr] “;
font-weight: bold;
}
.other-excerpt:lang(en) p.oe-first-child:before {
content: “[en] “;
font-weight: bold;
}
.bb-post-separator {
display: none;
}
div.hentry:lang(fr) .entry-title:after {
content: ” [fr] “;
vertical-align: middle;
font-size: 80%;
color: #bbb;
}
div.hentry:lang(en) .entry-title:after {
content: ” [en] “;
vertical-align: middle;
font-size: 80%;
color: #bbb;
}
Now, notice there is fancy stuff in there which relies on the lang
attribute. If you’re mixing languages on a page, you should [use the lang
attribute](http://www.w3.org/TR/html401/struct/dirlang.html#h-8.1) to indicate which language is where. This means (unfortunately, until I become buddies with PHP’s ob_start()
function) that you need to touch your template. It’s not that hard, though.
Find the outermost <div>
for each post in the template (it [should have the CSS class hentry
, by now](http://microformats.org/wiki/hatom#Entry)). Add this inside the tag: lang="<?php bb_the_language(); ?>"
. Do so on every theme template which produces posts. With [the Sandbox theme](http://www.plaintxt.org/themes/sandbox/), it would look like this:
<div id="post-” class=”” lang=””>
That’s it!
If you’re using this plugin, please leave a link to your blog. I’m also always interested in hearing of other examples of multilingual blogging or multilingualism online.
Similar Posts:
- Basic Bilingual [en] (2009)
- Basic Bilingual Plugin [en] (2005)
- Website Pro Day 3: Results! [en] (2008)
- Basic Bilingual 0.4 [en] (2009)
- Basic Bilingual 1.0 Plugin for WordPress: Blog in More Than One Language! [en] (2013)
- Two Plugin Updates: Basic Bilingual 0.32 and Language Linker 0.2 [en] (2008)
- Basic Bilingual and Bunny's Technorati Tags Plugins Updated for WordPress 2.1 [en] (2007)
- Nasty Problem With Basic Bilingual Plugin [en] (2007)
- Requirements for a Multilingual WordPress Plugin [en] (2006)
- Call to WordPress Plugin Developers [en] (2005)