Translating WordPress Multisite using .mo files
My Notes on translating WordPress multisite using an .mo file
These notes do not cover how to create a .po file, how to use a .po file, or how to compile a .po file into a .mo file. These notes do, however, cover one way you can use a .mo file.
These notes do not cover how to translate a single-site installation of WordPress. They do, however, cover how to translate a sub-site of a WordPress multisite installation.
The format of these notes is as follows:
1. Details about my development environment.
2. Details about the specific site I'm developing.
3. My observations as I got WordPress to finally respect my .mo files.
Environment:
- Windows 7 32-bit
- Web server: WAMP Server 2.2, which consists of the following 3 items:
- Apache 2.2.22
- MySQL 5.5.24
- PHP 5.4.3 with the php_gettext extension enabled
- WordPress 3.7.1 - with multisite enabled
- My domain name is example.com
- I have 2 sub-sites: example.com/subsite1 and example.com/subsite2
- I am using a WordPress theme named "mytheme" on both sub-sites
- The translated text is compiled into a file named: mytheme-en_US.mo
- The language and locale together have this format: "en_US" or "nl_NL".
- The .po file is a non-compiled text file that has a bunch of strings and their translations.
- The .mo file is a compiled binary file (compiled from the .po file) that WordPress (or is it PHP?) will consume.
- You can generate a .mo file from a .po file using the free program, Poedit, which you can download for free from www.poedit.net.
- Setting the WPLANG constant in the wp-config.php file is not enough to tell WordPress what language and locale you want a given sub-site to use. I don't know what significance that constant has when WordPress is in multisite mode. I can see it being used for the main/blog site... at most; but even then, I'm not sure (I haven't tried translating the main site/blog yet).
- You can specify the locale and language you want a given sub-site to use by going to My Sites > Network Admin > Sites; find the sub-site in the list; click the "Edit" link beneath the name of the sub-site; click the "Settings" tab; search for, or scroll down to, the WPLANG attribute, and enter the language and locale you want that sub-site to use (e.g. "en_US" without the quotes); click "Save Changes" to save it. IMPORTANT: Now, check to see whether it saved. If it didn't save, it may be because you do not have your language file (i.e. your .mo file) in the location WordPress expects yet.
- You can name your .mo file as follows: <theme_name>-<language>_<LOCALE>.mo (e.g. mytheme-en_US.mo)
- You can store your .mo file in the following directory: wp-content/languages/themes/, so the resulting path to the file is: wp-content/languages/themes/mytheme-en_US.mo. You may have to create the "languages" and "themes" directories (I did).
- In order to see whether the translation has taken effect, simply refresh the page in your browser. You don't have to restart Apache or anything like that.
Location of .mo file. |
WPLANG attribute in sub-site settings. |
If you have any questions, you can leave a comment on this blog article. I've never received a comment before, so I don't know how I'll be notified, but I'll check this blog article from time to time and maybe another visitor will beat me to answering your question. You can also leave comments and feedback.
Hi there! If you need to translate your WordPress website, I suggest evaluating https://poeditor.com/ which is a collaborative translation management platform designed to make the localization process a lot easier for both developers and project managers. It understands many formats such as po, pot, xliff, strings, json, resx/resw.
ReplyDelete