syrasia Posted January 3, 2017 Share Posted January 3, 2017 Hi there, again I am put before a headache. I want my script (well, only the gui in particular) to be multilingual. At the moment this is only German and English, so no big deal. I give every gui-element a "text-id", and in the sql database i have saved the sentences for German and English respectively. Now, if the client needs a string for a gui element, he request it from the server in the given language. So far so good, but requesting a string over and over again just wastes bandwidth and cpu as hell. And a bit of delay (client request - sql query - server answer - guiSetText). To get rid of this inconvenience I want to safe the already loaded string in a file local on the client, but I don't trust xml to be the best choice for large data storage. I should add; I only read the file once at client startup and store the stings in a table and just for addition of new loaded strings the xml gets updated. No constant access to the xml! And I just thought: the Update can be done at logout? Do scripts finish all given code on unload? Thanks in advance for your help! Link to comment
pa3ck Posted January 4, 2017 Share Posted January 4, 2017 (edited) You can just store the XML on server side, so player's won't be able to edit it. Even if they do, the checksum will be different and will be downloaded (AFAIK that's how server side files are downloaded) If you don't want to use XML, use JSON, that works as well and probably easier to load from JSON anyway. Edited January 4, 2017 by pa3ck Link to comment
Miika Posted January 4, 2017 Share Posted January 4, 2017 (edited) Or just create client sided table and add it to meta so players can't edit it. It would be also fastest because you don't have to request every single word from server. Just create client table like this: languages = { ["Germany"] = { ["edit1"] = "German version of text"; ["edit2"] = "blablablabla"; }; ["English"] = { ["edit1"] = ["English version of text"; ["edit2"] = "blablablabla"; }; } And just use the data like this: if language == "germany" then guiSetText(text-element, languages["Germany"]["edit1"]) guiSetText(button-element, languages["Germany"]["edit2"]) elseif language == "english" then guiSetText(text-element, languages["English"]["edit1"]) guiSetText(button-element, languages["English"]["edit2"]) end Nice, simple and logical. Edited January 4, 2017 by Miika Link to comment
Tails Posted January 4, 2017 Share Posted January 4, 2017 (edited) 2 hours ago, syrasia said: Now, if the client needs a string for a gui element, he request it from the server in the given language. Unless you really need the data to be private, I'd suggest to just store the data in a table on the client. Isn't it to just change the language of the texts in the gui, something they can already see and read and is loaded in memory? To add to Miika's example: local chosenLanguage = "English" local languages = { ["Germany"] = { ["edit1"] = "German version of text", ["edit2"] = "blablablabla", }, ["English"] = { ["edit1"] = "English version of text", ["edit2"] = "blablablabla", }, } guiSetText(text-element, languages[chosenLanguage]["edit1"]) guiSetText(button-element, languages[chosenLanguage]["edit2"]) Edited January 4, 2017 by Tails Link to comment
Tails Posted January 4, 2017 Share Posted January 4, 2017 (edited) Okay, here's a better example: local myGui = {} myGui.label1 = guiCreateLabel(397, 433, 280, 67, "test", false) myGui.label2 = guiCreateLabel(397, 493, 280, 67, "test", false) local languages = { ["german"] = { label1 = "Ich bin hans", label2 = "kekekekkek", }, ["english"] = { label1 = "I am hans", label2 = "hahahahaha", }, } function setGuiLanguage(language) for k,v in pairs(languages[language]) do if myGui[k] then guiSetText(myGui[k],v) end end end addCommandHandler("language", function(_,lang) if languages[lang] then setGuiLanguage(lang) end end ) Edited January 4, 2017 by Tails Link to comment
syrasia Posted January 4, 2017 Author Share Posted January 4, 2017 (edited) The thing is, that this would work, but as my gui text increases (and this will get by far over 10000 strings because of a chat system for npc's) this would get messy. Also I want user to be able to modify the language files, because this way someone cloud implement french or polish for example. And adding to a table in the files would limit me, as I will have multiple resources with the same text later. (Unnecessary redundancy) Therefore a external script in my helper resource will do the job. Now I just want to know the finest solution for a huge amount of data. Is xml still okay for this task? Edit: The language script in the helper resource will do the job of replacing the strings in the gui elements! Not the gui script them self. I already have the basic figured out. What I want to know is more or less, if xml has limits for greater file sizes, if there are drawbacks and if there are alternatives for dynamic (user modifiable) data storage. Edited January 4, 2017 by syrasia Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now