150 likes | 328 Views
Java/ICU Internationalization Architecture. Mark Davis. Summary: Java / ICU. Shared basic architecture Locales, resources, services, data-driven Same development team: Java and C/C++ Core ICU4j part of Java 1.1 and later API syntax customized to programming language Cross-platform
E N D
Java/ICU Internationalization Architecture Mark Davis
Summary: Java / ICU • Shared basic architecture • Locales, resources, services, data-driven • Same development team: Java and C/C++ • Core ICU4j part of Java 1.1 and later • API syntax customized to programming language • Cross-platform • Fully extensible • Thread-safe model • Open Source: ICU4j, ICU4c
Locales • Name, not data structure • Language, Country, Variant • English • English, US • Norwegian, Norway, Nynorsk • Italy, Italian, Euro
Resources • General Purpose: map Key Data • Application-Specific Data • General Services Data • String String Array: recurseKey Data: recurse • Java: arbitrary Objects as well
Find Bundle Resources Inheritance • Find Resource en_us_some-varianten_usendefLang_defCountrydefLangroot • Results cached
Data • Flexible loading structure • Memory mapped files • DLLs • Simple loading
Services • Locale-Independent • Unicode characters: storage / access, properties • Character conversion • Locale or ID-Dependent — Explicit or Default Locale • Format/parse: number/currency/date-time/msgs,… • Language-sensitive collation, searching,… • Boundaries: character, word, line-wrap, sentence • Display names: country / language • Transliteration, casing
Open, Use, Close • Java col = Collator.getInstance ( aLocale );…sortKey = col.getSortKey ( aStr ); • ICU4c col = ucol_open( aLocale, &err);…keyLen = ucol_getSortKey ( col, aStr, -1, sortKey, maxLen ); …ucol_close ( col );
Why Open/Close? • Amortize setup over multiple uses • With convenience routines for one-time or simple use • Full Multi-locale, Multi-thread • Example: Open sortFranceandsortUS • Use at same time, in same thread or different threads • Constant data shared between threads • Note: Different threads need different “opens”
Thread 1 Thread 2 Collator State Ptr Collator State Ptr Collator State Ptr Common read-only data German Common read-only data French Threading
Error Handling • Java • Exceptions • C / C++ • Local error parameter: &err • Supports chaining • Minimal compiler demands
Data Driven • Wherever possible, services are data-driven. • Examples • Collations: “z < þ” or “И < Й” • Numbers: “#,##0.00” • Transliterations: “a <> α” or “ps <> ψ” • Services: built at compile time or runtime • Services: built by “merging” • E.g. French + Arabic sorting
Data Storage Format • Java • Class files (compiled) • Property files (processed at runtime) • ICU4c • Precompiled DLLs or Memory-mapped file • Flattened structure: memory structure = disk • Collation — ICU4c 1.7
Character Conversions • List supported names, aliases • Low-level buffer support • We handle details — no copying “parts”
Summary: Java / ICU • Shared basic architecture • Locales, resources, services, data-driven • Same development team: Java and C/C++ • Core ICU4j part of Java 1.1 and later • API syntax customized to programming language • Cross-platform • Fully extensible • Thread-safe • Open Source: ICU4j, ICU4c