Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Different languages WordPress

  • SOLVED

Hello I would like to add different languages to my wordpress site.

The base language is English, the site is built and working well and is installed on a .co.uk domain.

I also have the domains with .fr and .es endings.

I am capable of doing the translations myself for the content and menus of the site.

Ideally when someone visits mydomain.co.uk they will get English language, when they visit mydomain.fr they will get French language and mydomain.es they will get Spanish language throughout the site. Posts, Pages and Menus etc.

Also with the ability to change language via some links in the header e.g: 'En | Fr |Sp' or flags.


Can someone tell me whats the best way to do this? Is there a plugin out there that anyone has used before?


I ideally don't want to have to create mirror sites for each language, so it would be nice to be able to create a new post in English and to be able to add a translated version in French and Spanish on the same post via a custom field or something.


Thank you

Answers (7)

2011-11-25

S├ębastien | French WordpressDesigner answers:

http://wpml.org/

but i think that a multisite installation is a good solution

2011-11-25

Ryan Riatno answers:

You can use WPML http://wpml.org/ . But I don't know if this can use another domain for differnt language. You can use subdomain or subdirectory for example fr.mydomain.com or mydomain.com/fr.

2011-11-25

Francisco Javier Carazo Gil answers:

Hi Ross,

The [[LINK href="http://2011.sevilla.wordcamp.org/session/sitios-multilenguaje-la-asignatura-pendiente-de-wordpress/"]]second speech in WordCamp Seville 2011[[/LINK]] was about your problem.

The speaker was Rafael Poveda from Mecus (the best WordPress developer bussiness in Spain and collaborators of Automattic) and the final option was the next one.

The solution is to create a network with different blogs. All plugins have a problem and at the end, the best one to create, administrate and write is this option.

You can create a network reusing themes and plugins, and then write the content separately.

You can contact with [[LINK href="http://mecus.es/"]]Mecus[[/LINK]].

2011-11-25

Gabriel Reguly answers:

Hi Ross,

Why not try qTranslate?

Regards,
Gabriel


Gabriel Reguly comments:

Download qTranslate from [[LINK href="http://www.qianqin.de/qtranslate/"]]http://www.qianqin.de/qtranslate/[[/LINK]]


Gabriel Reguly comments:

Hi,

John Cotton solution seems to be a good one. Just add some plugin to do the poedit task inside WordPress and it will be better.

Unfortunately I can't find that plugin right now, but I know that there is one.

Regards,
Gabriel


Gabriel Reguly comments:

Francisco also has an interesting option.

The downside is you will have to set up a multisite install, but I can help you with that.

Be warned that you will need replicate all content and navigation and plugins, but adding content is the easiest one and the most common task - so that should not scare you.

Regards,
Gabriel

2011-11-25

John Cotton answers:

I've done this on several sites. A good example is here: [[LINK href="http://www.begobi.com"]]www.begobi.com[[/LINK]].

By default, the site is in English, but it will detect browser language preference and display in French if requested. The visitor can also switch language using the flags at the top of the page.

It's not a plugin, just some language detection code in functions.php:


// must be called before load_theme_textdomain()
function begobi_localised($locale) {
if ( isset($_GET['l']) ) {
$locale = $_GET['l'];

} else if ( isset( $_COOKIE["begobi_locale"] ) ) {
$locale = $_COOKIE["begobi_locale"];

} else {
if( strlen($_SERVER['HTTP_ACCEPT_LANGUAGE']) >= 2 ) {
$header = substr( $_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2 );
$locale = strtolower($header) . '_' . strtoupper($header);
}
}

setlocale(LC_ALL, $locale );

return $locale;
}
add_filter( 'locale', 'begobi_localised' );


Then I have this call in my ini function:

function begobi_init() {
// code removed....

load_theme_textdomain( 'begobi.com', TEMPLATEPATH . '/languages' );
}
add_action('init', 'begobi_init');


Finally, all text displayed is wrapped in [[LINK href="http://codex.wordpress.org/Translating_WordPress"]]translation functions[[/LINK]], e.g.

$prefix = __('I love this Gobicard! - ', 'begobi.com');

Once the code is ready, just run it through POEdit, create a language file for each language you want - job done!


John Cotton comments:

The points made about page content are good ones - and I didn't explain how that was done.

Essentially, all pages are duplicated - one for each language. That means, of course, that the permalinks change. No problem as any hard codeed/menu permalinks are inside translation tags (so the POEdit file contains the correct link effectively), and anything inside the page can be set to whatever you want anyway.

Have a look at the menu in the two languages and see how the links change - that's just done with a dynamic nav menu....

2011-11-25

Julio Potier answers:

Hello

Just ti say that i'm Web Security Consultant and i read this code from John :

// must be called before load_theme_textdomain()
function begobi_localised($locale) {
if ( isset($_GET['l']) ) {
$locale = $_GET['l'];

} else if ( isset( $_COOKIE["begobi_locale"] ) ) {
$locale = $_COOKIE["begobi_locale"];

} else {
if( strlen($_SERVER['HTTP_ACCEPT_LANGUAGE']) >= 2 ) {
$header = substr( $_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2 );
$locale = strtolower($header) . '_' . strtoupper($header);
}
}

setlocale(LC_ALL, $locale );

return $locale;
}
add_filter( 'locale', 'begobi_localised' );

Sorry but this is not secure.
$locale from $_GET is dangerous, look at this code iused in twentyten template for example :
$locale = get_locale();
$locale_file = get_template_directory() . "/languages/$locale.php";
if ( is_readable( $locale_file ) )
require_once( $locale_file );

You filter is used in "get_locale", so a LFI vulnerability is here.

FYI ;)

2011-11-26

senlin answers:

Your solution is definitely WPML. Unlike other people suggest, WPML does <strong>not</strong> work on multisite, so that is not an option.

I have been working with WPML almost since the beginning and know many ins and outs, more information at [[LINK href="http://wpml.org/documentation/support/wpml-contractors/"]]http://wpml.org/documentation/support/wpml-contractors/[[/LINK]]