| Author |
Variable in properties file.
|
pawan chopra
Ranch Hand
Joined: Jan 23, 2008
Posts: 362
|
|
Hi All,
For localization purpose I am using properties file in my java application. I have few values with variables for example:
I have {0} number of bags
In above case {0} represents the number of bags. I was just thinking if instead of 0 I can say {numberOfBags}. is it possible by any way? I have tried it but didn't work.
|
Pawan Chopra
SCJP - DuMmIeS mInD
|
 |
Sunny Jain
Ranch Hand
Joined: Jul 23, 2007
Posts: 433
|
|
|
try apache velocity...Txt base template engine...
|
Thanks and Regards,
SCJP 1.5 (90%), SCWCD 1.5 (85%), The Jovial Java, java.util.concurrent tutorial
|
 |
Jesper de Jong
Java Cowboy
Bartender
Joined: Aug 16, 2005
Posts: 12927
|
|
Class java.text.MessageFormat can do things like that for you - look it up in the API documentation. Also lookup class java.util.ResourceBundle, which is Java's standard mechanism for dealing with localized messages.
pawan chopra wrote:I have tried it but didn't work.
What have you tried and why did it not work? ItDoesntWorkIsUseless
|
Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
pawan chopra wrote:In above case {0} represents the number of bags. I was just thinking if instead of 0 I can say {numberOfBags}. is it possible by any way?
Is numberOfBags another property in the file? If so, you can definitely get this to work. Well, I could
I won't give you my full class, but here are a few hints:
- Get the result of getProperty(key).
- Use a Pattern to get all the templates.
- For each template, use a recursive call to get their values and replace the value.
One thing: take care of loops. Consider you have two properties, "property1 = Value of property2 is {property2}" and "property2 = Value of property1 is {property1}". Now you want to get the value of property1. For this you need the value of property2. For this you need the value of property1. Oops. Note that this is the simplest form of looping; it can use many intermediate properties to form a loop.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
pawan chopra
Ranch Hand
Joined: Jan 23, 2008
Posts: 362
|
|
|
Thanks everyone. Thanks Rob I will try to implement this.
|
 |
 |
|
|
subject: Variable in properties file.
|
|
|