Simple Multilanguage Switcher

Firstly i have been install wp with different languange with indonesian languange as default, i have plan, want to translate with other languange,
How to simple translate switch, but keep Indonesian as default.
with .po file

thanks for the help …

Related posts

Leave a Reply

1 comment

  1. Assuming you’re talking about the front-end and you have your strings properly internationalized, you just need to insert the load_theme_textdomain() function to tell wordpress where are your .po files.

    this is how the Toolbox Theme does it:

    /**
     * Make theme available for translation
     * Translations can be filed in the /languages/ directory
     * If you're building a theme based on martins, use a find and replace
     * to change 'martins' to the name of your theme in all the template files
     */
    load_theme_textdomain( 'martins', TEMPLATEPATH . '/languages' );
    
    $locale = get_locale();
    $locale_file = TEMPLATEPATH . "/languages/$locale.php";
    if ( is_readable( $locale_file ) )
        require_once( $locale_file );
    

    UPDATE:

    i once played with changing users locale to do that automatically, getting the users language from the $_SERVER superglobal.

    i came up with this, but it’s not working yet. Maybe you can work from it.

    WARNING: THIS IS UNTESTED AND MIGHT BEHAVE WEIRDLY OR EVEN BREAK YOUR SITE, BE CAREFUL

    function rm_get_locale($lang) {
        global $locale;
        // This gets the users' primary browser settings for acceptable languages
        // and transforms the string so it looks like en_US or pt_BR rather than
        // en-us and pt-br. It takes only the first value returned, no all of them.
        $langcode = explode(";", $_SERVER['HTTP_ACCEPT_LANGUAGE']);
        $langcode = explode(",", $langcode['0']);
        $langcode = $langcode['0'];
        $langcode = preg_split('/-/', $langcode);
        $upper = strtoupper($langcode[1]);
        $lower = $langcode[0];
    
        // now we get the native wp locale and the parsed user locale
        $wplocale = get_locale();
        $userlocale = implode('_',array($lower,$upper));
    
        // compare them and apply the user's locale if they don't match.
        if ($userlocale != $wplocale) {
            return $userlocale;
        } else {
            return $lang;
        }
    
    
    }
    add_filter('locale','rm_get_locale');