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 want to install WP in 3 languages: en, ro, ru

mysite.com/en
mysite.com/ro
mysite.com/ru

I was not sure, but installed WP in the root folder.

Now I need to redirect visitors to default language. Say "en". AND I don't need having 4 sites actually: /, /en/, /ro/, /ru/, but 3.

The situation is actually like this

I can't "remove" the "/" site, actually

share|improve this question
    
Do you really want different websites for each language? Why dont you use WPML plugin instead? –  sorin Nov 1 '10 at 6:30
    
@Sorin Sbarnea WPML plugin is a plugin with bugs. And it does not translates the images on themes. –  serhio Nov 2 '10 at 2:21
add comment

2 Answers

up vote 6 down vote accepted

I use on the root site a small theme for redirect to the languages. A very small theme for locate the language of the users and redirect to the blog of this language.

<?php
// Browsersprache ermitteln
function lang_get_from_browser($allowed_languages, $default_language, $lang_variable = NULL, $strict_mode = TRUE) {
    // $_SERVER['HTTP_ACCEPT_LANGUAGE'] verwenden, wenn keine Sprachvariable mitgegeben wurde
    if ( NULL === $lang_variable )
        $lang_variable = $_SERVER['HTTP_ACCEPT_LANGUAGE'];

    // wurde irgendwelche Information mitgeschickt?
    if ( empty($lang_variable) ) 
        return $default_language;

    // Den Header auftrennen
    $accepted_languages = preg_split('/,\s*/', $lang_variable);

    // Die Standardwerte einstellen
    $current_lang = $default_language;
    $current_q    = 0;
    // Nun alle mitgegebenen Sprachen abarbeiten
    foreach ($accepted_languages as $accepted_language) {
        // Alle Infos dieser Sprache rausholen
        $res = preg_match(
            '/^([a-z]{1,8}(?:-[a-z]{1,8})*)'.
            '(?:;\s*q=(0(?:\.[0-9]{1,3})?|1(?:\.0{1,3})?))?$/i', 
            $accepted_language, 
            $matches
        );

        if (!$res)
            continue;

        // Sprachcode holen und dann sofort in die Einzelteile trennen
        $lang_code = explode('-', $matches[1]);

        // Wurde eine Qualität mitgegeben?
        if ( isset($matches[2]) )
            $lang_quality = (float)$matches[2];
        else
            $lang_quality = 1.0;

        // Bis der Sprachcode leer ist...
        while (count ($lang_code)) {
            // mal sehen, ob der Sprachcode angeboten wird
            if (in_array ( strtolower( join('-', $lang_code) ), $allowed_languages) ) {
                // Qualität anschauen
                if ($lang_quality > $current_q) {
                    $current_lang = strtolower( join('-', $lang_code) );
                    $current_q = $lang_quality;
                    break;
                }
            }
            // Wenn wir im strengen Modus sind, die Sprache nicht versuchen zu minimalisieren
            if ($strict_mode)
                break;

            // den rechtesten Teil des Sprachcodes abschneiden
            array_pop($lang_code);
        }
    }

    return $current_lang;
}

$allowed_langs = array('en', 'de');
$lang = lang_get_from_browser($allowed_langs, 'en', NULL, FALSE);

if ( 'de' === $lang )
    Header("Location: http://wpbasis.de/readme-de_DE.php");
else
    Header("Location: http://wpbasis.de/readme-en_US.php");
exit();
?>
share|improve this answer
    
Thanks! Would you be so kind to translate your comments to English? I don't need them but I don't want to include non-English comments in any of the files, it not good for maintenance. Also the solution could be adapted to use the languages defined in WordPress instead of harcoding them. –  sorin Nov 1 '10 at 13:59
    
I will write my code in a theme for free, then its all in english. –  bueltge Nov 1 '10 at 17:04
    
yeah. English comments rulles. Even If I am not a native English Speaker, I try to comment in English my code :) But, I don't understand, why this code you name "theme". Where should I find such a theme? –  serhio Nov 2 '10 at 2:31
    
i create a theme for WordPress in root blog for rewrite, current i write a theme for this. –  bueltge Nov 2 '10 at 19:02
1  
@bueltge: To stay with the comment language: Na das ist ja einmal gewaltig geil! –  kaiser Mar 25 '11 at 14:06
show 5 more comments

just leave it and place a redirect on it?

share|improve this answer
add comment

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.