Подтвердить что ты не робот

Как использовать параметры в файле messages.properties?

В этом вопросе он указывает, что возможно иметь что-то вроде:

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

Но я не знаю, как передать ему параметр

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

но, к сожалению, getString не может знать другие параметры. Любая идея?

4b9b3361

Ответ 1

Я предполагаю, что вы думаете о MessageFormat? Если это так, то это:

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

Или из свойств:

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");

Ответ 2

Попробуйте это:

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;)

Или в JSF:

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