Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Variable in properties file.

 
Ranch Hand
Posts: 419
Mac jQuery Objective C
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.



 
Ranch Hand
Posts: 433
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try apache velocity...Txt base template engine...
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 22684
128
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
pawan chopra
Ranch Hand
Posts: 419
Mac jQuery Objective C
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks everyone. Thanks Rob I will try to implement this.
 
30 seconds to difuse a loaf of bread ... here, use this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic