Installing WordPress For Multiple Language Blogs
Register domains for your foreign language blogs
You should run each blog in it’s own domain, or sub-domain. Theoretically, different language blogs can go to the same domain in different directories. The problem with this is that you lose flexibility, from the start. You’re never going to be able to separate these blogs to different machines without breaking all incoming links and losing your page rank.
For a very low cost, you can just register a sub-domain for your existing blog. For example, if your domain is:
www.all-about-cars.com
You can register de.all-about-cars.com for about a dollar per month.
Point all domains to the same blog directory
Once registered, go to your control panel and have the new domains point to the exact same directory, where your WordPress blog is installed. After doing this and before the next set of changes, all domains will just serve the same contents. Go ahead check and see that this is what’s happening.
A word of caution: Google hates duplicate contents on multiple domains. They think that you’re trying to trick them. Don’t leave all domains pointing to the same contents for too long. If you don’t have time, right now, to make the rest of the changes, better turn off the other domains.
Update (April 23 2009)
The new WPML WordPress plugin can automatically do the rest of what’s described here.
It will allow WordPress to run in multiple languages and serve contents from different domains (per language). When using WPML, you don’t need to edit the wp-config.php file or do anything else to allow multilingual contents.
Change the wp-config.php file to server different contents per domain
When WordPress gets a request, it loads up your wp-config.php file. This tells it where your database is, your database user and the table prefix. The rest of the blog settings are stored in the database itself.
Normally, for a single blog install, this config file will include a list of constants. What we’re going to do is change it so that a different configuration file is loaded, according to the domain of the blog.
Before we make our changes, the configuration would look like this (I removed the comments to make it shorter):
<?php
define('DB_NAME', 'putyourdbnamehere');
define('DB_USER', 'usernamehere');
define('DB_PASSWORD', 'yourpasswordhere');
define('DB_HOST', 'localhost');
define('DB_CHARSET', 'utf8');
define('DB_COLLATE', '');
define('AUTH_KEY', 'put your unique phrase here');
define('SECURE_AUTH_KEY', 'put your unique phrase here');
define('LOGGED_IN_KEY', 'put your unique phrase here');
$table_prefix = 'wp_';
define ('WPLANG', '');
if ( !defined('ABSPATH') )
define('ABSPATH', dirname(__FILE__) . '/');
require_once(ABSPATH . 'wp-settings.php');
?>
The first few lines set the database connection. The last lines set up constants that will later be used by other PHP files. We’re going to take the database setting lines and put them in a different – per domain file. Copy DB_NAME to WPLANG and save in a different file. In our example, we should call it:
config-de.all-about-cars.com.php
The contents of this file would be:
<?php
define('DB_NAME', 'putyourdbnamehere');
define('DB_USER', 'usernamehere');
define('DB_PASSWORD', 'yourpasswordhere');
define('DB_HOST', 'localhost');
define('DB_CHARSET', 'utf8');
define('DB_COLLATE', '');
define('AUTH_KEY', 'put your unique phrase here');
define('SECURE_AUTH_KEY', 'put your unique phrase here');
define('LOGGED_IN_KEY', 'put your unique phrase here');
$table_prefix = 'wp_';
define ('WPLANG', '');
Then, we edit wp-config.php so that it checks which domain is used to access the blog and load the respective database configuration. This is what it looks like after our edits:
<?php
$debian_server = preg_replace('/:.*/', "", $_SERVER['HTTP_HOST']);
$debian_file = dirname(__FILE__).'/config-'.strtolower($debian_server).'.php';
if (!file_exists($debian_file)) {
header("HTTP/1.0 404 Not Found");
echo "404 Not found";
}
require_once($debian_file);
define('ABSPATH', dirname(__FILE__).'/');
require_once(ABSPATH.'wp-settings.php');
?>
You should notice the name of the configuration file that’s going to be loaded, per domain. In this example, it would be:
config-DOMAIN.php
Per language database settings
Last thing we need to figure out is how we’re going to store the different language in the database. You’ve got full flexibility here, starting with a completely different database (even on a different machine) to using the same database, just with different table prefix.
For our blogs, we chose to use the same database and user and use different table prefixes. This way, we just have one database to back-up for all blogs. To do this, all values remain the same for all blog settings, except for the database prefix line. For example, for our German blog, we set:
$table_prefix = 'wp_de';
After doing these changes (including adding the configuration files for the foreign language blogs and changing the database settings, per language), you can go and view them in a browser. Each foreign language blog should now have its own contents.
Install language support
You’ll be able to post in different languages, but the blog is not yet localized. The post dates, navigation and controls still appear in your original language.
To change this, go to wordpress.org and download the localization files. For example, to grab the German language files, go to de.wordpress.org. On the front page you’ll see .mo files. Create a directory called languages wp-contents and copy these files there. Install all localization files you need.
Last, change the language selector in your configuration file to match the new localization files you’ve installed. In our German blog it’s set to:
define ('WPLANG', 'de_DE');
Localize your theme
Your blog’s theme probably has some texts in it too. In order to use the same theme without any modifications for all languages, you should wrap all texts inside the gettext() function call. This means, you’ll later have the .mo and .po files where WordPress can fetch translation for the texts in the theme.
Gettext() is a part of the PHP which runs WordPress. The nice thing about it is that any texts that doesn’t have translation will just serve the original one. So, if you edited the theme and added a few words or sentences, but didn’t translate yet - everything will keep working just fine.
The process of localizing a WordPress theme is:
- Wrap all texts in the theme in GetText calls.
- Create a PO file that includes the texts to translate (you can use our free PHP to .po converter).
- Send this file to translators. You can hire a professional translator from ICanLocalize for that.
- Place the .mo files in the plugin directory and tell WordPress to load it.
Have a look at this step by step tutorial for localizing WordPress themes and plugins for full how-to details.
That’s it. Happy multilingual blogging!




