簡體   English   中英

如何在Java代碼中使用資源包文件?

[英]How to use resource bundle files in Java code?

我已經在JSTL <fmt>標簽庫可以使用的資源包文件中獲得了本地化消息。 現在,我也想從Java代碼中使用這些消息。 如何做呢?

我需要的是類似key的getMessage()和帶有參數的key的getParameterizedMessage()


更新以下似乎有效:

ResourceBundle messages = ResourceBundle.getBundle("messages");
String str = messages.getString("PF1");
System.out.println(str);

Object[] messageArguments = {
    "test"
};

MessageFormat formatter = new MessageFormat("");
formatter.applyPattern(messages.getString("IT4"));
String output = formatter.format(messageArguments);
System.out.println(output);

將您的消息加載到java.util.Properties並具有一個幫助程序類,如果提供了鍵,它將返回“屬性”中的值。

如果您正在尋找I18支持,則可以在此處找到入門基礎

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM