Skip to content

JavaScript multi-language localisation using a json file to add UI translation to websites or games

Notifications You must be signed in to change notification settings

BdR76/MultiLanguage

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

JavaScript multi-language localisation using a json file to add UI translation to websites or games

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

Packages

No packages published