Paulund
2012-11-19 #wordpress

How To Change The Language Of Your Wordpress Site

When you install Wordpress the default language is set to be US English. But this doesn't mean it has to be this language, you can change the language used on your Wordpress site to anything you want. Wordpress developers already have the ability to translate themes and plugins using translation files and translation functions. To find translation files for your language Wordpress has built a page on where you can download Wordpress in your language. Wordpress In Your Language

Translation Files

To get Wordpress to translation all of the text it uses the GNU gettext system, which wraps all the text on the page in a lookup function call. This function will use the language translation file to lookup non-english words and display them in the required language. The files needed for gettext to translate the text are: - POT (Portable Object Template) Translation Files

  • PO (Portable Object) Translation Files
  • MO (Machine Object) Translation Files

POT Translation Files

POT Files are the main files that will be used to process the translation files when you use the __() function and the _e() function. POT Files form the basics of all the translation taken place on your Wordpress site.

PO Translation Files

Any translation that takes place will be stored in the PO file, with the english language and translated words. This is so they are cached for future translations.

MO Translation Files

The MO file will take the PO file and optimize it into a binary file (MO file). Compiling the translations into code makes it quicker to in retrieving translations in the future.

Translation Text In A Theme

There are two functions that Wordpress uses to translate words the __() function and the _e() function. The __() function is that takes an argument as text and will return the translated version.

__('Text To Translate');

Wordpress will attempt to translate this text and if it can it will return the text in the required language if it can't translate then it will just return Text To Translate. The _e() function is exactly the same as above but instead of just returning the text it will echo it to the screen. This is the function you should use inside your theme so Wordpress can echo the translated text on the screen.

_e('Text To Translate');

Installing The Language Manually

If you haven't installed Wordpress with your language files then you will need to setup Wordpress manually to be used in your language. To start with you need to download the .mo translation file from the link below. Wordpress In Your Language The naming structure of the file will be the country code_language code, for example the US English file is called us_en.mo. If you can't find the correct translation files for your language you could try using this plugin to install the language files for you. WP Native Dashboard Once you have your language files you need to add it to the wp-content folder. Create a new folder inside wp-content called /languages and upload your language files into here. The language in here are the only languages you can translation Wordpress into. There is also a Wordpress SVN repository with all the language files which you can search through here. Wordpress Language Repository

Change Language On Single Site

To change the default language of Wordpress open up your wp-config.php file and add the following line.


define ('WPLANG', '');

Change the value of this to the name of the language file, so to change the language to GB English you will use this code.


define ('WPLANG', 'en_GB');

That's all you have to do to change the language, upload these changes to your Wordpress site and Wordpress will translate all the text on your site.

Change Language On Multi Site

For a multi network blog you can set the language of each of the site individually. All the language settings can be setup in the network admin screen.