I have build a script for english version where all messages in game will be read from the script. Corresponding files will be built for each language, say messages_eng.txt, messages_fra.txt, …
So, here is the structure in the text file.
I created a Messages class than when game starts reads the script messages into a vector and I can use getMessage(int index) to read the message below.
/here is what the message looks like in the txt file/
INDEX-9|
“blah blah blah will cost %d production points and %d diplomacy points”
So, is this the best way to do it?
I am currently planning to read the string between the " charaters and replace the %d’s like this
public String replaceNumbers(String s, int[] ints)
where it loops through the int array and replace each occurrence of “%d”, for instance would the first %d be replaced by ints[0], the second one by ints[1], …
example of usage would be
this.replaceNumbers(this.messages.getMessage(9), 2, 8 );
In the example I inserted the numbers 2 and 8 into the message but ofcourse I will use variables for it.
Comments?