MultiLanguage
JavaScript multi-language localisation using a json file to add UI translation to websites or games
Install / Use
/learn @BdR76/MultiLanguageREADME
MultiLang.js
MultiLang.js is a JavaScript object to handle multilanguage, localisation, JSON file loading, detect default language, detect non-existing phrases etc.
It contains a working example page and a JSON example file with multiple languages. Initially created for Phaser.js games, but it can be applied to any JavaScript project or website.
How to use
Store two or more translations in a JSON file, for example languages.json like this:
{
"en": {
"Hello": "Hello World!",
"SaveChanges": "Do you want to save the changes?",
"Yes": "Yes",
"No": "No"
},
"fr": {
"Hello": "Bonjour à tous!",
"SaveChanges": "Voulez-vous sauvegarder les modifications?",
"Yes": "Oui",
"No": "Non"
},
"zh": {
"Hello": "大家好",
"SaveChanges": "是否要保存更改?",
"Yes": "要",
"No": "不要"
}
}
And then MultiLang.js can be used like this:
var multilang = new MultiLang('languages.json');
multilang.setLanguage('fr');
alert( multilang.get('Hello') );
Manage translations
Keeping track of all the translated strings can be a challenge, even for smaller projects. See this Excel spreadsheet to manage translations more easily. The translator(s) can fill the spreadsheet with translated texts and the JSON file can then be generated using a Excel VBA or LibreOffice macro. For more information see here.
Also see the Manage translations github page
spreadsheet --> macro --> JSON
XML strings
String.localization
resx
History
2016-oct-28 upload project on github
Send any questions or comments to Bas de Reuver - bdr1976@gmail.com
Related Skills
node-connect
344.4kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
99.2kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
344.4kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
344.4kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
