Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (121)
games submitted by our members
Games in WIP (577)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Language Scripting.  (Read 3098 times)
0 Members and 1 Guest are viewing this topic.
Offline zappsweden

Junior Duke




Java games rock!


« Posted 2007-02-14 15:04:19 »

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?



Offline Orangy Tang

JGO Kernel


Medals: 56
Projects: 11


Monkey for a head


« Reply #1 - Posted 2007-02-14 15:18:34 »

Heh, I'm afraid thats the typical n00b translation mistake - assuming the substitution params always occur in the same order. Eg. a phrase like "X will cost Y points" (where X and Y need replacing) may be phrased like "Y points needed for X" in another language. You need to distinguish between them somehow - one way would be to have your translated strings look like: "[1] will cost [2] points" and "[2] points needed for [1]", which correspond to the order of the params passed in to the replacement method.

I'd also look at replacing your '9' with something human readable, but thats a minor point.

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline zappsweden

Junior Duke




Java games rock!


« Reply #2 - Posted 2007-02-14 15:34:21 »

Heh, I'm afraid thats the typical n00b translation mistake - assuming the substitution params always occur in the same order. Eg. a phrase like "X will cost Y points" (where X and Y need replacing) may be phrased like "Y points needed for X" in another language. You need to distinguish between them somehow - one way would be to have your translated strings look like: "[1] will cost [2] points" and "[2] points needed for [1]", which correspond to the order of the params passed in to the replacement method.

I'd also look at replacing your '9' with something human readable, but thats a minor point.

So, the method implementation should prolly be something like

public String replaceNumbers(String s, int[] ints)
{

for(int i=0;i<ints.length;i++)
{
String next="["+i+"]";
String.replaceAll(next, ints[  i ] ) ;
}
}

I do not see the problem with the"9".
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Orangy Tang

JGO Kernel


Medals: 56
Projects: 11


Monkey for a head


« Reply #3 - Posted 2007-02-14 18:14:59 »

Well I'd much rather read:
1  
2  
3  
getMessage(Messages.ITEM_COST);
// or
getMessage("ItemCost");

that an arbitrary '9'.

Also, an array of Objects would be more useful than an array of ints, I think it's pretty likely you'll want to substiture in values other than ints at some point.

And you'll have to consider the case where you might want to print the token you're using to do replacement (ie. you actually want to display "[1]").

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline oNyx

JGO Coder


Medals: 2


pixels! :x


« Reply #4 - Posted 2007-02-14 18:55:03 »

http://java.sun.com/docs/books/tutorial/i18n/index.html

Java covers all of that already.

弾幕 ☆ @mahonnaiseblog
Offline Mr_Light

Senior Duke


Medals: 1


shiny.


« Reply #5 - Posted 2007-02-14 19:31:07 »

try also having a look at 'externalise strings' in your fav ide.

It's harder to read code than to write it. - it's even harder to write readable code.

The gospel of brother Riven: "The guarantee that all bugs are in *your* code is worth gold." Amen brother a-m-e-n.
Offline zappsweden

Junior Duke




Java games rock!


« Reply #6 - Posted 2007-02-15 13:36:22 »

it works and this is how the method looks. I use strings for everything now, just convert the numbers to string before i use this method. I found out that using the %s notation is best after all, if I were to use [var] then it could be mixed up with someting where you actually WANT to type [10] and not the value itself. %s is never used in any sentences that make sense so better use them.


 public static String replaceAll(String s, String[] var)
   {
     for(int i=0;i<var.length;i++)
     {
       String next = "%s" +(i+1) ;
       s=s.replaceAll(next, var [ i ] );
     }
     return s;
   }
Offline zappsweden

Junior Duke




Java games rock!


« Reply #7 - Posted 2007-02-15 13:40:11 »

.
Offline Abuse

JGO Knight


Medals: 13


falling into the abyss of reality


« Reply #8 - Posted 2007-03-17 09:32:36 »

it works and this is how the method looks. I use strings for everything now, just convert the numbers to string before i use this method. I found out that using the %s notation is best after all, if I were to use [var] then it could be mixed up with someting where you actually WANT to type [10] and not the value itself. %s is never used in any sentences that make sense so better use them.


 public static String replaceAll(String s, String[] var)
   {
     for(int i=0;i<var.length;i++)
     {
       String next = "%s" +(i+1) ;
       s=s.replaceAll(next, var [ i ] );
     }
     return s;
   }


Token order *does* change when localising text, so your mechanism is fundamentally flawed to begin with.
Also assuming the tokeniser special character will never be required is a poor limitation - you would normally allow escaping of the token identifier character to circumvent this limitation.
e.g. the String "%%" in the input String is substituted with the String "%" in the output.

As oNyx has pointed out - If you are using J2SE, all this functionality is provided for you already - why reinvent a substandard wheel, when a very good one has already been provided?
If this is for J2ME, then it is still a valid problem.

Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 818
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #9 - Posted 2007-03-17 13:01:11 »

Token order *does* change when localising text, so your mechanism is fundamentally flawed to begin with.

His code does take token-order into account...

Your other points are valid though.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline noblemaster

JGO Ninja


Medals: 20
Projects: 10


Age of Conquest makes your day!


« Reply #10 - Posted 2007-03-17 22:57:49 »

Just noted the thread - sorry for my late post Undecided

First of all, Java already has the capability to allow for multiple languages!!! There is no need to implement it yourself. It even includes the parameter substitution you mentioned above. Here is the link to the tutorial:
http://java.sun.com/docs/books/tutorial/i18n/index.html

It's the Java Internationalization. I managed to get my game translated to 10+ languages. All I need to give translators is the original messages bundle file with the English texts. A tool (I use attesoro) easy allows people to translate text to the desired language. It shows missing translations. Also, the messages bundle files are encoded, so I don't need to worry about translations people are sending back. Just plug them into your game = copy the file into the right directory and you are done!

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

theagentd (19 views)
2014-10-25 15:46:29

Longarmx (52 views)
2014-10-17 03:59:02

Norakomi (46 views)
2014-10-16 15:22:06

Norakomi (34 views)
2014-10-16 15:20:20

lcass (39 views)
2014-10-15 16:18:58

TehJavaDev (68 views)
2014-10-14 00:39:48

TehJavaDev (68 views)
2014-10-14 00:35:47

TehJavaDev (60 views)
2014-10-14 00:32:37

BurntPizza (74 views)
2014-10-11 23:24:42

BurntPizza (45 views)
2014-10-11 23:10:45
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!