2
votes

I'm about to launch a website which is available in three languages : English, French, German.

Right now we use a detection of the user's browser's language to display the right language automatically.

Each of the text objects in the HTML is assigned an id and we use innerHTML in a javascript file to replace text with the right language.

Here's an example of what we have in the JS :

function adjust_languages() {
    // change all object text, if french
    if (sprache == "french") {

        document.getElementById("hello").innerHTML = "Bonjour";

    }
    // change all objects if german
    else if (sprache == "german") {
        document.getElementById("hello").innerHTML = "Hallo";

    }
    else {
        // PUT ALL THE ENGLISH HERE
        document.getElementById("hello").innerHTML = "Hello";

    }
}

I'm curious to know if this method could also work for multilingual meta descriptions.

What I want is that Google displays the meta description of the website depending on the user's browser's language.

For example, if the user types in French keywords, or just simply types the name of the website in a browser whose default language is set as French, I want Google to display the French version of the website in the results (therefore with a French meta description).

Will the innerHTML method work in this case as well ?

1
For multilingual, XML usage is suggested. - Sagar V

1 Answers

0
votes

There are multiple way for lenguage translation.Suggested Way Below:

1 -> Preapare two different json file (1)idMapfile (2)langMap_Fr(or whatever lenguage is.) map those by common string like.

idMap.json

"helloContext":"helloDom"

*helloDom is DOM id

langMap_Fr.json

"helloContext":"Bonjour"

langMap_Gr

"helloContext":"Hello"

2 -> Now on load of site compare those langMap json with idMap json using js(lodash.js is providing good librery to compare json and other opratioins with json, object and array) and prepare 2D arrey(or probebly a json, as per your convinency) for each lenguage like: frArr = [["helloDom","Bonjour"]] and grArr = [["helloDom","Hello"]] so you can manupulat lenguage on runtime.

3 -> now write a function which put Translated word to specific dom element(something similer to your function but in loop).

This is the logic behind multiLang using js.