Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to develop the site to switch between multiple languages?

I have developed the website in html5. In this I have an language selection option, now it is in English. If I select any other language, then it should show the contents in that language. I don't want to use the Google translator to translate the content. I have the content in all languages. If any tags or methods in html5 or HTML to get and display the contents specific to that language?

like image 755
user2274193 Avatar asked Apr 11 '26 07:04

user2274193


2 Answers

You can use Javascript localization (this is one of your tags, so I guess you'd use it).

What you can do is a quick-check for the locale of the user, thus filling the page with a matching localization of your contents.

Here's a quick and dirty example. (note: this is purely dynamic)

locale = (navigator["language"] || "en").split("-")[0];

localization = {
    "de": "Hallo Benutzer!",
    "en": "Hey user!"
};

text = localization[locale] || localization["en"];

e = document.createElement("span");
e.innerHTML = text;
document.body.appendChild(e);
like image 69
19h Avatar answered Apr 12 '26 19:04

19h


If your website is a static one, then you can clone your site for each language, by using language specific content, and access each version with a different base url ( domain/en/..., domain/es/....).

like image 35
Ion Sapoval Avatar answered Apr 12 '26 19:04

Ion Sapoval



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!