Basic Bilingual 1.0 Plugin for WordPress: Blog in More Than One Language! [en]

[fr] Le plugin WordPress Basic Bilingual que j'utilise depuis un nombre incalculable d'années pour fournir des résumés "dans l'autre langue" à mes articles a enfin été mis à jour. Grâce à Claude Vedovini, il passe à la version 1.0, que je vous conseille d'essayer tout de suite!

A huge huge thanks to Claude Vedovini who spent the last few days working on my really old plugin (but still used daily!) Basic Bilingual in order to release version 1.0. Download it now!

The plugin has been around since early 2005, and honestly, what it does hasn’t really changed: it allows you to specify a summary of your post in another language and label it as such, as you can see here on Climb to the Stars. If you want more complex handling of languages in WordPress, head over to WPML, the likes of which weren’t around when I first threw a few functions together to try and make my bilingual blogging life easier.

So, what’s new?

  • unlike me, Claude actually knows how to write code, so instead of being some horribly outdated collection of clumsy functions, the plugin’s code is now upto 2013 standards (hadn’t seen an update in 4 years, can you imagine?)
  • it’s now possible to have more than two languages in your blog, with two “different language” excerpts accompanying your main post
  • you can now choose the markup for your excerpts without having to wade through plugin code: there is a lovely settings page for that and other things you can configure
  • the language widget in the page editing screen is a drop-down now, and not an ugly text field where you need to type your language’s code
  • you can also filter excerpts based on your readers’ browser settings
  • …and the plugin has been tested with the latest version of WordPress! (not that it broke too much before…)

So thanks so much Claude, it feels good to have Basic Bilingual off life support and alive again!

If you use Basic Bilingual I’d really love if you could take a few minutes to write a review over on wordpress.org. Thanks! Oh, and if you have a crazy plugin idea that needs bringing to life, ping Claude about it 😉

Plans for Basic Bilingual [en]

[fr] Projets de développement pour le plugin WordPress Basic Bilingual, qui rend ce blog bilingue.

Here are the next improvements I want to make to the WordPress plugin Basic Bilingual. Considering my coding skills, they will happen slowly, so feel free to lend a hand if you think you can.

  1. Move the language definition to the admin screen. There’s already a screen and an option there, so it’s a simple case of copying and modifying code around to create options for language 1 and language 2, and create a simple function to retrieve the values at the beginning of the plugin.
  2. Allow WordPress search to access the other-excerpt field. The Keyword Search in Plugin Table example in Codex is close enough to what I’d like, only it would need to search in the postmeta table instead of a custom plugin table.
  3. Here’s the big one. Append a language code to any WordPress URL (except permalinks) to filter out posts from the other language. Ideally, would display posts in the language and also the other-excerpts of posts in the other language, with different formatting (smaller title font to distinguish them from full posts written in the desired language). Am reading up on wp-rewrite, permalinks for custom archives, WordPress queries and custom queries. I feel I’m onto something, but I also feel just a little bit out of my depth.

Basic Bilingual 0.4 [en]

[fr] Mon plugin bilingue vient enfin d'être mis à jour: version 0.4 à disposition, par les bons soins de Luca!

Another long-overdue update of my Basic Bilingual plugin (which, as you can see by following the link, now has its own page here, in addition to the page in the WordPress plugin repository).

Luca Palli e-mailed me a few months ago saying he had upgraded the admin code to make it compatible with WordPress 2.8. I’m happy to let you know that you can now drag the language and other excerpt fields to more convenient places in your post and page editing screens.

Basic Bilingual with new editing screen, thanks Luca!

Luca also added an options screen, and I have hope that I (or somebody) will at some point manage to write the code to set the languages through the options screen rather than by editing the plugin, as we have to do now (it’s pretty simple editing, though).

So, thanks a lot, Luca.

Thanks too to the “how to use Subversion” page on the WordPress extend site, as it saved my life once again. I update my plugins so infrequently that I completely forget how to use svn in between.

As always, back up your data regularly, and if you bump into any problems, let me know. If you want to contribute code, as you can see, you’re more than welcome!

Two Plugin Updates: Basic Bilingual 0.32 and Language Linker 0.2 [en]

[fr] Je me suis levée à l'aube pour aller faire la nouille sur RSR1 et prendre un p'tit déj improvisé chez une ancienne copine d'uni. Ensuite, j'ai passé la journée les mains dans le PHP, ce qui veut dire que je n'ai beaucoup blogué, mais que j'ai mis à jour deux plugins: Basic Bilingual, qui permet de tenir sans peine un blog "bilingue" comme celui-ci (c'est ce qui me permet de rédiger et d'afficher ce petit extrait en français) et Bunny's Language Linker, très utile pour afficher des liens entre pages correspondantes des différentes traductions d'un site.

After waking up at an ungodly hour this New Year’s Day (for a live radio appearance and impromptu breakfast at a uni friend’s home nearby) I spent the rest of my day elbows deep in PHP code. As a result, I haven’t written the half-dozen of posts that have been sitting in my drafts list over Christmas, but I have updated two plugins — an old one, and a new-born.

Basic Bilingual 0.32

Download | zip | .phps

This release fixes the disappearing excerpts problem (was fixed in 0.31 actually, but I never announced it) and replaces the ugly “language box” floating somewhere near the top of the post admin page by a pretty DBX (let me know what it stands for) box in the sidebar:

Basic Bilingual got a dbx box for the new year!

Bunny’s Language Linker 0.2

Download | zip | .phps

(I always want to call it “Language Links”, which was the initial name I chose — still not sure I was right to change.) Anyway, this version is pretty exciting, as it does something I’ve been thinking of for a while: it puts the link to the other localized versions of the page you’re viewing in the menu bar if you’re using a Sandbox-based theme:

