2013-03-24 6 views
12

W this question, to zwraca uwagę, to jest możliwe, aby mieć coś takiego:Jak mogę używać parametrów w pliku messages.properties?

message.myMessage = This message is for {0} in {1}

Ale nie wiem jak przekazać parametr do niego

MESSAGES.getString ("message.myMessage" , "foor", "bar")

ale niestety getString nie może znać innych parametrów Masz pomysł?

+0

Jaki jest rodzaj wiadomości? –

+0

@JBNizet to ResourceBundle – mko

Odpowiedz

7

Wypróbuj ten jeden:

String message = "This message is for {0} in {1}."; 
String result = MessageFormat.format(message, "me", "the next morning"); 
System.out.println(result); 

(java.text.MessageFormat;)

albo w JSF:

<h:outputFormat value="This message is for {0} in {1}."> 
    <f:param value="me"> 
    <f:param value="the next morning"> 
</h:outputFormat> 
22

Zgaduję myślisz MessageFormat? Jeśli tak, to po prostu to:

String s = MessageFormat.format("This message is for {0} in {1}", "foo", "bar"); 

albo z właściwości:

Properties p = new Properties(); 
p.setProperty("messages.myMessage", "This message is for {0} in {1}"); 
String s = MessageFormat.format(
    p.getProperty("messages.myMessage"), "foo", "bar"); 
+0

Dziękuję za szybką odpowiedź, czy 'ResourceBundle' ma metody getProperty: – mko

+0

' private static final properties MESSAGES = new Properties() .load (ClassLoader.getSystemResourceAsStream ("rawcode.gui.messages")); ' – mko

Powiązane problemy