12e5b6d6dSopenharmony_ci--- 22e5b6d6dSopenharmony_cilayout: default 32e5b6d6dSopenharmony_cititle: Localizing with ICU 42e5b6d6dSopenharmony_cinav_order: 3 52e5b6d6dSopenharmony_ciparent: Locales and Resources 62e5b6d6dSopenharmony_ci--- 72e5b6d6dSopenharmony_ci<!-- 82e5b6d6dSopenharmony_ci© 2020 and later: Unicode, Inc. and others. 92e5b6d6dSopenharmony_ciLicense & terms of use: http://www.unicode.org/copyright.html 102e5b6d6dSopenharmony_ci--> 112e5b6d6dSopenharmony_ci 122e5b6d6dSopenharmony_ci# Localizing with ICU 132e5b6d6dSopenharmony_ci{: .no_toc } 142e5b6d6dSopenharmony_ci 152e5b6d6dSopenharmony_ci## Contents 162e5b6d6dSopenharmony_ci{: .no_toc .text-delta } 172e5b6d6dSopenharmony_ci 182e5b6d6dSopenharmony_ci1. TOC 192e5b6d6dSopenharmony_ci{:toc} 202e5b6d6dSopenharmony_ci 212e5b6d6dSopenharmony_ci--- 222e5b6d6dSopenharmony_ci 232e5b6d6dSopenharmony_ci## Overview 242e5b6d6dSopenharmony_ci 252e5b6d6dSopenharmony_ciThere are many different formats for software localization, i.e., for resource 262e5b6d6dSopenharmony_cibundles. The most important file format feature for translation of text elements 272e5b6d6dSopenharmony_ciis to represent key-value pairs where the values are strings. 282e5b6d6dSopenharmony_ci 292e5b6d6dSopenharmony_ciEach format was designed for a certain purpose. Many but not all formats are 302e5b6d6dSopenharmony_cirecognized by translation tools. For localization it is best to use a source 312e5b6d6dSopenharmony_ciformat that is optimized for translation, and to convert from it to the 322e5b6d6dSopenharmony_ciplatform-specific formats at build time. 332e5b6d6dSopenharmony_ci 342e5b6d6dSopenharmony_ciThis overview concentrates on the formats that are relevant for working with 352e5b6d6dSopenharmony_ciICU. The examples below show only lists of strings, which is the lowest common 362e5b6d6dSopenharmony_cidenominator for resource bundles. 372e5b6d6dSopenharmony_ci 382e5b6d6dSopenharmony_ci## Recommendation 392e5b6d6dSopenharmony_ci 402e5b6d6dSopenharmony_ciThe most promising long-term approach is to author localizable data in XLIFF 412e5b6d6dSopenharmony_ciformat (see the [XLIFF](#xliff) (§) section below) and to convert it to native, 422e5b6d6dSopenharmony_ciplatform/tool-specific formats at build time. 432e5b6d6dSopenharmony_ci 442e5b6d6dSopenharmony_ciShort-term, due to the lack of ICU tools for XLIFF, either custom tools must be 452e5b6d6dSopenharmony_ciused to convert from some authoring/translation format to Java/ICU formats, or 462e5b6d6dSopenharmony_cione of the Java/ICU formats needs to be used for authoring and translation. 472e5b6d6dSopenharmony_ci 482e5b6d6dSopenharmony_ci## Java and ICU4J 492e5b6d6dSopenharmony_ci 502e5b6d6dSopenharmony_ci### .properties files 512e5b6d6dSopenharmony_ci 522e5b6d6dSopenharmony_ciJava `PropertyResourceBundle` uses runtime-parsed .properties files. They contain 532e5b6d6dSopenharmony_cikey-value pairs where both keys and values are Unicode strings. No other native 542e5b6d6dSopenharmony_cidata types (e.g., integers or binaries) are supported. There is no way to 552e5b6d6dSopenharmony_cispecify a charset, therefore .properties files must be in ISO 8859-1 with \u 562e5b6d6dSopenharmony_ciescape sequences (see the Java `native2ascii` tool). 572e5b6d6dSopenharmony_ci 582e5b6d6dSopenharmony_ciDefined at: http://java.sun.com/j2se/1.4/docs/api/java/util/PropertyResourceBundle.html 592e5b6d6dSopenharmony_ci 602e5b6d6dSopenharmony_ciExample: (`example_de.properties`) 612e5b6d6dSopenharmony_ci 622e5b6d6dSopenharmony_ci```properties 632e5b6d6dSopenharmony_cikey1=Deutsche Sprache schwere Sprache 642e5b6d6dSopenharmony_cikey2=Düsseldorf 652e5b6d6dSopenharmony_ci``` 662e5b6d6dSopenharmony_ci 672e5b6d6dSopenharmony_ci### .java ListResourceBundle files 682e5b6d6dSopenharmony_ci 692e5b6d6dSopenharmony_ciJava `ListResourceBundle` files provide implementation subclasses of the 702e5b6d6dSopenharmony_ci`ListResourceBundle` abstract base class. **They are Java code!** Source files are 712e5b6d6dSopenharmony_ci.java files that are compiled as usual with the javac compiler. Syntactic rules 722e5b6d6dSopenharmony_ciof Java apply. As Java source code, they can contain arbitrary Java objects and 732e5b6d6dSopenharmony_cican be nested. 742e5b6d6dSopenharmony_ci 752e5b6d6dSopenharmony_ciAlthough the Java compiler allows to specify a charset on the command line, this 762e5b6d6dSopenharmony_ciis uncommon, and .java resource bundle files are therefore usually encoded in 772e5b6d6dSopenharmony_ciISO 8859-1 with \u escapes like .properties files. 782e5b6d6dSopenharmony_ci 792e5b6d6dSopenharmony_ciDefined at: http://java.sun.com/j2se/1.4/docs/api/java/util/ListResourceBundle.html 802e5b6d6dSopenharmony_ci 812e5b6d6dSopenharmony_ciExample: (`example_de.java`) 822e5b6d6dSopenharmony_ci 832e5b6d6dSopenharmony_ci```java 842e5b6d6dSopenharmony_cipublic class example_de extends ListResourceBundle { 852e5b6d6dSopenharmony_ci public Object[][] getContents() { 862e5b6d6dSopenharmony_ci return contents; 872e5b6d6dSopenharmony_ci } 882e5b6d6dSopenharmony_ci static final Object[][] contents={ 892e5b6d6dSopenharmony_ci { "key1", "Deutsche Sprache " + 902e5b6d6dSopenharmony_ci "schwere Sprache" }, 912e5b6d6dSopenharmony_ci { "key2", "Düsseldorf" } 922e5b6d6dSopenharmony_ci }; 932e5b6d6dSopenharmony_ci} 942e5b6d6dSopenharmony_ci``` 952e5b6d6dSopenharmony_ci 962e5b6d6dSopenharmony_ciICU4J can also access the ICU4C resource bundles described in the next section, 972e5b6d6dSopenharmony_ciusing the API described in the [UResourceBundle](https://unicode-org.github.io/icu-docs/apidoc/released/icu4j/com/ibm/icu/util/UResourceBundle.html) documentation. 982e5b6d6dSopenharmony_ci 992e5b6d6dSopenharmony_ci## ICU4C 1002e5b6d6dSopenharmony_ci 1012e5b6d6dSopenharmony_ci### .txt resource bundles 1022e5b6d6dSopenharmony_ci 1032e5b6d6dSopenharmony_ciICU4C natively uses a plain text source format with a nested structure that was 1042e5b6d6dSopenharmony_ciderived from Java `ListResourceBundle` .java files when the original ICU Java 1052e5b6d6dSopenharmony_ciclass files were ported to C++. The ICU4C bundle format can of course contain 1062e5b6d6dSopenharmony_cionly data, not code, unlike .java files. Resource bundle source files are 1072e5b6d6dSopenharmony_cicompiled with the `genrb` tool into a binary runtime form (`.res` files) that is 1082e5b6d6dSopenharmony_ciportable among platforms with the same charset family (ASCII vs. EBCDIC) and 1092e5b6d6dSopenharmony_ciendianness. 1102e5b6d6dSopenharmony_ci 1112e5b6d6dSopenharmony_ciFeatures: 1122e5b6d6dSopenharmony_ci 1132e5b6d6dSopenharmony_ci1. Key-value pairs. Keys are strings of "invariant characters" - a portable subset of the ASCII graphic character repertoire. About "invariant characters" see the definition of the .txt file format (URL below) or [icu/source/common/unicode/utypes.h](https://unicode-org.github.io/icu-docs/apidoc/released/icu4c/utypes_8h.html) 1142e5b6d6dSopenharmony_ci 1152e5b6d6dSopenharmony_ci2. Values can be Unicode strings, integers, binaries (BLOBs), integer array (vectors), and nested structures. Nested structures are either arrays (position-indexed vectors) of values or "tables" of key-value pairs. 1162e5b6d6dSopenharmony_ci 1172e5b6d6dSopenharmony_ci3. Values inside nested structures can be all of the ones as on the top level, arbitrarily deeply nested via arrays and tables. 1182e5b6d6dSopenharmony_ci 1192e5b6d6dSopenharmony_ci4. Long strings can be split across lines: Adjacent strings separated only by whitespace including line breaks) are automatically concatenated at build time. 1202e5b6d6dSopenharmony_ci 1212e5b6d6dSopenharmony_ci5. At runtime, when a top-level item is not found, then ICU looks up the same key in the parent bundle as determined by the locale ID. 1222e5b6d6dSopenharmony_ci 1232e5b6d6dSopenharmony_ci6. A value can also be an "alias", which is simply a reference to another bundle's item. This is to save space by storing large data pieces only once when they cannot be inherited along the locale ID hierarchy (e.g., collation data in ICU shared among zh_HK and zh_TW). 1242e5b6d6dSopenharmony_ci 1252e5b6d6dSopenharmony_ci7. Source files can be in any charset. Unicode signature byte sequences are recognized automatically (UTF-8/16, SCSU, ...), otherwise the tool takes a charset name on the command line. 1262e5b6d6dSopenharmony_ci 1272e5b6d6dSopenharmony_ciDefined at: [icu-docs/main/design/bnf_rb.txt](https://raw.githubusercontent.com/unicode-org/icu-docs/main/design/bnf_rb.txt) 1282e5b6d6dSopenharmony_ci 1292e5b6d6dSopenharmony_ciTo use with ICU4C, see the [Resource Bundle APIs](resources#resource-bundle-apis) section of this userguide. 1302e5b6d6dSopenharmony_ci 1312e5b6d6dSopenharmony_ciExample: (`de.txt`) 1322e5b6d6dSopenharmony_ci 1332e5b6d6dSopenharmony_ci``` 1342e5b6d6dSopenharmony_cide { 1352e5b6d6dSopenharmony_ci key1 { "Deutsche Sprache " 1362e5b6d6dSopenharmony_ci "schwere Sprache" } 1372e5b6d6dSopenharmony_ci key2 { "Düsseldorf" } 1382e5b6d6dSopenharmony_ci} 1392e5b6d6dSopenharmony_ci``` 1402e5b6d6dSopenharmony_ci 1412e5b6d6dSopenharmony_ci### ICU4C XML resource bundles 1422e5b6d6dSopenharmony_ci 1432e5b6d6dSopenharmony_ciThe ICU4C XML resource bundle format was defined simply to express the same 1442e5b6d6dSopenharmony_cicapabilities of the .txt and binary ICU4C resource bundles in XML form. However, 1452e5b6d6dSopenharmony_ciwe have decided to drop the format for lack of use and instead adopt standard 1462e5b6d6dSopenharmony_ciXLIFF format for localization. For more information on XLIFF format, see the 1472e5b6d6dSopenharmony_cifollowing section. For examples on using ICU tools to produce and read XLIFF 1482e5b6d6dSopenharmony_ciformat see the XLIFF Usage section in the [resource management chapter](resources#using-xliff-for-localization). 1492e5b6d6dSopenharmony_ci 1502e5b6d6dSopenharmony_ci## XLIFF 1512e5b6d6dSopenharmony_ci 1522e5b6d6dSopenharmony_ciThe XML Localization Interchange File Format (XLIFF) is an emerging industry 1532e5b6d6dSopenharmony_cistandard "for the interchange of localization information". Version 1.1 is 1542e5b6d6dSopenharmony_ciavailable (2003-Oct-31), and 1.2 is almost complete (2007-Jan-20). 1552e5b6d6dSopenharmony_ci 1562e5b6d6dSopenharmony_ciThis is the result of a quick review of XLIFF and may need to be improved. 1572e5b6d6dSopenharmony_ci 1582e5b6d6dSopenharmony_ciFeatures: 1592e5b6d6dSopenharmony_ci 1602e5b6d6dSopenharmony_ci1. Multiple resource bundles per XLIFF file are supported. 1612e5b6d6dSopenharmony_ci 1622e5b6d6dSopenharmony_ci2. Multiple languages per XLIFF file are supported. 1632e5b6d6dSopenharmony_ci 1642e5b6d6dSopenharmony_ci3. XLIFF provides a rich set of ways to communicate intent, types of items, 1652e5b6d6dSopenharmony_ci etc. all the way from content creation to all stages and phases of 1662e5b6d6dSopenharmony_ci translation. 1672e5b6d6dSopenharmony_ci 1682e5b6d6dSopenharmony_ci4. Nesting of values appears to not be supported. 1692e5b6d6dSopenharmony_ci 1702e5b6d6dSopenharmony_ci5. XLIFF is independent of actual build-time or runtime resource bundle 1712e5b6d6dSopenharmony_ci formats. .xlf files must be converted to native formats at build time. 1722e5b6d6dSopenharmony_ci 1732e5b6d6dSopenharmony_ciDefined at: http://www.oasis-open.org/committees/xliff/ 1742e5b6d6dSopenharmony_ci 1752e5b6d6dSopenharmony_ciExample: (`example.xlf`) 1762e5b6d6dSopenharmony_ci 1772e5b6d6dSopenharmony_ci```xml 1782e5b6d6dSopenharmony_ci<<?xml version="1.0" encoding="utf-8"?> 1792e5b6d6dSopenharmony_ci<xliff version = "1.1" xmlns='urn:oasis:names:tc:xliff:document:1.1' 1802e5b6d6dSopenharmony_cixmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' 1812e5b6d6dSopenharmony_cixsi:schemaLocation='urn:oasis:names:tc:xliff:document:1.1 1822e5b6d6dSopenharmony_cihttp://www.oasis-open.org/committees/xliff/documents/xliff-core-1.1.xsd'> 1832e5b6d6dSopenharmony_ci <file xml:space = "preserve" source-language = "en" target-language = "sh" 1842e5b6d6dSopenharmony_ci datatype = "x-icu-resource-bundle" original = "root.txt" 1852e5b6d6dSopenharmony_ci date = "2007-08-17T21:17:08Z"> 1862e5b6d6dSopenharmony_ci <header> 1872e5b6d6dSopenharmony_ci <tool tool-id = "genrb-3.3-icu-3.8" tool-name = "genrb"/> 1882e5b6d6dSopenharmony_ci </header> 1892e5b6d6dSopenharmony_ci <body> 1902e5b6d6dSopenharmony_ci <group id = "root" restype = "x-icu-table"> 1912e5b6d6dSopenharmony_ci <trans-unit id = "optionMessage" resname = "optionMessage"> 1922e5b6d6dSopenharmony_ci <source>unrecognized command line option:</source> 1932e5b6d6dSopenharmony_ci <target>nepoznata opcija na komandnoj liniji:</target> 1942e5b6d6dSopenharmony_ci </trans-unit> 1952e5b6d6dSopenharmony_ci <trans-unit id = "usage" resname = "usage"> 1962e5b6d6dSopenharmony_ci <source>usage: ufortune [-v] [-l locale]</source> 1972e5b6d6dSopenharmony_ci <target>upotreba: ufortune [-v] [-l lokal]</target> 1982e5b6d6dSopenharmony_ci </trans-unit> 1992e5b6d6dSopenharmony_ci </group> 2002e5b6d6dSopenharmony_ci </body> 2012e5b6d6dSopenharmony_ci </file> 2022e5b6d6dSopenharmony_ci</xliff> 2032e5b6d6dSopenharmony_ci``` 2042e5b6d6dSopenharmony_ci 2052e5b6d6dSopenharmony_ciFor examples on using ICU tools to produce and read XLIFF format see the XLIFF 2062e5b6d6dSopenharmony_ciUsage (§) section in the [resource management chapter](resources#using-xliff-for-localization). 2072e5b6d6dSopenharmony_ci 2082e5b6d6dSopenharmony_ci## DITA 2092e5b6d6dSopenharmony_ci 2102e5b6d6dSopenharmony_ciThe Darwin Information Typing Architecture (DITA) is "IBM's XML architecture for 2112e5b6d6dSopenharmony_citopic-oriented information". It is a family of XML formats for several types of 2122e5b6d6dSopenharmony_cipublications including manuals and resource bundles. It is extensible. For 2132e5b6d6dSopenharmony_ciexample, subformats can be defined by refining DTDs. One design feature is to 2142e5b6d6dSopenharmony_ciprovide cross-document references for reuse of existing contents. For more 2152e5b6d6dSopenharmony_ciinformation see http://www.ibm.com/developerworks/xml/library/x-dita4/index.html 2162e5b6d6dSopenharmony_ci 2172e5b6d6dSopenharmony_ciWhile it is certainly possible to define resource bundle formats via DTDs in the 2182e5b6d6dSopenharmony_ciDITA framework, there currently (2002-Nov-27) do not appear to be resource 2192e5b6d6dSopenharmony_cibundle formats actually defined, or tools available specifically for them. 2202e5b6d6dSopenharmony_ci 2212e5b6d6dSopenharmony_ci## Linux/gettext 2222e5b6d6dSopenharmony_ci 2232e5b6d6dSopenharmony_ciThe OpenI18N specification requires support for message handling functions 2242e5b6d6dSopenharmony_ci(mostly variants of `gettext()`) as defined in `libintl.h`. See Tables 3-5 and 3-6 2252e5b6d6dSopenharmony_ciand Annex C in http://www.openi18n.org/docs/html/LI18NUX-2000-amd4.htm 2262e5b6d6dSopenharmony_ci 2272e5b6d6dSopenharmony_ciResource bundles ("portable object files", extension .po) are plain text files 2282e5b6d6dSopenharmony_ciwith key-value pairs for string values. The format and functions support a 2292e5b6d6dSopenharmony_cisimple selection of plural forms by associating integer values (via C language 2302e5b6d6dSopenharmony_ciexpressions) with indexes of strings. 2312e5b6d6dSopenharmony_ci 2322e5b6d6dSopenharmony_ciThe `msgfmt` utility compiles .po files into "message object files" (extension 2332e5b6d6dSopenharmony_ci.mo). The charset is determined from the locale ID in `LC_CTYPE`. There are 2342e5b6d6dSopenharmony_ciadditional supporting tools for .po files. 2352e5b6d6dSopenharmony_ci 2362e5b6d6dSopenharmony_ci*Note: The OpenI18N specification also requires POSIX `gencat`/`catgets` support. See the [POSIX](#posixcatsgets) (§) section below.* 2372e5b6d6dSopenharmony_ci 2382e5b6d6dSopenharmony_ciDefined at: Annex C of the Li18nux-2000 specification, see above. 2392e5b6d6dSopenharmony_ci 2402e5b6d6dSopenharmony_ciExample: (`example.po`) 2412e5b6d6dSopenharmony_ci 2422e5b6d6dSopenharmony_ci``` 2432e5b6d6dSopenharmony_cidomain "example_domain" 2442e5b6d6dSopenharmony_cimsgid "key1" 2452e5b6d6dSopenharmony_cimsgstr "Deutsche Sprache schwere Sprache" 2462e5b6d6dSopenharmony_cimsgid "key2" 2472e5b6d6dSopenharmony_cimsgstr "Düsseldorf" 2482e5b6d6dSopenharmony_ci``` 2492e5b6d6dSopenharmony_ci 2502e5b6d6dSopenharmony_ci## POSIX/catgets 2512e5b6d6dSopenharmony_ci 2522e5b6d6dSopenharmony_ciPOSIX (The Open Group specification) defines message catalogs with the `catgets()` 2532e5b6d6dSopenharmony_ciC function and the gencat build-time tool. Message catalogs contain key-value 2542e5b6d6dSopenharmony_cipairs where the keys are integers `1`..`NL_MSGMAX` (see `limits.h`), and the values 2552e5b6d6dSopenharmony_ciare strings. Strings can span multiple lines. The charset is determined from the 2562e5b6d6dSopenharmony_cilocale ID in `LC_CTYPE`. 2572e5b6d6dSopenharmony_ci 2582e5b6d6dSopenharmony_ciDefined at: 2592e5b6d6dSopenharmony_cihttps://pubs.opengroup.org/onlinepubs/009695399/utilities/gencat.html and 2602e5b6d6dSopenharmony_cihttps://pubs.opengroup.org/onlinepubs/009695399/functions/catgets.html 2612e5b6d6dSopenharmony_ci 2622e5b6d6dSopenharmony_ciExample: (`example.txt`) 2632e5b6d6dSopenharmony_ci 2642e5b6d6dSopenharmony_ci``` 2652e5b6d6dSopenharmony_ci1 Deutsche Sprache \ 2662e5b6d6dSopenharmony_cischwere Sprache 2672e5b6d6dSopenharmony_ci2 Düsseldorf 2682e5b6d6dSopenharmony_ci``` 2692e5b6d6dSopenharmony_ci 2702e5b6d6dSopenharmony_ci## Windows 2712e5b6d6dSopenharmony_ci 2722e5b6d6dSopenharmony_ciWindows uses a number of file formats depending on the language environment -- 2732e5b6d6dSopenharmony_ciMSVC 6, Visual Basic, or Visual Studio .NET. The most well-known source formats 2742e5b6d6dSopenharmony_ciare the [.rc Resource](https://docs.microsoft.com/windows/win32/menurc/about-resource-files) 2752e5b6d6dSopenharmony_ciand [.mc Message](https://docs.microsoft.com/en-us/windows/win32/eventlog/message-files) 2762e5b6d6dSopenharmony_cifile formats. They both get compiled into .res files that are linked into 2772e5b6d6dSopenharmony_cispecial sections of executables. Source formats can be UTF-16, while compiled 2782e5b6d6dSopenharmony_cistrings are (almost) always UTF-16 from .rc files (except for predefined 2792e5b6d6dSopenharmony_ciComboBox strings) and can optionally be UTF-16 from .mc files. 2802e5b6d6dSopenharmony_ci 2812e5b6d6dSopenharmony_ci.rc files carry key-value pairs where the keys are usually numeric but can be 2822e5b6d6dSopenharmony_cistrings. Values can be strings, string tables, or one of many Windows 2832e5b6d6dSopenharmony_ciGUI-specific structured types that compile directly into binary formats that the 2842e5b6d6dSopenharmony_ciGUI system interprets at runtime. .rc files can include C #include files for 2852e5b6d6dSopenharmony_ci#defined numeric keys. .mc files contain string values preceded by per-message 2862e5b6d6dSopenharmony_ciheaders similar to the Linux/gettext() format. There is a special format of 2872e5b6d6dSopenharmony_cimessages with positional arguments, with printf-style formatting per argument. 2882e5b6d6dSopenharmony_ciIn both .rc and .mc formats, Windows LCID values are defined to be set on the 2892e5b6d6dSopenharmony_cicompiled resources. 2902e5b6d6dSopenharmony_ci 2912e5b6d6dSopenharmony_ciDevelopers and translators usually overlook the fact that binary resources are 2922e5b6d6dSopenharmony_ciincluded, and include them into each translation. This despite Windows, like 2932e5b6d6dSopenharmony_ciJava and ICU, using locale ID fallback at runtime. 2942e5b6d6dSopenharmony_ci 2952e5b6d6dSopenharmony_ci.rc and .mc files are tightly integrated with Microsoft C/C++, Visual Studio and 2962e5b6d6dSopenharmony_cithe Windows platform, but are not used on any other platforms. 2972e5b6d6dSopenharmony_ci 2982e5b6d6dSopenharmony_ciA [sample Windows .rc file](#sample-windows-rc-file) (§) is at the end of this document. 2992e5b6d6dSopenharmony_ci 3002e5b6d6dSopenharmony_ci## ICU tools 3012e5b6d6dSopenharmony_ci 3022e5b6d6dSopenharmony_ciICU 2.4 provides tools for conversion between resource bundle formats: 3032e5b6d6dSopenharmony_ci 3042e5b6d6dSopenharmony_ci1. ICU4C .txt -> ICU4C .res: Default operation of genrb (ICU 2.0 and before). 3052e5b6d6dSopenharmony_ci 3062e5b6d6dSopenharmony_ci2. ICU4C .txt -> ICU4C .xml: Option with genrb (ICU 2.4). 3072e5b6d6dSopenharmony_ci 3082e5b6d6dSopenharmony_ci3. ICU4C .txt -> Java ListResourceBundle .java format: Option with genrb (ICU 3092e5b6d6dSopenharmony_ci 2.2). 3102e5b6d6dSopenharmony_ci Generates subclasses of ICUListResourceBundle to support non-string types. 3112e5b6d6dSopenharmony_ci 3122e5b6d6dSopenharmony_ci4. Java ListResourceBundle .java format -> ICU4C .txt: Use ICU4J 2.4's 3132e5b6d6dSopenharmony_ci src/com/ibm/icu/dev/tools/localeconverter 3142e5b6d6dSopenharmony_ci 3152e5b6d6dSopenharmony_ci5. ICU4C .xml -> ICU4C .txt: There is a tool for this conversion, but it is not 3162e5b6d6dSopenharmony_ci fully tested or documented. Please see the 3172e5b6d6dSopenharmony_ci [XLIFF2ICUConverter](https://icu-project.org/download/xliff2icuconverter.html) 3182e5b6d6dSopenharmony_ci tool. 3192e5b6d6dSopenharmony_ci 3202e5b6d6dSopenharmony_ciThere are currently no ICU tools for XLIFF. 3212e5b6d6dSopenharmony_ci 3222e5b6d6dSopenharmony_ci### Converting de.txt to a ListResourceBundle 3232e5b6d6dSopenharmony_ci 3242e5b6d6dSopenharmony_ciThe following genrb invocation generates a ListResourceBundle from `de.txt` (see 3252e5b6d6dSopenharmony_cithe example file `de.txt` above): 3262e5b6d6dSopenharmony_ci 3272e5b6d6dSopenharmony_ci`genrb -j -b TestName -p com.example de.txt` 3282e5b6d6dSopenharmony_ci 3292e5b6d6dSopenharmony_ciThe -j option causes .java output, -b is an arbitrary bundle name prefix, and -p 3302e5b6d6dSopenharmony_ciis an arbitrary package name. "Arbitrary" means "depends on your product" and 3312e5b6d6dSopenharmony_cimay be truly arbitrary if the generated .java files are not actually used in a 3322e5b6d6dSopenharmony_ciJava application. genrb auto-detects .txt files encoded in Unicode charsets like 3332e5b6d6dSopenharmony_ciUTF-8 or UTF-16 if they have a signature byte sequence ("BOM"). The .java output 3342e5b6d6dSopenharmony_cifile is in native2ascii format, i.e., it is encoded in US-ASCII with \u 3352e5b6d6dSopenharmony_ciescapes. 3362e5b6d6dSopenharmony_ci 3372e5b6d6dSopenharmony_ciThe output of the above genrb invocation is `TestName_de.java`: 3382e5b6d6dSopenharmony_ci 3392e5b6d6dSopenharmony_ci```java 3402e5b6d6dSopenharmony_cipackage com.example; 3412e5b6d6dSopenharmony_ciimport java.util.ListResourceBundle; 3422e5b6d6dSopenharmony_ciimport com.ibm.icu.impl.ICUListResourceBundle; 3432e5b6d6dSopenharmony_cipublic class TestName_de extends ICUListResourceBundle { 3442e5b6d6dSopenharmony_ci public TestName_de () { 3452e5b6d6dSopenharmony_ci super.contents = data; 3462e5b6d6dSopenharmony_ci } 3472e5b6d6dSopenharmony_ci static final Object[][] data = new Object[][] { 3482e5b6d6dSopenharmony_ci { 3492e5b6d6dSopenharmony_ci "key1", 3502e5b6d6dSopenharmony_ci "Deutsche Sprache schwere Sprache", 3512e5b6d6dSopenharmony_ci }, 3522e5b6d6dSopenharmony_ci { 3532e5b6d6dSopenharmony_ci "key2", 3542e5b6d6dSopenharmony_ci "D\u00FCsseldorf", 3552e5b6d6dSopenharmony_ci }, 3562e5b6d6dSopenharmony_ci }; 3572e5b6d6dSopenharmony_ci} 3582e5b6d6dSopenharmony_ci``` 3592e5b6d6dSopenharmony_ci 3602e5b6d6dSopenharmony_ci### Converting a ListResourceBundle back to .txt 3612e5b6d6dSopenharmony_ci 3622e5b6d6dSopenharmony_ciAn ICUListResourceBundle .java file as generated in the previous example can be 3632e5b6d6dSopenharmony_ciconverted to an ICU4C .txt file with the following steps: 3642e5b6d6dSopenharmony_ci 3652e5b6d6dSopenharmony_ci1. Compile the .java file, e.g. with `javac -d . TestName_de.java`. ICU4J needs 3662e5b6d6dSopenharmony_ci to be on the classpath (or use the -classpath option). If the .java file is 3672e5b6d6dSopenharmony_ci not in `native2ascii` format, then use the -encoding option (e.g. -encoding 3682e5b6d6dSopenharmony_ci UTF-8). The -d option (specifying an output directory, in this example the 3692e5b6d6dSopenharmony_ci current folder) is required. Without it, the Java compiler would not 3702e5b6d6dSopenharmony_ci generate the com/example folder hierarchy that is required in the next step. 3712e5b6d6dSopenharmony_ci 3722e5b6d6dSopenharmony_ci2. You now have a .class file `com/example/TestName_de.class`. 3732e5b6d6dSopenharmony_ci 3742e5b6d6dSopenharmony_ci3. Invoke the ICU4J locale converter tool to generate ICU4C .txt format output for 3752e5b6d6dSopenharmony_ci this .class file: 3762e5b6d6dSopenharmony_ci 3772e5b6d6dSopenharmony_ci `java -cp ;(folder to ICU4J)/icu4j.jar;(working folder for the previous steps); com.ibm.icu.dev.tool.localeconverter.ConvertICUListResourceBundle -icu -package com.example -bundle-name TestName de > de.txt` 3782e5b6d6dSopenharmony_ci 3792e5b6d6dSopenharmony_ci Note that the classpath must include the working folder for the previous 3802e5b6d6dSopenharmony_ci steps (the folder that contains "com"). The package name (com.example), 3812e5b6d6dSopenharmony_ci bundle name (TestName) and locale ID (de) must match the .java/.class files. 3822e5b6d6dSopenharmony_ci Note also that the locale converter writes to the standard output; the 3832e5b6d6dSopenharmony_ci command line above includes a redirection to de.txt. 3842e5b6d6dSopenharmony_ci 3852e5b6d6dSopenharmony_ciThe last step generates a new de.txt in `native2ascii` format: 3862e5b6d6dSopenharmony_ci 3872e5b6d6dSopenharmony_ci``` 3882e5b6d6dSopenharmony_cide { 3892e5b6d6dSopenharmony_ci key2{"D\u00FCsseldorf"} 3902e5b6d6dSopenharmony_ci key1{"Deutsche Sprache schwere Sprache"} 3912e5b6d6dSopenharmony_ci} 3922e5b6d6dSopenharmony_ci``` 3932e5b6d6dSopenharmony_ci 3942e5b6d6dSopenharmony_ci## Further information 3952e5b6d6dSopenharmony_ci 3962e5b6d6dSopenharmony_ci1. TMX: "The purpose of TMX is to allow easier exchange of translation memory 3972e5b6d6dSopenharmony_ci data between tools and/or translation vendors with little or no loss of 3982e5b6d6dSopenharmony_ci critical data during the process." 3992e5b6d6dSopenharmony_ci http://www.lisa.org/tmx/ 4002e5b6d6dSopenharmony_ci 4012e5b6d6dSopenharmony_ci2. LISA: Localisation Industry Standards Association 4022e5b6d6dSopenharmony_ci http://www.lisa.org/ 4032e5b6d6dSopenharmony_ci 4042e5b6d6dSopenharmony_ci## Sample Windows .rc file 4052e5b6d6dSopenharmony_ci 4062e5b6d6dSopenharmony_ciThis file (`winrc.rc`) was generated with MSVC 6, using the New Project wizard to 4072e5b6d6dSopenharmony_cigenerate a simple "Hello World!" application, changing the LCIDs to German, then 4082e5b6d6dSopenharmony_ciadding the two example strings as above. 4092e5b6d6dSopenharmony_ci 4102e5b6d6dSopenharmony_ci``` 4112e5b6d6dSopenharmony_ci//Microsoft Developer Studio generated resource script. 4122e5b6d6dSopenharmony_ci// 4132e5b6d6dSopenharmony_ci#include "resource.h" 4142e5b6d6dSopenharmony_ci#define APSTUDIO_READONLY_SYMBOLS 4152e5b6d6dSopenharmony_ci///////////////////////////////////////////////////////////////////////////// 4162e5b6d6dSopenharmony_ci// 4172e5b6d6dSopenharmony_ci// Generated from the TEXTINCLUDE 2 resource. 4182e5b6d6dSopenharmony_ci// 4192e5b6d6dSopenharmony_ci#define APSTUDIO_HIDDEN_SYMBOLS 4202e5b6d6dSopenharmony_ci#include "windows.h" 4212e5b6d6dSopenharmony_ci#undef APSTUDIO_HIDDEN_SYMBOLS 4222e5b6d6dSopenharmony_ci#include "resource.h" 4232e5b6d6dSopenharmony_ci///////////////////////////////////////////////////////////////////////////// 4242e5b6d6dSopenharmony_ci#undef APSTUDIO_READONLY_SYMBOLS 4252e5b6d6dSopenharmony_ci///////////////////////////////////////////////////////////////////////////// 4262e5b6d6dSopenharmony_ci// German (Germany) resources 4272e5b6d6dSopenharmony_ci#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_DEU) 4282e5b6d6dSopenharmony_ci#ifdef _WIN32 4292e5b6d6dSopenharmony_ciLANGUAGE LANG_GERMAN, SUBLANG_GERMAN 4302e5b6d6dSopenharmony_ci#pragma code_page(1252) 4312e5b6d6dSopenharmony_ci#endif //_WIN32 4322e5b6d6dSopenharmony_ci///////////////////////////////////////////////////////////////////////////// 4332e5b6d6dSopenharmony_ci// 4342e5b6d6dSopenharmony_ci// Icon 4352e5b6d6dSopenharmony_ci// 4362e5b6d6dSopenharmony_ci// Icon with lowest ID value placed first to ensure application icon 4372e5b6d6dSopenharmony_ci// remains consistent on all systems. 4382e5b6d6dSopenharmony_ciIDI_WINRC ICON DISCARDABLE "winrc.ICO" 4392e5b6d6dSopenharmony_ciIDI_SMALL ICON DISCARDABLE "SMALL.ICO" 4402e5b6d6dSopenharmony_ci///////////////////////////////////////////////////////////////////////////// 4412e5b6d6dSopenharmony_ci// 4422e5b6d6dSopenharmony_ci// Menu 4432e5b6d6dSopenharmony_ci// 4442e5b6d6dSopenharmony_ciIDC_WINRC MENU DISCARDABLE 4452e5b6d6dSopenharmony_ciBEGIN 4462e5b6d6dSopenharmony_ci POPUP "&File" 4472e5b6d6dSopenharmony_ci BEGIN 4482e5b6d6dSopenharmony_ci MENUITEM "E&xit", IDM_EXIT 4492e5b6d6dSopenharmony_ci END 4502e5b6d6dSopenharmony_ci POPUP "&Help" 4512e5b6d6dSopenharmony_ci BEGIN 4522e5b6d6dSopenharmony_ci MENUITEM "&About ...", IDM_ABOUT 4532e5b6d6dSopenharmony_ci END 4542e5b6d6dSopenharmony_ciEND 4552e5b6d6dSopenharmony_ci///////////////////////////////////////////////////////////////////////////// 4562e5b6d6dSopenharmony_ci// 4572e5b6d6dSopenharmony_ci// Accelerator 4582e5b6d6dSopenharmony_ci// 4592e5b6d6dSopenharmony_ciIDC_WINRC ACCELERATORS MOVEABLE PURE 4602e5b6d6dSopenharmony_ciBEGIN 4612e5b6d6dSopenharmony_ci "?", IDM_ABOUT, ASCII, ALT 4622e5b6d6dSopenharmony_ci "/", IDM_ABOUT, ASCII, ALT 4632e5b6d6dSopenharmony_ciEND 4642e5b6d6dSopenharmony_ci///////////////////////////////////////////////////////////////////////////// 4652e5b6d6dSopenharmony_ci// 4662e5b6d6dSopenharmony_ci// Dialog 4672e5b6d6dSopenharmony_ci// 4682e5b6d6dSopenharmony_ciIDD_ABOUTBOX DIALOG DISCARDABLE 22, 17, 230, 75 4692e5b6d6dSopenharmony_ciSTYLE DS_MODALFRAME | WS_CAPTION | WS_SYSMENU 4702e5b6d6dSopenharmony_ciCAPTION "About" 4712e5b6d6dSopenharmony_ciFONT 8, "System" 4722e5b6d6dSopenharmony_ciBEGIN 4732e5b6d6dSopenharmony_ci ICON IDI_WINRC,IDC_MYICON,14,9,16,16 4742e5b6d6dSopenharmony_ci LTEXT "winrc Version 1.0",IDC_STATIC,49,10,119,8,SS_NOPREFIX 4752e5b6d6dSopenharmony_ci LTEXT "Copyright (C) 2002",IDC_STATIC,49,20,119,8 4762e5b6d6dSopenharmony_ci DEFPUSHBUTTON "OK",IDOK,195,6,30,11,WS_GROUP 4772e5b6d6dSopenharmony_ciEND 4782e5b6d6dSopenharmony_ci///////////////////////////////////////////////////////////////////////////// 4792e5b6d6dSopenharmony_ci// 4802e5b6d6dSopenharmony_ci// String Table 4812e5b6d6dSopenharmony_ci// 4822e5b6d6dSopenharmony_ciSTRINGTABLE DISCARDABLE 4832e5b6d6dSopenharmony_ciBEGIN 4842e5b6d6dSopenharmony_ciIDS_APP_TITLE "winrc" 4852e5b6d6dSopenharmony_ciIDS_HELLO "Hello World!" 4862e5b6d6dSopenharmony_ciIDC_WINRC "WINRC" 4872e5b6d6dSopenharmony_ciIDS_SENTENCE "Deutsche Sprache schwere Sprache" 4882e5b6d6dSopenharmony_ciIDS_CITY "Düsseldorf" 4892e5b6d6dSopenharmony_ciEND 4902e5b6d6dSopenharmony_ci#endif // German (Germany) resources 4912e5b6d6dSopenharmony_ci///////////////////////////////////////////////////////////////////////////// 4922e5b6d6dSopenharmony_ci///////////////////////////////////////////////////////////////////////////// 4932e5b6d6dSopenharmony_ci// English (U.S.) resources 4942e5b6d6dSopenharmony_ci#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) 4952e5b6d6dSopenharmony_ci#ifdef _WIN32 4962e5b6d6dSopenharmony_ciLANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US 4972e5b6d6dSopenharmony_ci#pragma code_page(1252) 4982e5b6d6dSopenharmony_ci#endif //_WIN32 4992e5b6d6dSopenharmony_ci#ifdef APSTUDIO_INVOKED 5002e5b6d6dSopenharmony_ci///////////////////////////////////////////////////////////////////////////// 5012e5b6d6dSopenharmony_ci// 5022e5b6d6dSopenharmony_ci// TEXTINCLUDE 5032e5b6d6dSopenharmony_ci// 5042e5b6d6dSopenharmony_ci2 TEXTINCLUDE DISCARDABLE 5052e5b6d6dSopenharmony_ciBEGIN 5062e5b6d6dSopenharmony_ci "#define APSTUDIO_HIDDEN_SYMBOLS\r\n" 5072e5b6d6dSopenharmony_ci "#include ""windows.h""\r\n" 5082e5b6d6dSopenharmony_ci "#undef APSTUDIO_HIDDEN_SYMBOLS\r\n" 5092e5b6d6dSopenharmony_ci "#include ""resource.h""\r\n" 5102e5b6d6dSopenharmony_ci "\0" 5112e5b6d6dSopenharmony_ciEND 5122e5b6d6dSopenharmony_ci3 TEXTINCLUDE DISCARDABLE 5132e5b6d6dSopenharmony_ciBEGIN 5142e5b6d6dSopenharmony_ci "\r\n" 5152e5b6d6dSopenharmony_ci "\0" 5162e5b6d6dSopenharmony_ciEND 5172e5b6d6dSopenharmony_ci1 TEXTINCLUDE DISCARDABLE 5182e5b6d6dSopenharmony_ciBEGIN 5192e5b6d6dSopenharmony_ci "resource.h\0" 5202e5b6d6dSopenharmony_ciEND 5212e5b6d6dSopenharmony_ci#endif // APSTUDIO_INVOKED 5222e5b6d6dSopenharmony_ci#endif // English (U.S.) resources 5232e5b6d6dSopenharmony_ci///////////////////////////////////////////////////////////////////////////// 5242e5b6d6dSopenharmony_ci#ifndef APSTUDIO_INVOKED 5252e5b6d6dSopenharmony_ci///////////////////////////////////////////////////////////////////////////// 5262e5b6d6dSopenharmony_ci// 5272e5b6d6dSopenharmony_ci// Generated from the TEXTINCLUDE 3 resource. 5282e5b6d6dSopenharmony_ci// 5292e5b6d6dSopenharmony_ci///////////////////////////////////////////////////////////////////////////// 5302e5b6d6dSopenharmony_ci#endif // not APSTUDIO_INVOKED 5312e5b6d6dSopenharmony_ci```