開發網頁很有可能會遇到要做多國語言的問題,像 ASP.NET 等的 Server 端程式可能都有提供相關的套件來達到效果,但是前端JavaScript 要怎樣做到多國語言呢?

筆者曾經也做過類似的多國語言程式,不過當時只需要英文及繁體中文兩種而已,所以用了比較簡單的作法來完成。不過現在若還有同樣需求的話,筆者會改採用 Localisation assistance for jQuery 來做。

Localisation assistance for jQuery 在使用時要先指定一個預設的語言檔,例如:lang.js,接著其它語言檔名就依瀏覽器所取到的 language 名稱為主,因此像是繁體中文的語言檔名就變成了 lang-zh-TW.js,簡體中文就是 lang-zh-CN.js。

套件名稱:Localisation assistance for jQuery
套件版本:1.0.2
作者網站:http://keith-wood.name/localisation.html
套件網址:http://plugins.jquery.com/project/localisation
發佈日期:2007-09-29
檔案大小:2.42 KB
檔案下載:jquery.localisation.js
其它語言檔:greeting.js greeting-en.js greeting-zh-CN.js greeting-zh-TW.js