Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question

2 Answers 2

up vote 2 down vote accepted

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.

share|improve this answer

Thats correct.. we don't have control over wp-config file. But the user who wants to use the plugin in different language will be setting that up on wp-config file.

share|improve this answer
    
so that's really how its supposed to be? I really thought its possible from the plugin. Looks like I spent a lot of time solving the wrong problem –  soul Feb 13 '13 at 9:32

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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