Hello, yes you need to have a language variable that the player can change, so you need to have a string for each dialogue, example $quest1, based on the language variable the string will get the data from english archive(or text file) or from others language database or text files…
I suggest you to call the variables based on where they are used example $shop_welcome01 or $inn_foodlist01
You will also have some words that will be used in different kind of situation so u can set a $talk_goodbye or $talk_you variables that can be used in different part of game…that’s how i solved the problem
The easiest way is probably to create a json file for each language you want. In your game you can load and use the json file for the language you require.
Where ever you use strings in your game/ui, make sure you look up the string rather than hard code it.
loadLang: function (lang) {
// find the json asset that has your language
var asset = app.assets.find(lang, "json");
// when the asset is loaded store the data into variable `this.data`
asset.ready(function (asset) {
this.data = asset.resource;
}, this);
// load the asset if it isn't already
app.assets.load(asset);
},
getText: function (src) {
return this.data[src];
}
Make sure to assign a default value to language variable or you will be without a reference when a player start the game or make a choice at the start if u insert the player name
Notice how I’m using the browser’s currently selected language to chose which strings I use:
var getLang = function () {
var lang = 'en';
if (navigator.language) {
if (navigator.language.substring(0, 2) === 'fr') {
lang = 'fr';
}
}
return lang;
}
i am using the tanx game , but i add some new functions like chat ingame , chat just for the team , rankings , login syste , create account with mysql , room list , user can create new room , when chat ingame appear baloon , and now i am putting multi language!!