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.
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
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.
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.
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.
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.
Fastest WordPress Hosting With WPEngine
Stunning speed, powerful security, and best-in-class customer service. At WP Engine.
Join the weekly newsletter
Sign up for our newsletter. You'll be updated on new tutorials as they come available.
Subscribe today and get a 50% discount code to Paulund