Let’s make multi language website
A Simple Guide to implement Multi Language into your website. Here is the list of what is in use for this guide.
Create “index.html” with language switch button
“index.html” file that includes Bootstrap, jQuery, and custom script
It will look like this
<Head> where we include Bootstrap
<body> where we create the <h1> for text and button for each language
The end of <body> where we include jQuery, Bootstrap Script, and Our Custom Script
Code for th.json 🇹🇭
Code for en.json 🇬🇧
Code for ch.json 🇨🇳
Create script.js to handle language switching
getLang() function to define a default language and fetch for json file according to selected language.
setLang(lang) function handle a language change when user click on the buttons – Parameter ‘lang’ define what language to change into.
English Button will call setLang(‘en’) when clicked.
Call a getLang() function and apply text into <h1> tag with id=”text” when a webpage is loaded.
Now your website can say ‘Hello’ in English Thai and Chinese – YAY!