lukaMis Posted June 30, 2014 Share Posted June 30, 2014 Hi Is it possible in Phaser to load game texts at beginning as txt or json files and use them in game to allow easy customization and/or localization? tnxLuka Link to comment Share on other sites More sharing options...
lewster32 Posted June 30, 2014 Share Posted June 30, 2014 You can load JSON files just by doing game.load.json("gametext", "/path/to/gametext.json") and then retrieve it later with game.cache.getJSON("gametext") which will give you an object representing the JSON you loaded. From there you can built your own localisation routine; maybe a wrapper function which returns the specified language version of a string:// json file contents{ "hello": { "en": "Hello", "fr": "Bonjour", "sk": "Ahojte" }}Translate function (bare bones, would need to be smarter than this for real use):function localise(str, lang) { lang = lang || "en"; // default language if none specified // get our localisation file contents as a JS object var loc = game.cache.getJSON("gametext"); // return the specified string in the specified language dynamically using array notation return loc[str][lang];}console.log(localise("hello") + " Luka!"); // "Hello Luka!";console.log(localise("hello", "fr") + " Luka!"); // "Bonjour Luka!";console.log(localise("hello", "sk") + " Luka!"); // "Ahojte Luka!"; lukaMis 1 Link to comment Share on other sites More sharing options...
lukaMis Posted June 30, 2014 Author Share Posted June 30, 2014 @lewster32 Tnx.Right what was i imagining. Link to comment Share on other sites More sharing options...
Recommended Posts