property Labels Bundle properties This is the default
Файл. property Состоит из пар ключ = значение Labels. Bundle. properties # This is the default Labels. Bundle. properties file s 1 = computer s 2 = disk s 3 = monitor s 4 = keyboard Labels. Bundle_de. properties # This is the Labels. Bundle_de. properties file s 1 = Computer s 2 = Platte s 3 = Monitor s 4 = Tastatur 17
Основные шаги 1. Создание файлов. properties по умолчанию и дополнительных Labels. Bundle. properties Labels. Bundle_de. properties Labels. Bundle_fr. properties 2. Создание объектов Locale (или использование констант) Locale[ ] supported. Locales = { Locale. FRENCH, Locale. GERMAN, Locale. ENGLISH }; 3. Создание объекта Resource. Bundle labels = Resource. Bundle. get. Bundle("Labels. Bundle", current. Locale); 4. Получение текста, соответствующего выбранной локали String value = labels. get. String(key); example 16 : поддержка различных языков Hamlet. International. java 18
Перечисление всех ключей в виде Enumeration<String> можно получить вызовом метода get. Keys(). Конкретное значение по ключу извлекается методом String get. String(String key). Resource. Bundle labels = Resource. Bundle. get. Bundle("Labels. Bundle", current. Locale); Enumeration bundle. Keys = labels. get. Keys(); while (bundle. Keys. has. More. Elements()) { String key = (String)bundle. Keys. next. Element(); String value = labels. get. String(key); System. out. println("key = " + key + ", " + "value = " + value); } 19
- Slides: 23