• Resolved andaluzo

    (@andaluzo)


    Hi,

    first great work and thanks!
    Where is the donate button πŸ™‚

    Actually i have installed and everything works fine so far.

    I have one issue.

    As I want consistant URLS

    like
    /de/
    /es/
    /en/
    /it/

    I realy do not like to use the root / for any language. But User type the direct URL so what to do with that part of the network, is there any way to redirect by default o by User language to one of the network sites?

    That would be great !

    http://wordpress.org/extend/plugins/multisite-language-switcher/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Dennis Ploetner

    (@realloc)

    Seems something like this: https://github.com/lloc/Multisite-Language-Switcher/issues/15

    Cheers,
    Dennis.

    Plugin Author Dennis Ploetner

    (@realloc)

    Is this problem resolved now?

    BTW There is a donate button which points to http://www.greenpeace.org/ … πŸ˜‰

    Thread Starter andaluzo

    (@andaluzo)

    I resolved it with

    putting the following as index.php in the template for ‘/’

    ?php
    /**
     * The main template file.
     *
     * This is the most generic template file in a WordPress theme
     * and one of the two required files for a theme (the other being style.css).
     * It is used to display a page when nothing more specific matches a query.
     * E.g., it puts together the home page when no home.php file exists.
     * Learn more: http://codex.wordpress.org/Template_Hierarchy
     *
     * @package WordPress
     * @subpackage Redirect
     */
    
    /**
     * Detect browser language.
     *
     * @param array $allowed_languages An array of languages that are available on the site.
     * @param string $default_language Default language to use if none could be detected.
     * @param string $lang_variable Custom user language support. If not specified $_SERVER['HTTP_ACCEPT_LANGUAGE'] is used.
     * @param string $strict_mode If true (default) the whole language code ("en-us") is used and not only the left part ("en").
     * @return string The detected browser language.
     */
    function get_lang_from_browser($allowed_languages, $default_language, $lang_variable = NULL, $strict_mode = TRUE) {
        // Use $_SERVER['HTTP_ACCEPT_LANGUAGE'] if no language variable is available
        if (NULL === $lang_variable)
            $lang_variable = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
    
        // Any info sent?
        if (empty($lang_variable))
            return $default_language;
    
        // Split the header
        $accepted_languages = preg_split('/,\s*/', $lang_variable);
    
        // Set default values
        $current_lang = $default_language;
        $current_q    = 0;
        // Now work through all included languages
        foreach ($accepted_languages as $accepted_language) {
            // Get all info about this language
            $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;
    
            // Get language code and split into parts immediately
            $lang_code = explode('-', $matches[1]);
    
            // Is there a quality set?
            if (isset($matches[2]))
                $lang_quality = (float)$matches[2];
            else
                $lang_quality = 1.0;
    
            // Until the language code is empty...
            while (count($lang_code)) {
                // Check if the language code is available
                if (in_array(strtolower(join('-', $lang_code)), $allowed_languages)) {
                    // Check quality
                    if ($lang_quality > $current_q) {
                        $current_lang = strtolower(join('-', $lang_code));
                        $current_q = $lang_quality;
                        break;
                    }
                }
                // If we're in strict mode we won't try to minimalize the language
                if ($strict_mode)
                    break;
    
                // Cut the most right part of the language code
                array_pop($lang_code);
            }
        }
    
        return $current_lang;
    }
    
    $allowed_langs = array('en', 'de', 'es');
    $lang = get_lang_from_browser($allowed_langs, 'en', NULL, FALSE);
    header('Location: http://' . $_SERVER['HTTP_HOST'] . "/$lang/");
    
    exit();
    ?>

    If you generate it as blank theme you should also put some styles.css in that Theme folder.

    Works great, seams to be German engineering your plugin πŸ™‚

    Plugin Author Dennis Ploetner

    (@realloc)

    Yes, your solution is similar to the solution I linked in my first answer. The default blog gets a theme which makes nothing else than forwarding a user.

    And yes, I’m German (but live in Milan). πŸ˜‰

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘URL Structure Problem’ is closed to new replies.