Tag Archive for 'php'

L10n: localisation of WordPress

Application localisation has caught my interest recently, for many years it was satisfactory to create applications that only understood (or expected) simplified character sets. Even though there were often cases where such an application would fail, where words or names are borrowed from other languages.

The question for me now is “How can I publish in multiple languages?” I have chosen WordPress as my content management engine. Can it succeed internationally?

When you start searching for multi-lingual or bilingual wordpress, you are likely to end up on the WordPress codex pages. You may also be wondering what it means. These pages will show you how to get WordPress specifically in your languages, i.e. German WordPress, French WordPress. They also tell you how you can help and they link to places to go.

The WordPress pages: Translating WordPress and WordPress in Your Language. If your language is not listed in WordPress in Your Language, you can also try the WordPress Language File Repository. I found the WordPress Language File Repository to be the easiest location for retrieving *.po and *.mo files.

*.mo files can be used by WordPress to render your blog in the correct language if a visitor arrives that is not as familiar to your language. They don’t really help you display your blog in a different language, unless you have lots of registered users that use the admin facilities of your blog.

You can create your own *.mo files for plugins and templates, these will be more useful to attract foreign visitors. A useful tool for managing your localisation capabilities is the Codestyling Localization, wordpress plugin.

It is very good at visualising localisation and you can turn it on and off as you please. The process of using the plugin to create *.po files is to painful, unless you have a very small plugin or template.

So how would you create translation *.po files? Go to the WordPress Language File Repository and download the *.po and *.mo files for your version of WordPress and your desired language locales.

I also wanted something for the actual content.
Polyglot2
can be used to work out the users preferential locale and if that is available, display content in that locale. Unfortunately this plugin will only pick up the user locale if it matches a set of prepared locales. The plugin only uses two letter locales, so there are some limitations. You are also forced to write the translations directly into the same post, limiting the number of translations and the size of the possible articles.

A better WordPress plugin for multilingual blogging called Gengo. This tool allows you to manage multiple languages, creating relationships of translation groups. This allows you to produce multiple streams of content from the same blog in multiple languages. If you want to assign translations it is simply a matter of selecting the post that you have a new translation for.

I have created content in the following languages to demonstrate:

  • English
  • French
  • German
  • Hindi
  • Chinese
  • Japanese
  • Arabic

I’m really impressed with the design of this bilingual spanish/english magazine http://www.kprensa.com/. I don’t know what plugins they have used. But they have done a good looking job.

Update (2008-12-17): I’ve dropped multilingual support on this blog. I can’t communicate in multiple languages anyway. It was purely a very time consuming experiment, which I will continue to be interested in.

Code markup

I may have found the code mark up utility I was looking for. It is called code markup and it is relatively simple to use. All you have to do is edit the lang attribute to the source code language and markup=”none” displays content exactly as written, no markup is rendered.

So let’s write some hello world applications:

1. HelloWorld.java

package hello.world;

/**
 * Class will say hello to world.
 * @author James Little
 */
public class HelloWorld {
	private static String welcome = "Hello ";
	public static void main(String [] args) {
		if(args.length > 0)
			System.out.println(welcome + args[0]);
		else
			System.out.println(welcome + "World");
	}
}

2. hello_world.php

<?php
/**
 * hello_world.php
 * Author: James
 */
class HelloWorld
{
	// Resolve the class type
	public $class = "HelloWorld";

	public function __construct($argv)
	{
		echo "{$i} hello world\n";
	}
}

new HelloWorld($argv[1]);
?>