I’ve scoured the internet in and out and I still do not understand how the translation functions work in combination with the .MO files. I understand that .MO files hold the translations to other languages, and that __() and _e() functions server as translators.
I have translated text in my plugin using __('text', 'plugin-slug')
format.
I have created a .MO file for German translation but I’m not sure how it gets activated.
Do I have to develop an option in settings page where you can select the language of your choice.. if so, how do you pro grammatically force the plugin to use a certain language?
Or does wordpress automatically selects a plugin language based on the WordPress installation?
I am using the following code to load textdomain.
load_plugin_textdomain( 'plugin-slug', false, dirname( plugin_basename( __FILE__ ) ) . '/lang/' );
It loads it correctly, as far as I’m concerned. The MO file within the /lang/
folder is named de_DE.mo
.
How do I go about it next? There’s really not much information on this topic out there.. any advice?
That’s very much exactly what it does. You need to define the language in your config file (by defining
WPLANG
). WP picks it up from there and localizes strings the best it can according to your chosen locale.