简体   繁体   中英

Google and multi-language website with same URL

I'm building a website with multi-language support using geoplugin php class to detect country code. Here is my geolocate code:

//GEOLOCATE
$geoplugin = new geoPlugin(); 
$geoplugin->locate();
define('REAL_COUNTRY', strtoupper($geoplugin->countryCode));

//AVAILABLE COUNTRIES
function available_countries(){
    $countries_array = array();
    $sql = mysql_query("SELECT id FROM countries WHERE enabled = '1';") or die(mysql_error());
    while($row = mysql_fetch_array($sql)) array_push($countries_array, $row['id']);
    return $countries_array;
}

//RETURN COUNTRY CODE
function detect_language(){
    if(isset($_COOKIE['country'])) return $_COOKIE['country'];
    else if(isset($_SESSION['country'])) return $_SESSION['country'];
    else if(in_array(REAL_COUNTRY, available_countries())) return REAL_COUNTRY;
    else return 'EN';
}

Based on returned country code, my php script then loads content from database.

I want to have links formatted like this:

English site: sitename.com/contact
German site: sitename.com/kontakt
Slovenian site: sitename.com/kontakt


Notice, that URLs for German and Slovenian site are the same, but it still loads different content based on IP and returned code from geoplugin.

The site works well, but my concern are Google and other search engines. Will Google ever find pages in other languages than 'EN' or is it better to just use more classic approach and add a language id to URLs like this:

English site: sitename.com/ /contact / contact
German site: sitename.com/ /kontakt / kontakt
Slovenian site: sitename.com/ /kontakt / kontakt


Thanks!

I would recommend that you go with the descriptive URL. It makes it based on the URL 100% different for any search engine, and confusion is thus eliminated.

Do ensure that you also change the META information on each page to the right language. This will help classify the Language from the start.

By using the this approach you would also ensure that regardless of what part of the site get's linked and thus improved in search engines, the complete Domain will get the better ranking, thus keeping your SEO efforts together.

Readable URL are in every way the best idea for this decade.

CSS for hide google tool bar

.goog-te-banner-frame.skiptranslate {
    display: none !important;
}
#google_translate_element{
    display: none !important;   
}

Callback fucntion for tranlation

function googleTranslateElementInit() {
    new google.translate.TranslateElement({
        pageLanguage: 'de', 
        //includedLanguages: 'ar,en,gu,hi,pa,ur',       
        autoDisplay: false,

    }, 'google_translate_element');
}
<script type="text/javascript" src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>

fire event on page load

function fireEvent(element, event) {
  if (document.createEventObject) {
    var evt = document.createEventObject();
    return element.fireEvent('on' + event, evt)
  } else {
    var evt = document.createEvent("HTMLEvents");
    evt.initEvent(event, true, true);
    return !element.dispatchEvent(evt);
  }
}

var jObj = $('.goog-te-combo');
var db = jObj.get(0);
jObj.val('gu');
fireEvent(db, 'change');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM