ListResourceBundle
是 ResourceBundle
的一個抽象類,用于管理方便而又易于使用的列表中的語言環境資源。有關資源包的常規信息,請參閱 ResourceBundle
。
子類必須重寫
getContents
并提供一個數組,其中數組中的每個項都是一個對象對。每對的第一個元素是鍵,該鍵必須是一個
String
,并且第二個元素是和該鍵相關聯的值。
下面的示例顯示了具有基本名稱 "MyResources" 的資源包系列的兩個成員。"MyResources" 是資源包系列的默認成員,"MyResources_fr" 是 French 成員。這些成員是基于ListResourceBundle
(一個相關的示例顯示了如何把一個資源包添加到基于屬性文件的此系列)。此示例中的鍵形式為 "s1" 等。實際的鍵完全取決于您的選擇,只要它們和程序中用于從資源包中獲取對象的鍵相同。鍵區分大小寫。
public class MyResources extends ListResourceBundle {
protected Object[][] getContents() {
return new Object[][] = {
// LOCALIZE THIS
{"s1", "The disk \"{1}\" contains {0}."}, // MessageFormat pattern
{"s2", "1"}, // location of {0} in pattern
{"s3", "My Disk"}, // sample disk name
{"s4", "no files"}, // first ChoiceFormat choice
{"s5", "one file"}, // second ChoiceFormat choice
{"s6", "{0,number} files"}, // third ChoiceFormat choice
{"s7", "3 Mar 96"}, // sample date
{"s8", new Dimension(1,5)} // real object, not just string
// END OF MATERIAL TO LOCALIZE
};
}
}
public class MyResources_fr extends ListResourceBundle {
protected Object[][] getContents() {
return new Object[][] = {
// LOCALIZE THIS
{"s1", "Le disque \"{1}\" {0}."}, // MessageFormat pattern
{"s2", "1"}, // location of {0} in pattern
{"s3", "Mon disque"}, // sample disk name
{"s4", "ne contient pas de fichiers"}, // first ChoiceFormat choice
{"s5", "contient un fichier"}, // second ChoiceFormat choice
{"s6", "contient {0,number} fichiers"}, // third ChoiceFormat choice
{"s7", "3 mars 1996"}, // sample date
{"s8", new Dimension(1,3)} // real object, not just string
// END OF MATERIAL TO LOCALIZE
};
}
}
posted on 2012-01-04 14:29
RoyPayne 閱讀(311)
評論(0) 編輯 收藏 所屬分類:
java高級