How to localize a simple HTML website page in my case?

前端 未结 11 589
没有蜡笔的小新
没有蜡笔的小新 2020-12-01 04:34

I am NOT developing any web service application which contain client side and backend server side (like java EE application or Ruby on Rai

相关标签:
11条回答
  • 2020-12-01 05:09

    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.

    0 讨论(0)
  • 2020-12-01 05:12

    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

    0 讨论(0)
  • 2020-12-01 05:15

    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>
    
    0 讨论(0)
  • 2020-12-01 05:15

    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.

    0 讨论(0)
  • 2020-12-01 05:18

    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

    0 讨论(0)
提交回复
热议问题