如何在messages.properties文件中使用参数? [英] How can I use parameters in a messages.properties file?

查看:609
本文介绍了如何在messages.properties文件中使用参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题中,它指出,可能会有以下内容:

In this question, it points out, It's possible to have something like:

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

但我不知道如何将参数传递给它

But I don't know how to pass parameter to it

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

但遗憾的是getString无法知道其他参数
有什么想法吗?

but unfortunately getString can't know take other parameters Any idea?

推荐答案

我我猜你在考虑 MessageFormat ?如果是这样,就是这样:

I'm guessing you're thinking of MessageFormat? If so, it's just this:

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

这篇关于如何在messages.properties文件中使用参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