Language Linker link in the menu bar!

Otherwise, it puts it at the end of the page in its own div (you can style it the way you wish). I’m not saying this is the best, final solution, but I think it’s headed in the right direction.

Nasty Problem With Basic Bilingual Plugin [en]

[fr] Un problème avec le plugin Basic Bilingual qui fait disparaître les extraits dans "l'autre langue". Je bosse sur une solution (voir commentaires).

Heck. I just spent the last 15 minutes digging through the Google cache to retrieve “other language excerpts” which had been wiped from a good dozen of my recent posts. Not all of them, mind you — almost all of them. I haven’t yet managed to reproduce the problem, but clearly, the meta fields get reset in some circumstances.

I suspect it might be something that has to do with editing posts. Maybe related to the old disappearing tags problem?

In any case, I’m afraid Basic Bilingual must be misbehaving. Be particularly cautious when editing posts. Let me know if you have the same problem or a path to a fix — I’m working on it now.

Update: if somebody has the French excerpt to my post Advisors, Boards, Companies, Partners, Oh My! in their newsreader or browser cache, could you please send it to me or copy-paste it here as a comment? Thanks a lot.

Update, 17:30: I think I solved the problem (see comments) and corrected the files available on my server, bumping up the version to 0.31. Please download the latest version if you’re using this plugin.

Ridding WordPress Plugins of Template Tags [en]

[fr] Cet article décrit une méthode permettant de se défaire des "template tags" qu'utilisent certains plugins. Plutôt que de copier le fameux template tag à 3 endroits différents dans son thème (comme c'était le cas auparavant pour Basic Bilingual), il est possible de modifier à peu de frais un plugin pour qu'il injecte automatiquement son contenu dans le blog.

If you’re like me and use a bunch of plugins to liven up your WordPress blog, you’ve probably noticed that adding template tags in your favourite (or favourite-of-the-week) theme files can quickly become a royal pain in the neck.

One of the things I wanted to do with Basic Bilingual, and which I did with the last release, was make the plugin inject the text for the “other excerpt” (the French text you can see at the top of this post) automatically into the templates and feeds.

Once I’d figured out how to do that, I realised I could modify other plugins, too. And I’m going to tell you how you can do it, too. This method should work for any plugin which generates a template tag, as long as you want the content generated by the plugin to go immediately after or before the post content. (I’m still working on advanced rules for cases where you want to make modifications elsewhere in the template.)

Christine‘s Inline Tag Thing put me on the track (thanks!), as it does just that. Here’s the trick:

  1. create a function which concatenates (= “adds”) the plugin output to the content
  2. add an action hook to the plugin to apply that function to “the_content”.

Fear not, I’ll explain all. You don’t need to really know much PHP to do this, as long as you’re comfortable wading through a bit of code and copy-pasting stuff and making a few small modifications.

Let’s take an example: the Similar Posts plugin, which I’m now using to point out posts related to the current one (normally, in a box at the top of the post if you’re on the website, and as a list at the end of the post if you’re reading the feed).

Similar Posts provides a template tag, <?php similar_posts(); ?>, which you can paste in your template where you like the related posts to appear. Personally, I want them to appear on the main blog page, on the individual archive pages, and on the monthly, category, and taggy archive pages. This means I need to paste the tag into at least 3-4 different template files. And if I decide that I want the tag at the top of the post rather than the bottom, or I decide to remove it, there I go again. Not optimal.

So, here’s how I made it “better” (for me):

A. First, I looked at the plugin code to figure out where the template tag function was; in this case, quite easy, it’s the function called similar_posts(), logically. Here are the last two lines of this function, which do the actual data output:

print $result;
if (defined('POC_CACHE')) print $cache_time;

I changed them to:

return $result;
if (defined('POC_CACHE')) return $cache_time;

So that they didn’t print directly (ie, output text), but just return the value of the data we want to insert.

Then, I created the following function:

function sp_embed_similar_posts($content) {
    $content = similar_posts() . $content;
    return $content;
}

This function takes one parameter ($content), and sticks the output of similar_posts() in front of it. Now you see why we needed to change the other function so that it didn’t print. We’re just modifying the value of the $content string. This new function returns the modified value for the content (in our case, imagine it as being the content of your post with the code for the similar posts listing stuck in front.

Now all that is left to do is to tell WordPress to actually use that function at some point (plugins are usually a collection of functions, followed by a series of “hooks” which actually execute the functions at certain chosen moments). Here’s the action we’ll use:

add_action('the_content', 'sp_embed_similar_posts');

Try it!

This will also add the list of similar posts to the feed.

So, in summary, here is what we have done:

  • modified the template tag function so that it returns a value instead of printing it (in some plugins, you’ll find a function that already does that!)
  • created a function to stick that value on the beginning or end of a parameter, $content
  • add an action hook on the_content to execute the function.

Happy hacking!

Basic Bilingual 0.3 for Multilingual Blogging [en]

[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 or check out the code.

Some explanations. First, you all know of my long-standing interest in all things multilingual and in multilingual blogging in particular.

Years ago, I switched to Movable Type and then 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, and then actually write a plugin to do it in a cleaner way. 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 (Matt saw the light for tagging ;-), so I do have hope). By the way, I stumbled upon this 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.

Basic Bilingual in Google Reader

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 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). Add this inside the tag: lang="<?php bb_the_language(); ?>". Do so on every theme template which produces posts. With the Sandbox theme, it would look like this:

&lt;div id=&quot;post-" class="" lang=""&gt;

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.