私のプロジェクトではproperties files
、国際化に使用される2つがあります。パラメータとともに使用ResourceBundle
しLocale
、プロパティファイルのキーをコレクションに保存します。残念ながら、コレクションには両方のファイルの結合されたキーが保存されています。ロケールに応じて、単一のファイルからキーが必要です。私の場合、ロケールは「bg_BG」です。プロパティファイルは次のとおりです。
time_intervals.properties
time_intervals_bg.properties
そして、これは私がそれらを読んでいる方法です:
public List<SelectItem> getTimeSpentList() {
timeSpentList = new ArrayList<SelectItem>();
FacesContext context = FacesContext.getCurrentInstance();
ResourceBundle bundle = ResourceBundle.getBundle("properties.time_intervals", context.getViewRoot().getLocale());
Enumeration<String> time_interval_keys = bundle.getKeys();
List<String> sortedKeys = new ArrayList<String>();
while(time_interval_keys.hasMoreElements()) {
String key = time_interval_keys.nextElement();
sortedKeys.add(key);
}
Collections.sort(sortedKeys, new Comparator<String>() {
@Override
public int compare(String o1, String o2) {
if (o1.charAt(1) != ' ') {
return -1;
} else if (o2.charAt(1) != ' ') {
return 1;
}
return o1.compareTo(o2);
}
});
for (String key : sortedKeys) {
timeSpentList.add(new SelectItem(key));
}
if (timeSpentList == null || timeSpentList.isEmpty()) {
timeSpentList.add(new SelectItem(""));
return timeSpentList;
}
return timeSpentList;
}
ここでの問題は、Enumeration<String> time_interval_keys
呼び出した後に両方のプロパティファイルから結合されたキーを取得するbundle.getKeys()
が、そのうちの1つからの値のみが必要なことです。助けてください。
PS私の説明とコードについて不明な点があれば教えてください。