Meet Us At WordCamp Europe!

Bild 435This weekend Frank and I will be attending and speaking at the first ever WordCamp Europe in Leiden near Amsterdam, Netherlands! We are really thrilled to be there and can't wait to meet all the WordPress Gurus from all over the world and see some really interesting sessions!

Frank and Toscho will have a presentation about our MultilingualPress Plugin, a great solution for WordPress with multilingual functionality. Since the very best comes at the end, they are scheduled to be the last presentation on Sunday at 16:45 "The State of Multilingual WordPress". They will show how easy it is to use a WordPress Multisite and create a multilingual website.

We are really excited to see many of our friends and other WordPress enthusiasts, as we are, at the event. The participant list is a who’s who of WordPress experts. It will surely a great and interesting weekend!

If you’re attending WordCamp Europe make sure you say hello, we love to have a chat or a beer with you! :)

Ooooh, and if someone doesn't know how we look like, here we go:

Alex

Alex

Frank

Frank

WordPress-Christmas-2010-24

Best Practice for Multilanguage WordPress Content? New Plugin!

Since the beginning of WordPress the desire to publish the content in different languages is huge. But the topic can quickly become complex, because not only the rendering of content in the form of text in different languages ​​is an issue, we also have to take care of the meta data for content, for images that can be different depending on the language and the use of the admin interface in the preferred language. Thus, only a part would be covered depending on the requirements (a example on StackExchange) it would quickly become an project and WordPress would be just a "small" framework behind it. There are already many Plugins available, the different approaches - new tables in the system or separation of content for each language in a table entry to post, or other solutions.

All these solutions have their limitations, are inflexible and you go into a dependency that will be hard to get out and with each update of WordPress you have to check if the Plugin is still working or has any bugs with the new version. Therefore, I would suggest a solution that we use in our Inpsyde Team frequently for customers and maintained their strength in the flexibility, in extensibility and in its capacity to use the WordPress standard without changing the core or anything else. You can deactivate the Plugin at any time, you won't lose anything, your website remains the same.

Continue reading …

What’s the difference between __(), _e(), _x(), and _ex()?

If you're a thorough plugin developer you're internationalizing (i18n) all your strings. WordPress includes several functions that allow the programmer to easily make his plugin usable natively worldwide:

  • __()
  • _e()
  • _x()
  • _ex()
  • _n()

In some older plugins you may find the function _c() which is deprecated and replaced by _x() since version 2.9. If you're not familiar with i18n of your plugin you should take a look at the Codex.

All these functions translate a string to the language defined in wp-config.php. So what's the difference between them?

__() and _e() are the simplest functions: they return or echo the translated string. Their usage should be obvious: one string, one translation.
Not so obvious is the function of _x(). Suggest you have two strings in two different contexts in your plugin which are totally the same in your language. Are you sure they are also the same in the remaining 3000+ languages spoken on earth? Even Sebastian Heine is unlikely to know it so you shouldn't be sure neither.
Fortunately the creators of WordPress have a solution in their bag: _x().This function contains an additional parameter:

string _x (string $text, string $context, [string $domain = 'default']) 

By using the parameter $context you can differentiate identical strings in different contexts. Simple, eh? The remaining problem is to define two different string in the .po file. That's not too difficult neither:

msgctxt "test1"
msgid "testing"
msgstr "context1"

msgctxt "test2"
msgid "testing"
msgstr "context2"

The magic token ist msgctxt which you might translate to "message context". The code

echo 'Context: test1 -> ' . _x('testing', 'test1', 'test');
echo '<br>Context: test2 -> ' . _x('testing', 'test2', 'test');

would create the output

Context: test1 -> context1
Context: test2 -> context2

The remaining function _ex is a combination of _e and _x: it echoes a translated string using a context.

If you're using a visual editor for your .pot files you should be aware that not every editor is capable of handling context definitions and might destroy your data.

Last but not least _n() for retrieving the plural or single form based on the amount.

_n( $single, $plural, $number, $domain = 'default' )

If the domain is not set in the $l10n list, then a comparison will be made and either $plural or $single parameters returned. The function returned via the filter ngettext and about this you can filter the returned strings.

Update (10 JUN 2011): The above explanation of _n() seems to have confused some people. Maybe a few examples will clarify the usage of the function.

A simple example of _n() would be:

$domain = 'test';
$comment_count = 1;
echo _n('comment', 'comments', $comment_count, $domain) . '<br/>';
$comment_count = 2;
echo _n('comment', 'comments', $comment_count, $domain);

the corresponding German (de_DE) language file entries are:

msgid "comment"
msgid_plural "comments"
msgstr[0] "Kommentar"
msgstr[1] "Kommentare"

and the output:

Kommentar
Kommentare

which are the correct singular and plural translations.

If you're planning to output the value of the numbers you have to use sprintf(). Here's an example:

$approved = 1;				
echo sprintf( _n( '%s comment approved', '%s comments approved', $approved, 'test' ), $approved);
echo '<br/>';
$approved = 2;				
echo sprintf( _n( '%s comment approved', '%s comments approved', $approved, 'test' ), $approved );

The code might look a bit confusing so let's rewrite it:

$approved = 1;
$text = _n( '%s comment approved', '%s comments approved', $approved, 'test' );
echo sprintf($text, $approved);
echo '<br/>';

$approved = 2;
$text = _n( '%s comment approved', '%s comments approved', $approved, 'test' );
echo sprintf($text, $approved);

First a correctly translated singular or plural string is stored in $text. Then this string is evaluated by sprintf() which replaces the specifier "%s" with the value of $approved.

Using the following language file definitions

msgid "%s comment approved"
msgid_plural "%s comments approved"
msgstr[0] "%s Kommentar genehmigt"
msgstr[1] "%s Kommentare genehmigt"

the output is

1 Kommentar genehmigt
2 Kommentare genehmigt

Of course there's also a combination of _n() and _x() called _nx()

function _nx($single, $plural, $number, $context, $domain = 'default')

Plugin Review: Codestyling Localization

Heiko Rabe, a very talented Plugin-Developer created a plugin, which comes just in time: Codestyling Localisation. Since I am currently developing a premium WordPress theme, which I like to have multilingual, this plugin is an excellent alternative to PoEdit. Compare to PoEdit this Plugin has the decisive advantage that you can translate a theme or plugin directly online, without an installed PoEdit on your computer. Therefore you don't have to constantly upload the language files, as they are directly in the theme / plugin stored. Continue reading …