I am NOT developing any web service application which contain client side and backend server side (like java EE application or Ruby on Rai
If you want your page to be search engine friendly, you have to put both static version in the HTML. You can put them into two div
and when user clicks on a flag you shows the correct div
.
You can also use a template like Mustache to render content with JavaScript. Then you can write your non-localized content as a template and make localized content as variables.
I read ceving's answer, and then write a JS library languages.js to do this.
I change the sequence of <title>
s' with different languages, so it works if you want to switch lang in the page title.
Write HTML like this:
<html>
<head>
<title lang="en">Test Page</title>
<title lang="zh-cmn-Hans">测试页面</title>
<title lang="ja">テストページ</title>
<title lang="miaw">miaw miaw miaw</title>
</head>
<body>
<div lang="en" style="display:block;">Why does the sun rise? Why does the moon shine?</div>
<div lang="zh-cmn-Hans">太阳为什么会升起?月亮为什么会发光?</div>
<div lang="ja" style="display:inline">太陽はなんで昇る?月はなぜ輝く?</div>
<div lang="miaw" style="display:inline">miaw miaw miaw miaw miaw miaw miaw miaw miaw miaw miaw miaw miaw</div>
</body>
</html>
<script src="https://raw.githubusercontent.com/MuromiU/JS/master/src/languages.js"></script>
Usage:
Languages.select(lang);
More detail: github readme
Your webpage needs to understand what encoding it should be using when rendering Chinese characters:
<! -- NOTICE THE "charset=UTF-8" !!!! -->
<head>
<meta content="text/html; charset=UTF-8" http-equiv="content-type"/>
</head>
Generally JS generating the code for you is not good. But, I did one POC for the same using underscore.js. The framework is having an "_template" function that helps us to replace all the keys in the HTML file. The function accepts the key value pair in JSON format.
Based on the language selected, load the corresponding JSON file and then pass it on to the _template function. This will replace all the keys.
Yes this is possible. Here is one way
Structure you HTML like this in your folders
/root
/Chinese
/English-American
index.html
The root folder would contain your page with the language selection and the Chinese and English-American will contain your language specific pages.
Now on index.html simply direct the user to the correct language folder and all links will reference the correct language folder