tombenner / wp-mvc

An MVC framework for WordPress
http://wpmvc.org
MIT License
624 stars 172 forks source link

Add language to url #248

Closed jafamo closed 5 years ago

jafamo commented 5 years ago

Hi, I created a new plugin on wordpress 5.0 with MVC plugin.

My plugin is working properly in http://localhost/xxxx/pluginName/ On my controller I have this:

     $myLocale = get_locale();
        if(strcmp($myLocale,'en')===0){
                $myLocale = 'en_US';
        }else if(strcmp($myLocale,'es')===0){
                $myLocale = 'es_ES';
        }else{
                $myLocale = 'it_IT';
        }

.....

$this->render_view('testFolder/viewTest');

I would like to know how to do working url with languages.

Example: http://localhost/xxxx/es/pluginName/ http://localhost/xxxx/en/pluginName/ http://localhost/xxxx/it/pluginName/

Regards,

cyberscribe commented 5 years ago

You can accomplish this in the plugin by passing a ?lang= (or similar) parameter on the URL, or what I do is set up a multisite instance with sub-sites corresponding to the languages, and activate the plugin globally on the multisite instance. That way everything within e.g. .../it/ is in Italian, including all site-wide string translations. Good luck!