I'm trying to create a plugin that will be able to translate language used in wordpress. Here's my current code:

add_action('plugins_loaded', function(){
    load_plugin_textdomain('ecom', false, dirname(plugin_basename(__FILE__)) . '/lang'); 

The problem is most of the tutorials that I find in the internet relies on updating the wp-config.php file to load the specific language file like this:

define('WPLANG', 'spanish');

But as a plugin developer we do not have control on the wp-config.php Any ideas?

The only solution that I can think of is to read the wp-config.php file and then modify its contents but it really sounds like a bad practice.

1 Answer 1


This questions was already asked half a year ago:

"Switch language by the click of a button"

The result of it can now be found as a plugin maintained by @StephenHarris and me.

WCM User Language Switcher

It also got a place in the official repo. The development version can be found in our wecodemore GitHub account.

What the plugin does:

  • It adds a user setting for the language, so each user can chose his own.
  • As this is user meta, it can be used elsewhere (plugins) as well
  • The toolbar drop down only features installed/uploaded languages
  • Uses the full ISO 639-2 palette to find languages
  • Even translates the language into their native equivalent when the language was switched

It's extremely easy to use. Just install, upload your languages and go.

Here's how the plugin looks in action.

enter image description here

As there was no complete list of ISO 639-2 language codes that features the native as well as the English language string, we pulled that generated list out of our project and offer it open sourced on GitHub as separate repository.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.