Setting language without $_GET

dev.xiligroup est en travaux Forums xili-language plugin Setting language without $_GET

Taggé: , ,

Ce sujet contient 0 réponses et 2 voix, et a été mis à jour par  Anonyme il y a Il y a 13 ans, 4 mois.

Visualisation du message 3 (1 sur 3, 3 au total)
  • Auteur
    Articles
  • #2947

    Anonyme

    After I wrote this, I tried writing this code in the beginning of your plugin:

    if(isset($_GET)){

    setcookie(‘lang’, $_GET);

    }

    elseif(isset($_COOKIE)){

    $_GET = $_COOKIE;

    }

    Now it’s working :) I think you must definitely use that in next versions if you didn’t.

    #2948

    Anonyme

    Your approach can be interesting according circumstances of uses. Do you know that xili-language is hookable, so you can change the behaviour how the language of theme is selected. Take a little time to read the source code and discover the « filter » entries. $_GET is a way to find explicitly the lang from URI but the_curlang function give you the language just after the famous loop of wp (specially when page or home or frontpage…).

    #2949

    Anonyme

    Ahm, it requires a bit time. Instead of reading the source code, I rather writing it from the beginning :p

    By the way, I added the code (above) inside set_when_plugin_loaded() function and expanded it:

    if(!is_admin()){

    $myLangs = $this->xili_settings;

    if(isset($_GET))

    {

    $check = false;

    foreach($myLangs as $l){

    if($l->slug == $_GET){

    setcookie(‘lang’, $_GET);

    $check = true;

    break;

    }

    }

    if($check == false){

    foreach($myLangs as $l){

    if($l->name == WPLANG){

    $_GET = $l->slug;

    setcookie(‘lang’, $l->slug);

    break;

    }

    }

    }

    }

    elseif(isset($_COOKIE)){

    $_GET = $_COOKIE;

    }}

    This checks if the get value of lang is available on language lists or not. If it’s not available, it sets the default language. Hope this helps people sharing my opinion.

    Have a good day.

Visualisation du message 3 (1 sur 3, 3 au total)

Vous devez être connecté pour répondre à ce sujet.