Questions tagged [messageformat]

Java's MessageFormat class and related utilities enable Java developers to construct localized property files and generate localized output.

Java's MessageFormat class and related utilities enable Java developers to construct localized property files and generate localized output.

IBM provides their own implementation of the same behavior to address some of the limitations with the native Java model, and other languages have implemented similar utilities, such as PHP's MessageFormatter class.

108 questions
154
votes
6 answers

How do I format a long integer as a string without separator in Java?

Simple question, but I'll bet that asking on here will probably be more straight forward than trying to understand the documentation for MessageFormat: long foo = 12345; String s = MessageFormat.format("{0}", foo); Observed value is…
Daniel Fortunov
  • 43,309
  • 26
  • 81
  • 106
95
votes
2 answers

What is the difference between MessageFormat.format and String.format in JDK 1.5?

What is the difference between MessageFormat.format and String.format in JDK 1.5?
kedar kamthe
  • 8,048
  • 10
  • 34
  • 46
78
votes
5 answers

Can I escape braces in a java MessageFormat?

I want to output some braces in a java MessageFormat. For example I know the following does not work: MessageFormat.format(" public {0} get{1}() {return {2};}\n\n", type, upperCamel, lowerCamel); Is there a way of escaping the braces surrounding…
Steve Bosman
  • 2,599
  • 1
  • 25
  • 41
38
votes
2 answers

Java internationalization (i18n) with proper plurals

I was going to use Java's standard i18n system with the ChoiceFormat class for plurals, but then realized that it doesn't handle the complex plural rules of some languages (e.g. Polish). If it only handles languages that resemble English, then it…
Dr.Haribo
  • 1,778
  • 1
  • 31
  • 43
12
votes
5 answers

Escaping single quotes for Java MessageFormat

There are already several questions about the MessagingFormat in general, but I haven't found anything yet that answers my question. I'm aware, that single quotes will break the pattern. If you use MessageFormat or Log4j something like "doesn't" can…
proko
  • 1,180
  • 1
  • 7
  • 14
11
votes
5 answers

Should I use java.text.MessageFormat for localised messages without placeholders?

We are localising the user-interface text for a web application that runs on Java 5, and have a dilemma about how we output messages that are defined in properties files - the kind used by java.util.Properties. Some messages include a placeholder…
Peter Hilton
  • 17,211
  • 6
  • 50
  • 75
11
votes
3 answers

Is the Java MessageFormat Class thread safe? (as opposed to SimpleDateFormat)

I know that SimpleDateFormat and NumberFormat are NOT thread safe. http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4101500 But what about the other Format classes like MessageFormat? Fortify 360 is flagging the use of…
user46915
11
votes
2 answers

Nested choice clause in MessageFormat?

I'm trying to do a simple logic with java.text.MessageFormat: MessageFormat cf = new MessageFormat( "{0,choice, 1
user2424380
  • 1,393
  • 3
  • 16
  • 29
9
votes
3 answers

Java Message Formatter is not working

I have String template xxxxxxxx xxxxx-xx: [{0}] xxxxxxx xxxxx xxxxxx xxxxxx [{1}] xxxxxx xxxx xxxxx'x xxxxx xxxxxx xxxx [{2}] Even if I provide all the three arguments still not working public static void main(String[] args) { String s =…
Makky
  • 17,117
  • 17
  • 63
  • 86
9
votes
3 answers

Java MessageFormat Null Values

What is the best way to treat null values in Java MessageFormat MessageFormat.format("Value: {0}",null); => Value: null but actually a "Value: " would be nice. Same with date MessageFormat.format("Value: {0,date,medium}",null); => Value: null a…
markush81
  • 201
  • 4
  • 10
7
votes
3 answers

better alternative to message format

I have a string of following format Select * where {{0} rdfs:label "Aruba" } limit 10 Now I would like to replace {0} with some new text, but the problem is message format is unable to parse the string due to the first curly bracket. I know if i…
Prim
  • 1,312
  • 5
  • 25
  • 51
6
votes
1 answer

How to represent plural rules for Russian or other complex plural languages in ICU MessageFormat

How can we represent Russian in ICU MessageFormat given the unusual nature of the pluralization rules? MessageFormat supports pluralization like {arg, plural, =1 {one} other {other}} and more complex {arg, plural, =0 {none} =1 {one} =2 {few} other…
Samuel Neff
  • 73,278
  • 17
  • 138
  • 182
6
votes
0 answers

Formatting a number as hexadecimal using MessageFormat in Java

How do I use MessageFormat to format a number in hexadecimal? I have an existing MessageFormat pattern, and the customer wants to change it from a decimal number to a three-digit hex number. Is this possible using MessageFormat? Or do I have to…
Ron Romero
  • 9,211
  • 8
  • 43
  • 64
6
votes
2 answers

How can I output localized Java floating point values in full precision?

If I format a double using the toString method, then I get the full precision of the double. For example (using Scala syntax): java.text.MessageFormat.format ("{0}", Math.PI.toString) will result in a string containing: 3.141592653589793 However,…
Mike Allen
  • 8,139
  • 2
  • 24
  • 46
6
votes
1 answer

TimeZone and MessageFormat with date parameters

MessageFormat class is cool because we can insert parameters and do the formatting directly with it. This permits me to be able to easily override a date format directly in a message bundle properties files. For exemple: MessageFormat.format("Test…
Sebastien Lorber
  • 89,644
  • 67
  • 288
  • 419
1
2 3 4 5 6 7 8