12e5b6d6dSopenharmony_ci--- 22e5b6d6dSopenharmony_cilayout: default 32e5b6d6dSopenharmony_cititle: Resources 42e5b6d6dSopenharmony_cinav_order: 2 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# Resource Management 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_ci> :point_right: **Note**: This page describes the use of ICU4C Resource 262e5b6d6dSopenharmony_ci> Management techniques and APIs. For an overview of the message localization 272e5b6d6dSopenharmony_ci> process using ICU, see the related page [Localizing with ICU](localizing.md). 282e5b6d6dSopenharmony_ci 292e5b6d6dSopenharmony_ciA software product that needs to be localized wins or loses depending on how 302e5b6d6dSopenharmony_cieasy is to change the data or "resources" which affect users. From the simplest 312e5b6d6dSopenharmony_cipoint of view, that data is the information presented to the user (such as a 322e5b6d6dSopenharmony_citranslated message) as well as the region-specific ways of doing things (such as 332e5b6d6dSopenharmony_cisorting). The process of localization will eventually involve translators and it 342e5b6d6dSopenharmony_ciwould be very convenient if the process of localizing could be done only by 352e5b6d6dSopenharmony_citranslators and experts in the target culture. There are several points to keep 362e5b6d6dSopenharmony_ciin mind when designing such a localizable software product. 372e5b6d6dSopenharmony_ci 382e5b6d6dSopenharmony_ci### Keeping Data Separate 392e5b6d6dSopenharmony_ci 402e5b6d6dSopenharmony_ciObviously, one does not want to make translators wade through the source code 412e5b6d6dSopenharmony_ciand make changes there. That would be a recipe for a disaster. Instead, the 422e5b6d6dSopenharmony_citranslatable data should be kept separately, in a format that allows translators 432e5b6d6dSopenharmony_cieasy access. A separate resource managing mechanism is hence required. 442e5b6d6dSopenharmony_ciApplication access data through API calls, which pick the appropriate entries 452e5b6d6dSopenharmony_cifrom the resources. Resources are kept in human readable/editable format with 462e5b6d6dSopenharmony_cioptional tools for content editing. 472e5b6d6dSopenharmony_ci 482e5b6d6dSopenharmony_ciThe data should contain all the elements to be localized, including, but no 492e5b6d6dSopenharmony_cilimited to, GUI messages, icons, formatting patterns, and collation rules. A 502e5b6d6dSopenharmony_ciconvenient way for keeping binary data should also be provided - often icons for 512e5b6d6dSopenharmony_cidifferent cultures should be different. 522e5b6d6dSopenharmony_ci 532e5b6d6dSopenharmony_ci### Keeping Data Small 542e5b6d6dSopenharmony_ci 552e5b6d6dSopenharmony_ciIt is not unlikely that the data will be same for several regions - take for 562e5b6d6dSopenharmony_ciexample Spanish speaking countries - names of the days and month will be the 572e5b6d6dSopenharmony_cisame in both Mexico and Spain. It would be very beneficial if we can prevent the 582e5b6d6dSopenharmony_ciduplication of data. This can be achieved by structuring resources in such a way 592e5b6d6dSopenharmony_ciso that an unsuccessful query into a more specific resource triggers the same 602e5b6d6dSopenharmony_ciquery in a more general resource. A convenient way to do this is to use a tree 612e5b6d6dSopenharmony_cilike structure. 622e5b6d6dSopenharmony_ci 632e5b6d6dSopenharmony_ciAnother way to reduce the data size is to allow linking of the resources that 642e5b6d6dSopenharmony_ciare same for the regions that are not in general-specific relation. 652e5b6d6dSopenharmony_ci 662e5b6d6dSopenharmony_ci### Find the Best Available Data 672e5b6d6dSopenharmony_ci 682e5b6d6dSopenharmony_ciSometimes, the exact data for a region is still not available. However, if the 692e5b6d6dSopenharmony_cidata is structured correctly, the user can be presented with similar data. For 702e5b6d6dSopenharmony_ciexample, a Spanish speaking user in Mexico would probably be happier with 712e5b6d6dSopenharmony_ciSpanish than with English captions, even if some of the details for Mexico are 722e5b6d6dSopenharmony_cinot there. 732e5b6d6dSopenharmony_ci 742e5b6d6dSopenharmony_ciIf the data is grouped correctly, the program can automatically find the most 752e5b6d6dSopenharmony_cisuitable data for the situation. 762e5b6d6dSopenharmony_ci 772e5b6d6dSopenharmony_ciThe previous points all lead to a separate mechanism that stores data separately 782e5b6d6dSopenharmony_cifrom the code. Software is able to access the data through the API calls. Data 792e5b6d6dSopenharmony_ciis structured in a tree like structure, with the most general region in the root 802e5b6d6dSopenharmony_ci(most commonly, the root region is the native language of the development team). 812e5b6d6dSopenharmony_ciBranches lead to more specialized regions, usually through languages, countries 822e5b6d6dSopenharmony_ciand country regions. Data that is already the same on the more general level is 832e5b6d6dSopenharmony_cinot repeated. 842e5b6d6dSopenharmony_ci 852e5b6d6dSopenharmony_ci> :point_right: **Note**: The path through languages, countries and country 862e5b6d6dSopenharmony_ci> region could be different. One may decide to go through countries and then 872e5b6d6dSopenharmony_ci> through languages spoken in the particular country. In either case, some data 882e5b6d6dSopenharmony_ci> must be duplicated - if you go through languages, the currency data for 892e5b6d6dSopenharmony_ci> different speaking parts of the same country will be duplicated (consider 902e5b6d6dSopenharmony_ci> French and English languages in Canada) - on the other side, when you go 912e5b6d6dSopenharmony_ci> through countries, you will need to duplicate day names and similar 922e5b6d6dSopenharmony_ci> information. 932e5b6d6dSopenharmony_ci 942e5b6d6dSopenharmony_ciHere is an example of a such a resource tree structure: 952e5b6d6dSopenharmony_ci 962e5b6d6dSopenharmony_ci``` 972e5b6d6dSopenharmony_ci root Root 982e5b6d6dSopenharmony_ci | 992e5b6d6dSopenharmony_ci +-------+---+---+----+----+ 1002e5b6d6dSopenharmony_ci | | | | | 1012e5b6d6dSopenharmony_ci en de ja ru zh Language 1022e5b6d6dSopenharmony_ci | | | | | 1032e5b6d6dSopenharmony_ci +---+ +---+ | | +------+ 1042e5b6d6dSopenharmony_ci | | | | | | | | 1052e5b6d6dSopenharmony_ci | | | | | | Hans Hant Script 1062e5b6d6dSopenharmony_ci | | | | | | | | 1072e5b6d6dSopenharmony_ci | | | | | | | +----+ 1082e5b6d6dSopenharmony_ci | | | | | | | | | 1092e5b6d6dSopenharmony_ci US IE DE AT JP RU CN HK TW Country or Region 1102e5b6d6dSopenharmony_ci | 1112e5b6d6dSopenharmony_ci POSIX Variant 1122e5b6d6dSopenharmony_ci``` 1132e5b6d6dSopenharmony_ci 1142e5b6d6dSopenharmony_ciLet us assume that the root resource contains data written by the original 1152e5b6d6dSopenharmony_ciimplementors and that this data is in English and conforms to the conventions 1162e5b6d6dSopenharmony_ciused in the United States. Therefore, resources for English and English in 1172e5b6d6dSopenharmony_ciUnited States would be empty and would take its data from the root resource. If 1182e5b6d6dSopenharmony_cia version for Ireland is required, appropriate overriding changes can be made to 1192e5b6d6dSopenharmony_cithe data for English in Ireland. Special variant information could be put into 1202e5b6d6dSopenharmony_cien_US_POSIX if specific legacy formatting were required, or specific sub-region 1212e5b6d6dSopenharmony_ciinformation were required. When making the version for the German speaking 1222e5b6d6dSopenharmony_ciregion, all the German data would be in that resource, with the differences in 1232e5b6d6dSopenharmony_cithe Germany and Austria resources. 1242e5b6d6dSopenharmony_ci 1252e5b6d6dSopenharmony_ciIt is important to note that some locales have the optional script tag. This is 1262e5b6d6dSopenharmony_ciimportant for multi-script locales, like Uzbek, Azerbaijani, Serbian or Chinese. 1272e5b6d6dSopenharmony_ciEven though Chinese uses Han characters, the characters are usually identified 1282e5b6d6dSopenharmony_cias either traditional Chinese (Hant) characters, or simplified Chinese (Hans). 1292e5b6d6dSopenharmony_ci 1302e5b6d6dSopenharmony_ciEven if all the data that would go to a certain resource comes from the more 1312e5b6d6dSopenharmony_cigeneral resources, it should be made clear that the particular region is 1322e5b6d6dSopenharmony_cisupported by application. This can be done by having completely empty resources. 1332e5b6d6dSopenharmony_ci 1342e5b6d6dSopenharmony_ci## The ICU Model 1352e5b6d6dSopenharmony_ci 1362e5b6d6dSopenharmony_ciICU bases its resource management model on the ideas presented above. All the 1372e5b6d6dSopenharmony_ciresource APIs are concentrated in the resource bundle framework. This framework 1382e5b6d6dSopenharmony_ciis closely tied in its functioning to the ICU [Locale](index.md) naming scheme. 1392e5b6d6dSopenharmony_ci 1402e5b6d6dSopenharmony_ciICU provides and relies on a set of locale specific data in the resource bundle 1412e5b6d6dSopenharmony_ciformat. If we think that we have correct data for a requested locale, even if 1422e5b6d6dSopenharmony_ciall its data comes from a more general locales, we will provide an empty 1432e5b6d6dSopenharmony_ciresource bundle. This is reflected in our return informational codes (see the 1442e5b6d6dSopenharmony_cisection on APIs). A lot of ICU frameworks (collation, formatting etc.) relies on 1452e5b6d6dSopenharmony_cithe data stored in resource bundles. 1462e5b6d6dSopenharmony_ci 1472e5b6d6dSopenharmony_ciResource bundles rely on the ICU data framework. For more information on the 1482e5b6d6dSopenharmony_cifunctioning of ICU data, see the appropriate [section](../icudata.md). 1492e5b6d6dSopenharmony_ci 1502e5b6d6dSopenharmony_ciUsers of the ICU library can also use the resource bundle framework to store and 1512e5b6d6dSopenharmony_ciretrieve localizable data in their projects. 1522e5b6d6dSopenharmony_ci 1532e5b6d6dSopenharmony_ciResource bundles are collections of resources. Individual resources can contain 1542e5b6d6dSopenharmony_cidata or other resources. 1552e5b6d6dSopenharmony_ci 1562e5b6d6dSopenharmony_ci> :point_right: **Note**: ICU4J relies on the resource bundle mechanism already 1572e5b6d6dSopenharmony_ci> provided by JDK for its functioning. Therefore, most of the discussion here 1582e5b6d6dSopenharmony_ci> pertains only to ICU4C. 1592e5b6d6dSopenharmony_ci 1602e5b6d6dSopenharmony_ci### Fallback Mechanism 1612e5b6d6dSopenharmony_ci 1622e5b6d6dSopenharmony_ciEssential part ICU's resource management framework is the fallback mechanism. It 1632e5b6d6dSopenharmony_ciensures that if the data for the requested locale is missing, an effort will be 1642e5b6d6dSopenharmony_cimade to obtain the most usable data. Fallback can happen in two situations: 1652e5b6d6dSopenharmony_ci 1662e5b6d6dSopenharmony_ci1. When a resource bundle for a locale is requested. If it doesn't exist, a 1672e5b6d6dSopenharmony_ci more general resource bundle will be used. If there are no such resource 1682e5b6d6dSopenharmony_ci bundles, a resource bundle for default locale will be used. If this fails, 1692e5b6d6dSopenharmony_ci the root resource bundle will be used. When using ICU locale data, not 1702e5b6d6dSopenharmony_ci finding the requested resource bundle means that we don't know what the data 1712e5b6d6dSopenharmony_ci should be for that particular locale, so you might want to consider this 1722e5b6d6dSopenharmony_ci situation an error. Custom packages of resource bundles may or may not 1732e5b6d6dSopenharmony_ci adhere to this contract. A special care should be taken in remote server 1742e5b6d6dSopenharmony_ci situations, when the data from the default locale might not mean anything to 1752e5b6d6dSopenharmony_ci the remote user (imagine a situation where a server in Japan responds to a 1762e5b6d6dSopenharmony_ci Spanish speaking client by using default Japanese data. 1772e5b6d6dSopenharmony_ci 1782e5b6d6dSopenharmony_ci2. When a resource inside a resource bundle is requested. If the resource is 1792e5b6d6dSopenharmony_ci not present, it will be sought after in more general resources. If at 1802e5b6d6dSopenharmony_ci initial opening of a resource bundle we went through the default locale, the 1812e5b6d6dSopenharmony_ci search for a resource will also go through it. For example, if a resource 1822e5b6d6dSopenharmony_ci bundle for zh_Hans_CN is opened, a missing resource will be looked for in 1832e5b6d6dSopenharmony_ci zh_Hans, zh and finally root. This is usually harmless, except when a 1842e5b6d6dSopenharmony_ci resource is only located in the default locale or in the root resource 1852e5b6d6dSopenharmony_ci bundle. 1862e5b6d6dSopenharmony_ci 1872e5b6d6dSopenharmony_ci### Data Packaging 1882e5b6d6dSopenharmony_ci 1892e5b6d6dSopenharmony_ciICU allows and requires that the application specific data be stored apart from 1902e5b6d6dSopenharmony_cithe ICU internal data (locale, converter, transformation data etc.). Application 1912e5b6d6dSopenharmony_cidata should be stored in packages. ICU uses the default package (NULL) for its 1922e5b6d6dSopenharmony_cidata. All the ICU's build tools provide means to specify the package for your 1932e5b6d6dSopenharmony_cidata. More about how to package application data can be found below. 1942e5b6d6dSopenharmony_ci 1952e5b6d6dSopenharmony_ci## Resource Bundle APIs 1962e5b6d6dSopenharmony_ci 1972e5b6d6dSopenharmony_ciICU4C provides both C and C++ APIs for using resource bundles. The core 1982e5b6d6dSopenharmony_ciimplementation is in C, while the C++ APIs are only a thin wrapper around it. 1992e5b6d6dSopenharmony_ciTherefore, the code using C APIs will generally be faster. 2002e5b6d6dSopenharmony_ci 2012e5b6d6dSopenharmony_ciResource bundles use ICU's "open use close" paradigm. In C all the resource 2022e5b6d6dSopenharmony_cibundle operations are done using the `UResourceBundle*` handle. `UResourceBundle*` 2032e5b6d6dSopenharmony_ciallows access to both resource bundles and individual resources. In C++, class 2042e5b6d6dSopenharmony_ci`ResourceBundle` should be used for both resource bundles and individual 2052e5b6d6dSopenharmony_ciresources. 2062e5b6d6dSopenharmony_ci 2072e5b6d6dSopenharmony_ciTo use the resource bundle framework, you need to include the appropriate header 2082e5b6d6dSopenharmony_cifile, `unicode/ures.h` for C and `unicode/resbund.h` for C++. 2092e5b6d6dSopenharmony_ci 2102e5b6d6dSopenharmony_ci### Error Checking 2112e5b6d6dSopenharmony_ci 2122e5b6d6dSopenharmony_ciIf an operation with resource bundle fails, an error code will be set. It is 2132e5b6d6dSopenharmony_ciimportant to check for the value of the error code. In C you should frequently 2142e5b6d6dSopenharmony_ciuse the following construct: 2152e5b6d6dSopenharmony_ci 2162e5b6d6dSopenharmony_ci```c 2172e5b6d6dSopenharmony_ciif (U_SUCCESS(status)) { 2182e5b6d6dSopenharmony_ci /* everything is fine */ 2192e5b6d6dSopenharmony_ci} else { 2202e5b6d6dSopenharmony_ci /* there was an error */ 2212e5b6d6dSopenharmony_ci} 2222e5b6d6dSopenharmony_ci``` 2232e5b6d6dSopenharmony_ci 2242e5b6d6dSopenharmony_ci### Opening of Resource Bundles 2252e5b6d6dSopenharmony_ci 2262e5b6d6dSopenharmony_ciThe most common C resource bundle opening API is: 2272e5b6d6dSopenharmony_ci 2282e5b6d6dSopenharmony_ci```c 2292e5b6d6dSopenharmony_ciUResourceBundle* ures_open(const char* package, const char* locale, UErrorCode* status) 2302e5b6d6dSopenharmony_ci``` 2312e5b6d6dSopenharmony_ci 2322e5b6d6dSopenharmony_ciThe first argument specifies the package name or `NULL` for the default ICU package. 2332e5b6d6dSopenharmony_ciThe second argument is the locale for which you want the resource bundle. 2342e5b6d6dSopenharmony_ciSpecial values for the locale are `NULL` for the default locale and `""` (empty 2352e5b6d6dSopenharmony_cistring) for the root locale. The third argument should be set to `U_ZERO_ERROR` 2362e5b6d6dSopenharmony_cibefore calling the function. It will return the status of operation. Apart from 2372e5b6d6dSopenharmony_cireturning regular errors, it can return two informational/warning codes: 2382e5b6d6dSopenharmony_ci`U_USING_FALLBACK_WARNING` and `U_USING_DEFAULT_WARNING`. The first informational 2392e5b6d6dSopenharmony_cicode means that the requested resource bundle was not found and that a more 2402e5b6d6dSopenharmony_cigeneral bundle was returned. If you are opening ICU resource bundles, do note 2412e5b6d6dSopenharmony_cithat this means that we do not guarantee that the contents of opened resource 2422e5b6d6dSopenharmony_cibundle will be correct for the requested locale. The situation might be 2432e5b6d6dSopenharmony_cidifferent for application packages. However, the warning `U_USING_DEFAULT_WARNING` 2442e5b6d6dSopenharmony_cimeans that there were no more general resource bundles found and that you were 2452e5b6d6dSopenharmony_cireturned either a resource bundle that is the default for the system, or the root 2462e5b6d6dSopenharmony_ciresource bundle. This will almost certainly contain wrong data. 2472e5b6d6dSopenharmony_ci 2482e5b6d6dSopenharmony_ciThere are a couple of other opening APIs: `ures_openDirect` takes the same 2492e5b6d6dSopenharmony_ciarguments as the `ures_open` but will fail if the requested locale is not found. 2502e5b6d6dSopenharmony_ciAlso, if opening is successful, no fallback will be performed if an individual 2512e5b6d6dSopenharmony_ciresource is not found. The second one, `ures_openU` takes a `UChar*` for package 2522e5b6d6dSopenharmony_ciname instead of `char*`. 2532e5b6d6dSopenharmony_ci 2542e5b6d6dSopenharmony_ciIn C++, opening is done through a constructor. There are several constructors. 2552e5b6d6dSopenharmony_ciMost notable difference from C APIs is that the package should be given as a 2562e5b6d6dSopenharmony_ci`UnicodeString` and the locale is passed as a `Locale` object. There is also a copy 2572e5b6d6dSopenharmony_ciconstructor and a constructor that takes a C `UResourceBundle*` handle. The 2582e5b6d6dSopenharmony_ciresult is a `ResourceBundle` object. Remarks about informational codes are also 2592e5b6d6dSopenharmony_civalid for the C++ APIs. 2602e5b6d6dSopenharmony_ci 2612e5b6d6dSopenharmony_ci> :point_right: **Note**: All the data accessing examples in the following 2622e5b6d6dSopenharmony_ci> sections use ICU's 2632e5b6d6dSopenharmony_ci> [root](https://github.com/unicode-org/icu/blob/main/icu4c/source/data/locales/root.txt) 2642e5b6d6dSopenharmony_ci> resource bundle. 2652e5b6d6dSopenharmony_ci 2662e5b6d6dSopenharmony_ci```c 2672e5b6d6dSopenharmony_ciUErrorCode status = U_ZERO_ERROR; 2682e5b6d6dSopenharmony_ciUResourceBundle* icuRoot = ures_open(NULL, "root", &status); 2692e5b6d6dSopenharmony_ciif (U_SUCCESS(status)) { 2702e5b6d6dSopenharmony_ci /* everything is fine */ 2712e5b6d6dSopenharmony_ci ... 2722e5b6d6dSopenharmony_ci /* do some interesting stuff here - see below */ 2732e5b6d6dSopenharmony_ci ... 2742e5b6d6dSopenharmony_ci /* and close the bundle afterwards */ 2752e5b6d6dSopenharmony_ci ures_close(icuRoot); /* discussed later */ 2762e5b6d6dSopenharmony_ci} else { 2772e5b6d6dSopenharmony_ci /* there was an error */ 2782e5b6d6dSopenharmony_ci /* report and exit */ 2792e5b6d6dSopenharmony_ci} 2802e5b6d6dSopenharmony_ci``` 2812e5b6d6dSopenharmony_ci 2822e5b6d6dSopenharmony_ciIn C++, opening would look like this: 2832e5b6d6dSopenharmony_ci 2842e5b6d6dSopenharmony_ci```c++ 2852e5b6d6dSopenharmony_ciUErrorCode status = U_ZERO_ERROR; 2862e5b6d6dSopenharmony_ci// we rely on automatic construction of Locale object from a char* 2872e5b6d6dSopenharmony_ciResourceBundle myResource("myPackage", "de_AT", status); 2882e5b6d6dSopenharmony_ciif (U_SUCCESS(status)) { 2892e5b6d6dSopenharmony_ci /* everything is fine */ 2902e5b6d6dSopenharmony_ci ... 2912e5b6d6dSopenharmony_ci /* do some interesting stuff here */ 2922e5b6d6dSopenharmony_ci ... 2932e5b6d6dSopenharmony_ci /* the bundle will be closed when going out of scope */ 2942e5b6d6dSopenharmony_ci} else { 2952e5b6d6dSopenharmony_ci /* there was an error */ 2962e5b6d6dSopenharmony_ci /* report and exit */ 2972e5b6d6dSopenharmony_ci} 2982e5b6d6dSopenharmony_ci``` 2992e5b6d6dSopenharmony_ci 3002e5b6d6dSopenharmony_ci### Closing of Resource Bundles 3012e5b6d6dSopenharmony_ci 3022e5b6d6dSopenharmony_ciAfter using, resource bundles need to be closed to prevent memory leaks. In C, 3032e5b6d6dSopenharmony_ciyou should call the `void ures_close(UResourceBundle* resB)` API. In C++, if you 3042e5b6d6dSopenharmony_cihave just used the `ResourceBundle` objects, going out of scope will close the 3052e5b6d6dSopenharmony_cibundles. When using allocated objects, make sure that you call the appropriate 3062e5b6d6dSopenharmony_cidelete function. 3072e5b6d6dSopenharmony_ci 3082e5b6d6dSopenharmony_ciAs already mentioned, resource bundles and resources share the same type. You 3092e5b6d6dSopenharmony_cican close bundles and resources in any order you like. You can invoke `ures_close` 3102e5b6d6dSopenharmony_cion `NULL` resource bundles. Therefore, you can always this API regardless of the 3112e5b6d6dSopenharmony_cisuccess of previous operations. 3122e5b6d6dSopenharmony_ci 3132e5b6d6dSopenharmony_ci### Accessing Resources 3142e5b6d6dSopenharmony_ci 3152e5b6d6dSopenharmony_ciOnce you are in the possession of a valid resource bundle, you can access the 3162e5b6d6dSopenharmony_ciresources and data that it holds. The result of accessing operations will be a 3172e5b6d6dSopenharmony_cinew resource bundle object. In C, `UResourceBundle*` handles can be reused by 3182e5b6d6dSopenharmony_ciusing the fill-in parameter. That saves you from frequent closing and 3192e5b6d6dSopenharmony_cireallocating of resource bundle structures, which can dramatically improve the 3202e5b6d6dSopenharmony_ciperformance. C++ APIs do not provide means for object reuse. All the C examples 3212e5b6d6dSopenharmony_ciin the following sections will use a fill-in parameter. 3222e5b6d6dSopenharmony_ci 3232e5b6d6dSopenharmony_ci#### Types of Resources 3242e5b6d6dSopenharmony_ci 3252e5b6d6dSopenharmony_ciResource bundles can contain two main types of resources: complex and simple 3262e5b6d6dSopenharmony_ciresources. Complex resources store other resources and can have named or unnamed 3272e5b6d6dSopenharmony_cielements. **Tables** store named elements, while **arrays** store unnamed ones. 3282e5b6d6dSopenharmony_ciSimple resources contain data which can be **string**, **binary**, **integer 3292e5b6d6dSopenharmony_ciarray** or a single **integer**. 3302e5b6d6dSopenharmony_ci 3312e5b6d6dSopenharmony_ciThere are several ways for accessing data stored in the complex resources. 3322e5b6d6dSopenharmony_ciTables can be accessed using keys, indexes and by iteration. Arrays can be 3332e5b6d6dSopenharmony_ciaccessed using indexes and by iteration. 3342e5b6d6dSopenharmony_ci 3352e5b6d6dSopenharmony_ciIn order to be able to distinguish between resources, one needs to know the type 3362e5b6d6dSopenharmony_ciof the resource at hand. To find this out, use the 3372e5b6d6dSopenharmony_ci`UResType ures_getType(UResourceBundle* resourceBundle)` API, or the C++ analog 3382e5b6d6dSopenharmony_ci`UResType getType(void)`. The `UResType` is an enumeration defined in the 3392e5b6d6dSopenharmony_ci[unicode/ures.h](https://github.com/unicode-org/icu/blob/main/icu4c/source/common/unicode/ures.h) 3402e5b6d6dSopenharmony_ciheader file. 3412e5b6d6dSopenharmony_ci 3422e5b6d6dSopenharmony_ci> :point_right: **Note**: Indexes of resources in tables do not necessarily 3432e5b6d6dSopenharmony_ci> correspond to the order of items in a table. Due to the way binary structure is 3442e5b6d6dSopenharmony_ci> organized, items in a table are sorted according to the binary ordering of the 3452e5b6d6dSopenharmony_ci> keys, therefore, the index of an item in a table will be the index of its key 3462e5b6d6dSopenharmony_ci> string in the binary order. Furthermore, the ordering of the keys are different 3472e5b6d6dSopenharmony_ci> on ASCII and EBCDIC platforms. 3482e5b6d6dSopenharmony_ci> <br> 3492e5b6d6dSopenharmony_ci> Starting with ICU 4.4, the order of table items is the ASCII string order on 3502e5b6d6dSopenharmony_ci> all platforms. 3512e5b6d6dSopenharmony_ci> <br> 3522e5b6d6dSopenharmony_ci> The iteration order of table items might change from release to release. 3532e5b6d6dSopenharmony_ci 3542e5b6d6dSopenharmony_ci#### Accessing by Key 3552e5b6d6dSopenharmony_ci 3562e5b6d6dSopenharmony_ciTo access resources using a key, you can use the `UResourceBundle* 3572e5b6d6dSopenharmony_ciures_getByKey(const UResourceBundle* resourceBundle, const char* key, 3582e5b6d6dSopenharmony_ciUResourceBundle* fillIn, UErrorCode* status)` API. First argument is the parent 3592e5b6d6dSopenharmony_ciresource bundle, which can be either a resource bundle opened using `ures_open` or 3602e5b6d6dSopenharmony_cisimilar APIs or a table resource. The key is always specified using invariant 3612e5b6d6dSopenharmony_cicharacters. The fill-in parameter can be either `NULL` or a valid resource bundle 3622e5b6d6dSopenharmony_cihandle. If it is `NULL`, a new resource bundle will be constructed. If you pass an 3632e5b6d6dSopenharmony_cialready existing resource bundle, it will be closed and the memory will be 3642e5b6d6dSopenharmony_cireused for the new resource bundle. Status indicator can return 3652e5b6d6dSopenharmony_ci`U_MISSING_RESOURCE_ERROR` which indicates that no resources with that key exist, 3662e5b6d6dSopenharmony_cior one of the above mentioned informational codes (`U_USING_FALLBACK_WARNING` and 3672e5b6d6dSopenharmony_ci`U_USING_DEFAULT_WARNING`) which do not affect the validity of data in the case of 3682e5b6d6dSopenharmony_ciresource retrieval. 3692e5b6d6dSopenharmony_ci 3702e5b6d6dSopenharmony_ci```c 3712e5b6d6dSopenharmony_ci... 3722e5b6d6dSopenharmony_ci/* we already got zones resource from the opening example */ 3732e5b6d6dSopenharmony_ciUResourceBundle *zones = ures_getByKey(icuRoot, "zoneStrings", NULL, &status); 3742e5b6d6dSopenharmony_ciif (U_SUCCESS(status)) { 3752e5b6d6dSopenharmony_ci /* ... do interesting stuff - see below ... */ 3762e5b6d6dSopenharmony_ci} 3772e5b6d6dSopenharmony_ciures_close(zones); 3782e5b6d6dSopenharmony_ci/* clean up the rest */ 3792e5b6d6dSopenharmony_ci... 3802e5b6d6dSopenharmony_ci``` 3812e5b6d6dSopenharmony_ci 3822e5b6d6dSopenharmony_ciIn C++, the analogous API is `ResourceBundle get(const char* key, UErrorCode& status) const`. 3832e5b6d6dSopenharmony_ci 3842e5b6d6dSopenharmony_ciTrying to retrieve resources by key on any other type of resource than tables 3852e5b6d6dSopenharmony_ciwill produce a `U_RESOURCE_TYPE_MISMATCH` error. 3862e5b6d6dSopenharmony_ci 3872e5b6d6dSopenharmony_ci#### Accessing by Index 3882e5b6d6dSopenharmony_ci 3892e5b6d6dSopenharmony_ciAccessing by index requires you to supply an index of the resource that you want 3902e5b6d6dSopenharmony_cito retrieve. Appropriate API is `UResourceBundle* ures_getByIndex(const 3912e5b6d6dSopenharmony_ciUResourceBundle* resourceBundle, int32_t indexR, UResourceBundle* fillIn, 3922e5b6d6dSopenharmony_ciUErrorCode* status)`. The arguments have the same semantics as for the 3932e5b6d6dSopenharmony_ci`ures_getByKey` API. The only difference is the second argument, which is the 3942e5b6d6dSopenharmony_ciindex of the resource that you want to retrieve. Indexes start at zero. If an 3952e5b6d6dSopenharmony_ciindex out of range is specified, `U_MISSING_RESOURCE_ERROR` is returned. To find 3962e5b6d6dSopenharmony_cithe size of a resource, you can use `int32_t ures_getSize(UResourceBundle* 3972e5b6d6dSopenharmony_ciresourceBundle)`. The maximum index is the result of this API minus 1. 3982e5b6d6dSopenharmony_ci 3992e5b6d6dSopenharmony_ci```c 4002e5b6d6dSopenharmony_ci... 4012e5b6d6dSopenharmony_ci/* we already got zones resource from the accessing by key example */ 4022e5b6d6dSopenharmony_ciUResourceBundle *currentZone = NULL; 4032e5b6d6dSopenharmony_ciint32_t index = 0; 4042e5b6d6dSopenharmony_cifor (index = 0; index < ures_getSize(zones); index++) { 4052e5b6d6dSopenharmony_ci currentZone = ures_getByIndex(zones, index, currentZone, &status); 4062e5b6d6dSopenharmony_ci /* ... do interesting stuff here ... */ 4072e5b6d6dSopenharmony_ci} 4082e5b6d6dSopenharmony_ciures_close(currentZone); 4092e5b6d6dSopenharmony_ci/* cleanup the rest */ 4102e5b6d6dSopenharmony_ci... 4112e5b6d6dSopenharmony_ci``` 4122e5b6d6dSopenharmony_ci 4132e5b6d6dSopenharmony_ciAccessing simple resource with an index 0 will return themselves. This is useful 4142e5b6d6dSopenharmony_cifor iterating over all the resources regardless of type. 4152e5b6d6dSopenharmony_ci 4162e5b6d6dSopenharmony_ciC++ overloads the get API with `ResourceBundle get(int32_t index, UErrorCode& status) const`. 4172e5b6d6dSopenharmony_ci 4182e5b6d6dSopenharmony_ci#### Iterating Over Resources 4192e5b6d6dSopenharmony_ci 4202e5b6d6dSopenharmony_ciIf you don't care about the order of the resources and want simple code, you can 4212e5b6d6dSopenharmony_ciuse the iteration mechanism. To set up iteration over a complex resource, you 4222e5b6d6dSopenharmony_cican simply start iterating using the `UResourceBundle* 4232e5b6d6dSopenharmony_ciures_getNextResource(UResourceBundle* resourceBundle, UResourceBundle* fillIn, 4242e5b6d6dSopenharmony_ciUErrorCode* status)`. It is advisable though to reset the iterator for a 4252e5b6d6dSopenharmony_ciresource before starting, in order to ensure that the iteration will indeed 4262e5b6d6dSopenharmony_cistart from the beginning - just in case somebody else has already been playing 4272e5b6d6dSopenharmony_ciwith this resource. To reset the iterator use `void 4282e5b6d6dSopenharmony_ciures_resetIterator(UResourceBundle* resourceBundle)` API. To check whether there 4292e5b6d6dSopenharmony_ciare more resources, call `UBool ures_hasNext(UResourceBundle* resourceBundle)`. 4302e5b6d6dSopenharmony_ciIf you have iterated through the whole resource, `NULL` will be returned. 4312e5b6d6dSopenharmony_ci 4322e5b6d6dSopenharmony_ci```c 4332e5b6d6dSopenharmony_ci... 4342e5b6d6dSopenharmony_ci/* we already got zones resource from the accessing by key example */ 4352e5b6d6dSopenharmony_ciUResourceBundle *currentZone = NULL; 4362e5b6d6dSopenharmony_ciures_resetIterator(zones); 4372e5b6d6dSopenharmony_ciwhile (ures_hasNext(zones)) { 4382e5b6d6dSopenharmony_ci currentZone = ures_getNextResource(zones, currentZone, &status); 4392e5b6d6dSopenharmony_ci /* ... do interesting stuff here ... */ 4402e5b6d6dSopenharmony_ci} 4412e5b6d6dSopenharmony_ciures_close(currentZone); 4422e5b6d6dSopenharmony_ci/* cleanup the rest */ 4432e5b6d6dSopenharmony_ci... 4442e5b6d6dSopenharmony_ci``` 4452e5b6d6dSopenharmony_ci 4462e5b6d6dSopenharmony_ciC++ provides analogous APIs: `ResourceBundle getNext(UErrorCode& status)`, `void resetIterator(void)` 4472e5b6d6dSopenharmony_ci and `UBool hasNext(void)`. 4482e5b6d6dSopenharmony_ci 4492e5b6d6dSopenharmony_ci#### Accessing Data in the Simple Resources 4502e5b6d6dSopenharmony_ci 4512e5b6d6dSopenharmony_ciIn order to get to the data in the simple resources, you need to use appropriate 4522e5b6d6dSopenharmony_ciAPIs according to the type of a simple resource. They are summarized in the 4532e5b6d6dSopenharmony_citables below. All the pointers returned should be considered pointers to read 4542e5b6d6dSopenharmony_cionly data. Using an API on a resource of a wrong type will result in an error. 4552e5b6d6dSopenharmony_ci 4562e5b6d6dSopenharmony_ciStrings: 4572e5b6d6dSopenharmony_ci 4582e5b6d6dSopenharmony_ci| Language | API | 4592e5b6d6dSopenharmony_ci| -------- | ------------------------------------------------------------------------------------------------------ | 4602e5b6d6dSopenharmony_ci| C | `const UChar* ures_getString(const UResourceBundle* resourceBundle, int32_t* len, UErrorCode* status)` | 4612e5b6d6dSopenharmony_ci| C++ | `UnicodeString getString(UErrorCode& status) const` | 4622e5b6d6dSopenharmony_ci 4632e5b6d6dSopenharmony_ciExample: 4642e5b6d6dSopenharmony_ci 4652e5b6d6dSopenharmony_ci```c 4662e5b6d6dSopenharmony_ci... 4672e5b6d6dSopenharmony_ciUResourceBundle* version = ures_getByKey(icuRoot, "Version", NULL, &status); 4682e5b6d6dSopenharmony_ciif (U_SUCCESS(status)) { 4692e5b6d6dSopenharmony_ci int32_t versionStringLen = 0; 4702e5b6d6dSopenharmony_ci const UChar* versionString = ures_getString(version, &versionStringLen, &status); 4712e5b6d6dSopenharmony_ci} 4722e5b6d6dSopenharmony_ciures_close(version); 4732e5b6d6dSopenharmony_ci... 4742e5b6d6dSopenharmony_ci``` 4752e5b6d6dSopenharmony_ci 4762e5b6d6dSopenharmony_ciBinaries: 4772e5b6d6dSopenharmony_ci 4782e5b6d6dSopenharmony_ci| Language | API | 4792e5b6d6dSopenharmony_ci| -------- | -------------------------------------------------------------------------------------------------------- | 4802e5b6d6dSopenharmony_ci| C | `const uint8_t* ures_getBinary(const UResourceBundle* resourceBundle, int32_t* len, UErrorCode* status)` | 4812e5b6d6dSopenharmony_ci| C++ | `const uint8_t* getBinary(int32_t& len, UErrorCode& status) const` | 4822e5b6d6dSopenharmony_ci 4832e5b6d6dSopenharmony_ciIntegers, signed and unsigned: 4842e5b6d6dSopenharmony_ci 4852e5b6d6dSopenharmony_ci| Language | API | 4862e5b6d6dSopenharmony_ci| -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- | 4872e5b6d6dSopenharmony_ci| C | `int32_t ures_getInt(const UResourceBundle* resourceBundle, UErrorCode* status)` `uint32_t ures_getUInt(const UResourceBundle* resourceBundle, UErrorCode* status)` | 4882e5b6d6dSopenharmony_ci| C++ | `int32_t getInt(UErrorCode& status) const` <br> `uint32_t getUInt(UErrorCode& status) const` | 4892e5b6d6dSopenharmony_ci 4902e5b6d6dSopenharmony_ciInteger Arrays: 4912e5b6d6dSopenharmony_ci 4922e5b6d6dSopenharmony_ci| Language | API | 4932e5b6d6dSopenharmony_ci| -------- | ----------------------------------------------------------------------------------------------------------- | 4942e5b6d6dSopenharmony_ci| C | `const int32_t* ures_getIntVector(const UResourceBundle* resourceBundle, int32_t* len, UErrorCode* status)` | 4952e5b6d6dSopenharmony_ci| C++ | `const int32_t* getIntVector(int32_t& len, UErrorCode& status) const` | 4962e5b6d6dSopenharmony_ci 4972e5b6d6dSopenharmony_ci#### Convenience APIs 4982e5b6d6dSopenharmony_ci 4992e5b6d6dSopenharmony_ciSince the vast majority of data stored in resource bundles are strings, ICU's 5002e5b6d6dSopenharmony_ciresource bundle framework provides a number of different convenience APIs that 5012e5b6d6dSopenharmony_cidirectly access strings stored in resources. They are analogous to APIs already 5022e5b6d6dSopenharmony_cidiscussed, with the difference that they return const `UChar*` or `UnicodeString` 5032e5b6d6dSopenharmony_ciobjects. 5042e5b6d6dSopenharmony_ci 5052e5b6d6dSopenharmony_ci> :point_right: **Note**: The C APIs that allow returning of `UnicodeStrings` only 5062e5b6d6dSopenharmony_ci> work if used in a C++ file. Trying to use them in a C file will produce a 5072e5b6d6dSopenharmony_ci> compiler error. 5082e5b6d6dSopenharmony_ci 5092e5b6d6dSopenharmony_ciAPIs that allow retrieving strings by specifying a key: 5102e5b6d6dSopenharmony_ci 5112e5b6d6dSopenharmony_ci| Language (Return Type) | API | 5122e5b6d6dSopenharmony_ci| ---------------------- | ------------------------------------------------------------------------------------------------------------------ | 5132e5b6d6dSopenharmony_ci| C (UChar*) | `const UChar* ures_getStringByKey(const UResourceBundle* resB, const char* key, int32_t* len, UErrorCode* status)` | 5142e5b6d6dSopenharmony_ci| C (UnicodeString) | `UnicodeString ures_getUnicodeStringByKey(const UResourceBundle* resB, const char* key, UErrorCode* status)` | 5152e5b6d6dSopenharmony_ci| C++ | `UnicodeString getStringEx(const char* key, UErrorCode& status) const` | 5162e5b6d6dSopenharmony_ci 5172e5b6d6dSopenharmony_ci 5182e5b6d6dSopenharmony_ciAPIs that allow retrieving strings by specifying an index: 5192e5b6d6dSopenharmony_ci 5202e5b6d6dSopenharmony_ci| Language (Return Type) | API | 5212e5b6d6dSopenharmony_ci| ---------------------- | ------------------------------------------------------------------------------------------------------------------- | 5222e5b6d6dSopenharmony_ci| C (UChar*) | `const UChar* ures_getStringByIndex(const UResourceBundle* resB, int32_t indexS, int32_t* len, UErrorCode* status)` | 5232e5b6d6dSopenharmony_ci| C (UnicodeString) | `UnicodeString ures_getUnicodeStringByIndex(const UResourceBundle* resB, int32_t indexS, UErrorCode* status)` | 5242e5b6d6dSopenharmony_ci| C++ | `UnicodeString getStringEx(int32_t index, UErrorCode& status) const` | 5252e5b6d6dSopenharmony_ci 5262e5b6d6dSopenharmony_ciAPIs for retrieving strings through iteration: 5272e5b6d6dSopenharmony_ci 5282e5b6d6dSopenharmony_ci| Language (Return Type) | API | 5292e5b6d6dSopenharmony_ci| ---------------------- | ---------------------------------------------------------------------------------------------------------------------- | 5302e5b6d6dSopenharmony_ci| C (UChar*) | `const UChar* ures_getNextString(UResourceBundle* resourceBundle, int32_t* len, const char** key, UErrorCode* status)` | 5312e5b6d6dSopenharmony_ci| C (UnicodeString) | `UnicodeString ures_getNextUnicodeString(UResourceBundle* resB, const char** key, UErrorCode* status)` | 5322e5b6d6dSopenharmony_ci| C++ | `UnicodeString getNextString(UErrorCode& status)` | 5332e5b6d6dSopenharmony_ci 5342e5b6d6dSopenharmony_ci#### Other APIs 5352e5b6d6dSopenharmony_ci 5362e5b6d6dSopenharmony_ciResource bundle framework provides a number of additional APIs that allow you to 5372e5b6d6dSopenharmony_ciget more information on the resources you are using. They are summarized in the 5382e5b6d6dSopenharmony_cifollowing tables. 5392e5b6d6dSopenharmony_ci 5402e5b6d6dSopenharmony_ci| Language | API | 5412e5b6d6dSopenharmony_ci| -------- | ------------------------------------------------------- | 5422e5b6d6dSopenharmony_ci| C | `int32_t ures_getSize(UResourceBundle* resourceBundle)` | 5432e5b6d6dSopenharmony_ci| C++ | `int32_t getSize(void) const` | 5442e5b6d6dSopenharmony_ci 5452e5b6d6dSopenharmony_ciGets the number of items in a resource. Simple resources always return size 1. 5462e5b6d6dSopenharmony_ci 5472e5b6d6dSopenharmony_ci| Language | API | 5482e5b6d6dSopenharmony_ci| -------- | -------------------------------------------------------- | 5492e5b6d6dSopenharmony_ci| C | `UResType ures_getType(UResourceBundle* resourceBundle)` | 5502e5b6d6dSopenharmony_ci| C++ | `UResType getType(void)` | 5512e5b6d6dSopenharmony_ci 5522e5b6d6dSopenharmony_ciGets the type of the resource. For a list of resource types, see: 5532e5b6d6dSopenharmony_ci[unicode/ures.h](https://github.com/unicode-org/icu/blob/main/icu4c/source/common/unicode/ures.h) 5542e5b6d6dSopenharmony_ci 5552e5b6d6dSopenharmony_ci| Language | API | 5562e5b6d6dSopenharmony_ci| -------- | ------------------------------------------------ | 5572e5b6d6dSopenharmony_ci| C | `const char* ures_getKey(UResourceBundle* resB)` | 5582e5b6d6dSopenharmony_ci| C++ | `const char* getKey(void)` | 5592e5b6d6dSopenharmony_ci 5602e5b6d6dSopenharmony_ciGets the key of a named resource or `NULL` if this resource is a member of an 5612e5b6d6dSopenharmony_ciarray. 5622e5b6d6dSopenharmony_ci 5632e5b6d6dSopenharmony_ci| Language | API | 5642e5b6d6dSopenharmony_ci| -------- | ----------------------------------------------------------------------------- | 5652e5b6d6dSopenharmony_ci| C | `void ures_getVersion(const UResourceBundle* resB, UVersionInfo versionInfo)` | 5662e5b6d6dSopenharmony_ci| C++ | `void getVersion(UVersionInfo versionInfo) const` | 5672e5b6d6dSopenharmony_ci 5682e5b6d6dSopenharmony_ciFills out the version structure for this resource. 5692e5b6d6dSopenharmony_ci 5702e5b6d6dSopenharmony_ci| Language | API | 5712e5b6d6dSopenharmony_ci| -------- | --------------------------------------------------------------------------------------- | 5722e5b6d6dSopenharmony_ci| C | `const char* ures_getLocale(const UResourceBundle* resourceBundle, UErrorCode* status)` | 5732e5b6d6dSopenharmony_ci| C++ | `const Locale& getLocale(void) const` | 5742e5b6d6dSopenharmony_ci 5752e5b6d6dSopenharmony_ciReturns the locale this resource is from. This API is going to change, so stay 5762e5b6d6dSopenharmony_cituned. 5772e5b6d6dSopenharmony_ci 5782e5b6d6dSopenharmony_ci### Format of Resource Bundles 5792e5b6d6dSopenharmony_ci 5802e5b6d6dSopenharmony_ciResource bundles are written in its source format. Before using them, they must 5812e5b6d6dSopenharmony_cibe compiled to the binary format using the `genrb` utility. Currently supported 5822e5b6d6dSopenharmony_cisource format is a text file. The format is defined in a [formal definition 5832e5b6d6dSopenharmony_cifile](https://github.com/unicode-org/icu-docs/blob/main/design/bnf_rb.txt). 5842e5b6d6dSopenharmony_ci 5852e5b6d6dSopenharmony_ciThis is an example of a resource bundle source file: 5862e5b6d6dSopenharmony_ci 5872e5b6d6dSopenharmony_ci``` 5882e5b6d6dSopenharmony_ci// Comments start with a '//' and extend to the end of the line 5892e5b6d6dSopenharmony_ci// first, a locale name for the bundle is defined. The whole bundle is a table 5902e5b6d6dSopenharmony_ci// every resource, including the whole bundle has its name. 5912e5b6d6dSopenharmony_ci// The name consists of invariant characters, digits and following symbols: -, _. 5922e5b6d6dSopenharmony_ciroot { 5932e5b6d6dSopenharmony_ci menu { 5942e5b6d6dSopenharmony_ci id { "mainmenu" } 5952e5b6d6dSopenharmony_ci items { 5962e5b6d6dSopenharmony_ci { 5972e5b6d6dSopenharmony_ci id { "file" } 5982e5b6d6dSopenharmony_ci name { "&File" } 5992e5b6d6dSopenharmony_ci items { 6002e5b6d6dSopenharmony_ci { 6012e5b6d6dSopenharmony_ci id { "open" } 6022e5b6d6dSopenharmony_ci name { "&Open" } 6032e5b6d6dSopenharmony_ci } 6042e5b6d6dSopenharmony_ci { 6052e5b6d6dSopenharmony_ci id { "save" } 6062e5b6d6dSopenharmony_ci name { "&Save" } 6072e5b6d6dSopenharmony_ci } 6082e5b6d6dSopenharmony_ci { 6092e5b6d6dSopenharmony_ci id { "exit" } 6102e5b6d6dSopenharmony_ci name { "&Exit" } 6112e5b6d6dSopenharmony_ci } 6122e5b6d6dSopenharmony_ci } 6132e5b6d6dSopenharmony_ci } 6142e5b6d6dSopenharmony_ci 6152e5b6d6dSopenharmony_ci { 6162e5b6d6dSopenharmony_ci id { "edit" } 6172e5b6d6dSopenharmony_ci name { "&Edit" } 6182e5b6d6dSopenharmony_ci items { 6192e5b6d6dSopenharmony_ci { 6202e5b6d6dSopenharmony_ci id { "copy" } 6212e5b6d6dSopenharmony_ci name { "&Copy" } 6222e5b6d6dSopenharmony_ci } 6232e5b6d6dSopenharmony_ci { 6242e5b6d6dSopenharmony_ci id { "cut" } 6252e5b6d6dSopenharmony_ci name { "&Cut" } 6262e5b6d6dSopenharmony_ci } 6272e5b6d6dSopenharmony_ci { 6282e5b6d6dSopenharmony_ci id { "paste" } 6292e5b6d6dSopenharmony_ci name { "&Paste" } 6302e5b6d6dSopenharmony_ci } 6312e5b6d6dSopenharmony_ci } 6322e5b6d6dSopenharmony_ci } 6332e5b6d6dSopenharmony_ci 6342e5b6d6dSopenharmony_ci ... 6352e5b6d6dSopenharmony_ci } 6362e5b6d6dSopenharmony_ci } 6372e5b6d6dSopenharmony_ci 6382e5b6d6dSopenharmony_ci // This resource is an array, thus accessible only through iteration and indexes... 6392e5b6d6dSopenharmony_ci errors { 6402e5b6d6dSopenharmony_ci "Invalid Command", 6412e5b6d6dSopenharmony_ci "Bad Value", 6422e5b6d6dSopenharmony_ci 6432e5b6d6dSopenharmony_ci // Add more strings here... 6442e5b6d6dSopenharmony_ci 6452e5b6d6dSopenharmony_ci "Read the Manual" 6462e5b6d6dSopenharmony_ci } 6472e5b6d6dSopenharmony_ci 6482e5b6d6dSopenharmony_ci splash:import { "splash_root.gif" } // This is a binary imported file 6492e5b6d6dSopenharmony_ci 6502e5b6d6dSopenharmony_ci pgpkey:bin { a1b2c3d4e5f67890 } // a binary value 6512e5b6d6dSopenharmony_ci 6522e5b6d6dSopenharmony_ci versionInfo { // a table 6532e5b6d6dSopenharmony_ci major:int { 1 } // of integers 6542e5b6d6dSopenharmony_ci minor:int { 4 } 6552e5b6d6dSopenharmony_ci patch:int { 7 } 6562e5b6d6dSopenharmony_ci } 6572e5b6d6dSopenharmony_ci 6582e5b6d6dSopenharmony_ci buttonSize:intvector { 10, 20, 10, 20 } // an array of 32-bit integers 6592e5b6d6dSopenharmony_ci 6602e5b6d6dSopenharmony_ci // will pick up data from zoneStrings resource in en bundle in the ICU package 6612e5b6d6dSopenharmony_ci simpleAlias:alias { "/ICUDATA/en/zoneStrings" } 6622e5b6d6dSopenharmony_ci 6632e5b6d6dSopenharmony_ci // will pick up data from CollationElements resource in en bundle 6642e5b6d6dSopenharmony_ci // in the ICU package 6652e5b6d6dSopenharmony_ci CollationElements:alias { "/ICUDATA/en" } 6662e5b6d6dSopenharmony_ci} 6672e5b6d6dSopenharmony_ci``` 6682e5b6d6dSopenharmony_ci 6692e5b6d6dSopenharmony_ciBinary format is described in the 6702e5b6d6dSopenharmony_ci[uresdata.h](https://github.com/unicode-org/icu/blob/main/icu4c/source/common/uresdata.h) 6712e5b6d6dSopenharmony_ciheader file. 6722e5b6d6dSopenharmony_ci 6732e5b6d6dSopenharmony_ci### Resources Syntax 6742e5b6d6dSopenharmony_ci 6752e5b6d6dSopenharmony_ciSyntax of the resources that can be stored in resource bundles is specified in 6762e5b6d6dSopenharmony_cithe following table: 6772e5b6d6dSopenharmony_ci 6782e5b6d6dSopenharmony_ci| Data Type | Format | Description | 6792e5b6d6dSopenharmony_ci| --------------- | ---------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | 6802e5b6d6dSopenharmony_ci| Tables | `[name][:table] { subname1 { subresource1 } ... subnameN { subresourceN } }` | Tables are a complex resource that holds named resources. If it is a part of an array, it does not have a name. At this point, a resource bundle is a table. Access is allowed by key, index, and iteration. | 6812e5b6d6dSopenharmony_ci| Arrays | `[name][:array] {subresource1, ... subresourceN }` | Arrays are a complex resource that holds unnamed resources. If it is a part of an array, it does not have a name. Arrays require less memory than tables (since they don't store the name of sub-resources) but the index and iteration access are as fast as with tables. | 6822e5b6d6dSopenharmony_ci| Strings | `[name][:string] { ["]UnicodeText["] }` | Strings are simple resources that hold a chunk of Unicode encoded data. If it is a part of an array, it does not have a name. | 6832e5b6d6dSopenharmony_ci| Binaries | `name:bin { binarydata } name:import{ "fileNameToImport" }` | Binaries are used for storing binary information (processed data, images etc). Information is stored on a byte level. | 6842e5b6d6dSopenharmony_ci| Integers | `name:int { integervalue }` | Integers are used for storing a 32 bit integer value. | 6852e5b6d6dSopenharmony_ci| Integer Vectors | `name:intvector { integervalue, ... integervalueN }` | Integer vectors are used for storing 32 bit integer values. | 6862e5b6d6dSopenharmony_ci| Aliases | `name:alias { locale and path to aliased resource }` | Aliases point to other resources. They are useful for preventing duplication of data in resources that are not on the same branch of the fallback chain. Alias can also have an empty path. In that case the position of the alias resource is used to find the aliased resource. | 6872e5b6d6dSopenharmony_ci 6882e5b6d6dSopenharmony_ciAlthough specifying type for some resources can be omitted for backward 6892e5b6d6dSopenharmony_cicompatibility reasons, you are strongly encouraged to always specify the type of 6902e5b6d6dSopenharmony_cithe resources. As structure gets more complicated, some combinations of 6912e5b6d6dSopenharmony_ciresources that are not typed might produce unexpected results. 6922e5b6d6dSopenharmony_ci 6932e5b6d6dSopenharmony_ci### Escape Sequences 6942e5b6d6dSopenharmony_ci 6952e5b6d6dSopenharmony_ciString values can contain C/Java-style escape sequences like `\t`, `\r`, `\n`, 6962e5b6d6dSopenharmony_ci`\xhh`, `\uhhhh` and `\U00hhhhhh`, consistent with the `u_unescape()` C API, see the 6972e5b6d6dSopenharmony_ci[ustring.h](https://unicode-org.github.io/icu-docs/apidoc/released/icu4c/ustring_8h.html) 6982e5b6d6dSopenharmony_ciAPI documentation. 6992e5b6d6dSopenharmony_ci 7002e5b6d6dSopenharmony_ciA literal backslash (\\) in a string value must be doubled (\\\\) or escaped 7012e5b6d6dSopenharmony_ciwith `\x5C` or `\u005C`. 7022e5b6d6dSopenharmony_ci 7032e5b6d6dSopenharmony_ciA literal ASCII double quote (") in a double-quoted string must be escaped with 7042e5b6d6dSopenharmony_ci\\" or `\x22` or `\u0022`. 7052e5b6d6dSopenharmony_ci 7062e5b6d6dSopenharmony_ciYou should also escape carriage return (`\r`) and line feed (`\n`) as well as 7072e5b6d6dSopenharmony_cicontrol codes, non-characters, unassigned code points and other default-invisible 7082e5b6d6dSopenharmony_cicharacters (see the Unicode [UAX #44](https://www.unicode.org/reports/tr44/) 7092e5b6d6dSopenharmony_ci `Default_Ignorable_Code_Point` property). 7102e5b6d6dSopenharmony_ci 7112e5b6d6dSopenharmony_ci### Examples 7122e5b6d6dSopenharmony_ci 7132e5b6d6dSopenharmony_ciThe way to write your resource is to start with a table that has your locale 7142e5b6d6dSopenharmony_ciname. The contents of a table are between the curly brackets: 7152e5b6d6dSopenharmony_ci 7162e5b6d6dSopenharmony_ci``` 7172e5b6d6dSopenharmony_ciroot:table { 7182e5b6d6dSopenharmony_ci} 7192e5b6d6dSopenharmony_ci``` 7202e5b6d6dSopenharmony_ci 7212e5b6d6dSopenharmony_ciThen you can start adding resources to your bundle. Resources on the first level 7222e5b6d6dSopenharmony_cimust be named and we suggest that you specify the type: 7232e5b6d6dSopenharmony_ci 7242e5b6d6dSopenharmony_ci``` 7252e5b6d6dSopenharmony_ciroot:table { 7262e5b6d6dSopenharmony_ci usage:string { "Usage: genrb [Options] files" } 7272e5b6d6dSopenharmony_ci version:int { 122 } 7282e5b6d6dSopenharmony_ci errorcodes:array { 7292e5b6d6dSopenharmony_ci :string { "Invalid argument" } 7302e5b6d6dSopenharmony_ci :string { "File not found" } 7312e5b6d6dSopenharmony_ci } 7322e5b6d6dSopenharmony_ci} 7332e5b6d6dSopenharmony_ci``` 7342e5b6d6dSopenharmony_ci 7352e5b6d6dSopenharmony_ciThe resource bundle format doesn't care about indentation and line breaks. You 7362e5b6d6dSopenharmony_cican continue one string over many lines - you need to have the line break 7372e5b6d6dSopenharmony_cioutside of the string: 7382e5b6d6dSopenharmony_ci 7392e5b6d6dSopenharmony_ci``` 7402e5b6d6dSopenharmony_ciaVeryLongString:string { 7412e5b6d6dSopenharmony_ci "This string is quite long " 7422e5b6d6dSopenharmony_ci "and therefore should be " 7432e5b6d6dSopenharmony_ci "broken into several lines." 7442e5b6d6dSopenharmony_ci} 7452e5b6d6dSopenharmony_ci``` 7462e5b6d6dSopenharmony_ci 7472e5b6d6dSopenharmony_ciFor more examples on syntax, take a look at our resource files for 7482e5b6d6dSopenharmony_ci[locales](https://github.com/unicode-org/icu/blob/main/icu4c/source/data/locales) 7492e5b6d6dSopenharmony_ciand 7502e5b6d6dSopenharmony_ci[test data](https://github.com/unicode-org/icu/blob/main/icu4c/source/test/testdata), 7512e5b6d6dSopenharmony_ciespecially at the 7522e5b6d6dSopenharmony_ci[testtypes resource bundle](https://github.com/unicode-org/icu/blob/main/icu4c/source/test/testdata/testtypes.txt). 7532e5b6d6dSopenharmony_ci 7542e5b6d6dSopenharmony_ci### Making Your Own Resource Bundles 7552e5b6d6dSopenharmony_ci 7562e5b6d6dSopenharmony_ciIn order to make your own resource bundle package, you need to perform several 7572e5b6d6dSopenharmony_cisteps: 7582e5b6d6dSopenharmony_ci 7592e5b6d6dSopenharmony_ci1. Create your root resource bundle. This bundle should contain all the data 7602e5b6d6dSopenharmony_ci for your program. You are probably best off if you fill it with data in your 7612e5b6d6dSopenharmony_ci native language. 7622e5b6d6dSopenharmony_ci 7632e5b6d6dSopenharmony_ci2. Create a chain of empty resource bundles for your native language and 7642e5b6d6dSopenharmony_ci region. For example, if your region is sr_CS, create all the entries in root 7652e5b6d6dSopenharmony_ci in Serbian and leave bundles for sr and sr_CS locales empty. This way, users 7662e5b6d6dSopenharmony_ci of your package will know whether you support a certain locale or not. 7672e5b6d6dSopenharmony_ci 7682e5b6d6dSopenharmony_ci3. If you already have some data to localize, create more bundles with 7692e5b6d6dSopenharmony_ci localized data. 7702e5b6d6dSopenharmony_ci 7712e5b6d6dSopenharmony_ci4. Decide on the name of your package. You will use the package name to access 7722e5b6d6dSopenharmony_ci your resources. 7732e5b6d6dSopenharmony_ci 7742e5b6d6dSopenharmony_ci5. Compile the resource bundles using the `genrb` tool. The command line format 7752e5b6d6dSopenharmony_ci is `genrb [options] list-of-input-files`. Genrb expects that source files 7762e5b6d6dSopenharmony_ci are in invariant encoding and `\uXXXX` characters or UTF-8/UTF-16 with BOM. 7772e5b6d6dSopenharmony_ci If you need to use a different encoding, specify it using the `--encoding` 7782e5b6d6dSopenharmony_ci option. You also need to specify the destination directory name for your 7792e5b6d6dSopenharmony_ci resources using the `--destdir` option. This destination name needs to be the 7802e5b6d6dSopenharmony_ci same as the package name. Full list of options can be retrieved by invoking 7812e5b6d6dSopenharmony_ci `genrb --help`. 7822e5b6d6dSopenharmony_ci 7832e5b6d6dSopenharmony_ci You can also output Java class files. You will need to specify the 7842e5b6d6dSopenharmony_ci `--write-java` option, followed by an optional encoding for the resulting 7852e5b6d6dSopenharmony_ci `.java` file. Default encoding is ASCII + `\uXXXX`. You will also have to 7862e5b6d6dSopenharmony_ci specify the resource bundle name using the `--bundle-name argument`. 7872e5b6d6dSopenharmony_ci 7882e5b6d6dSopenharmony_ci After using `genrb`, you will end up with files of name 7892e5b6d6dSopenharmony_ci `packagename_localename.res`. For example, if you had `root.txt`, `en.txt`, 7902e5b6d6dSopenharmony_ci `en_US.txt`, `es.txt` and you invoked `genrb` using the following command line: 7912e5b6d6dSopenharmony_ci `genrb -d myapplication root.txt en.txt en_US.txt es.txt`, you will end up 7922e5b6d6dSopenharmony_ci with `myapplication/root.res`, `myapplication/en.res`, etc. The forward slash can 7932e5b6d6dSopenharmony_ci be a back slash on some platforms, like Windows. These files are now ready 7942e5b6d6dSopenharmony_ci to use and you can open them using `ures_open("myapplication", "en_US", err);`. 7952e5b6d6dSopenharmony_ci 7962e5b6d6dSopenharmony_ci6. However, you might want to have only one file containing all the data. In 7972e5b6d6dSopenharmony_ci that case you need to use the package data tool. It can produce either a 7982e5b6d6dSopenharmony_ci memory mapped file or a dynamically linked library. For more information on 7992e5b6d6dSopenharmony_ci how to use package data tool, see the appropriate [section](../icudata.md). 8002e5b6d6dSopenharmony_ci 8012e5b6d6dSopenharmony_ciRolling out your own data takes some practice, especially if you want to package 8022e5b6d6dSopenharmony_ciit all together. You might want to take a look at how we package data. Good 8032e5b6d6dSopenharmony_ciplaces to start (except of course ICU's own 8042e5b6d6dSopenharmony_ci[data](https://github.com/unicode-org/icu/blob/main/icu4c/source/data/)) are 8052e5b6d6dSopenharmony_ci[source/test/testdata/](https://github.com/unicode-org/icu/blob/main/icu4c/source/test/testdata/) 8062e5b6d6dSopenharmony_ciand 8072e5b6d6dSopenharmony_ci[source/samples/ufortune/resources/](https://github.com/unicode-org/icu/blob/main/icu4c/source/samples/ufortune/resources/) 8082e5b6d6dSopenharmony_cidirectories. 8092e5b6d6dSopenharmony_ci 8102e5b6d6dSopenharmony_ciAlso, here is a sample Windows batch file that does compiling and packing of 8112e5b6d6dSopenharmony_ciseveral resources: 8122e5b6d6dSopenharmony_ci 8132e5b6d6dSopenharmony_ci```bat 8142e5b6d6dSopenharmony_cigenrb -d myapplication root.txt en.txt en_GB.txt fr.txt es.txt es_ES.txt 8152e5b6d6dSopenharmony_ciecho root.res en.res en_GB.res fr.res es.res es_ES.res > packagelist.txt 8162e5b6d6dSopenharmony_cimkdir tmpdir 8172e5b6d6dSopenharmony_cipkgdata -p myapplication -T tmpdir -m common packagelist.txt 8182e5b6d6dSopenharmony_ci``` 8192e5b6d6dSopenharmony_ci 8202e5b6d6dSopenharmony_ciIt is also possible to use the `icupkg` tool instead of `pkgdata` to generate .dat 8212e5b6d6dSopenharmony_cidata archives. The `icupkg` tool became available in ICU4C 3.6. If you need the 8222e5b6d6dSopenharmony_cidata in a shared or static library, you still need to use the `pkgdata` tool. For 8232e5b6d6dSopenharmony_cieasier maintenance, packaging, installation and application patching, it's 8242e5b6d6dSopenharmony_cirecommended that you use .dat data archives. 8252e5b6d6dSopenharmony_ci 8262e5b6d6dSopenharmony_ci### Using XLIFF for Localization 8272e5b6d6dSopenharmony_ci 8282e5b6d6dSopenharmony_ciICU provides tool that allow for converting resource bundles to and from XLIFF 8292e5b6d6dSopenharmony_ciformat. Files in XLIFF format can contain translations of resources. In that 8302e5b6d6dSopenharmony_cicase, more than one resulting resource bundle will be constructed. 8312e5b6d6dSopenharmony_ci 8322e5b6d6dSopenharmony_ciTo produce a XLIFF file from a resource bundle, use the `-x` option of `genrb` tool 8332e5b6d6dSopenharmony_cifrom ICU4C. Assume that we want to convert a simple resource bundle to the XLIFF 8342e5b6d6dSopenharmony_ciformat: 8352e5b6d6dSopenharmony_ci 8362e5b6d6dSopenharmony_ci``` 8372e5b6d6dSopenharmony_ciroot { 8382e5b6d6dSopenharmony_ci usage {"usage: ufortune [-v] [-l locale]"} 8392e5b6d6dSopenharmony_ci optionMessage {"unrecognized command line option:"} 8402e5b6d6dSopenharmony_ci} 8412e5b6d6dSopenharmony_ci``` 8422e5b6d6dSopenharmony_ci 8432e5b6d6dSopenharmony_ciTo get a XLIFF file, we need to call genrb like this: `genrb -x -l en root.txt`. 8442e5b6d6dSopenharmony_ciOption `-x` tells `genrb` to produce XLIFF file, option `-l` specifies the language of 8452e5b6d6dSopenharmony_cithe resource. If the language is not specified, `genrb` will try to deduce the 8462e5b6d6dSopenharmony_cilanguage from the resource name (en, zh, sh). If the resource name is not an ISO 8472e5b6d6dSopenharmony_cilanguage code (root), default language for the platform will be used. Language 8482e5b6d6dSopenharmony_ciwill be a source attribute for all the translation units. XLIFF file produced 8492e5b6d6dSopenharmony_cifrom the resource above will be named `root.xlf` and will look like this: 8502e5b6d6dSopenharmony_ci 8512e5b6d6dSopenharmony_ci```xml 8522e5b6d6dSopenharmony_ci<?xml version="1.0" encoding="utf-8"?> 8532e5b6d6dSopenharmony_ci<xliff version = "1.1 "xmlns = 'urn:oasis:names:tc:xliff:document:1.1' 8542e5b6d6dSopenharmony_cixmlns:xsi = 'http://www.w3.org/2001/XMLSchema-instance' 8552e5b6d6dSopenharmony_cixsi:schemaLocation='urn:oasis:names:tc:xliff:document:1.1 8562e5b6d6dSopenharmony_cihttp://www.oasis-open.org/committees/xliff/documents/xliff-core-1.1.xsd'> 8572e5b6d6dSopenharmony_ci <file xml:space = "preserve" source-language = "en” 8582e5b6d6dSopenharmony_ci datatype = "x-icu-resource-bundle" original = "root.txt" 8592e5b6d6dSopenharmony_ci date = "2007-08-17T21:17:08Z"> 8602e5b6d6dSopenharmony_ci <header> 8612e5b6d6dSopenharmony_ci <tool tool-id = "genrb-3.3-icu-3.8" tool-name = "genrb"/> 8622e5b6d6dSopenharmony_ci </header> 8632e5b6d6dSopenharmony_ci <body> 8642e5b6d6dSopenharmony_ci <group id = "root" restype = "x-icu-table"> 8652e5b6d6dSopenharmony_ci <trans-unit id = "optionMessage" resname = "optionMessage"> 8662e5b6d6dSopenharmony_ci <source>unrecognized command line option:</source> 8672e5b6d6dSopenharmony_ci </trans-unit> 8682e5b6d6dSopenharmony_ci <trans-unit id = "usage" resname = "usage"> 8692e5b6d6dSopenharmony_ci <source>usage: ufortune [-v] [-l locale]</source> 8702e5b6d6dSopenharmony_ci </trans-unit> 8712e5b6d6dSopenharmony_ci </group> 8722e5b6d6dSopenharmony_ci </body> 8732e5b6d6dSopenharmony_ci </file> 8742e5b6d6dSopenharmony_ci</xliff> 8752e5b6d6dSopenharmony_ci``` 8762e5b6d6dSopenharmony_ci 8772e5b6d6dSopenharmony_ciThis file can be sent to translators. Using translation tools that support 8782e5b6d6dSopenharmony_ciXLIFF, translators will produce one or more translations for this resource. 8792e5b6d6dSopenharmony_ciProcessed file might look a bit like this: 8802e5b6d6dSopenharmony_ci 8812e5b6d6dSopenharmony_ci```xml 8822e5b6d6dSopenharmony_ci<?xml version="1.0" encoding="utf-8"?> 8832e5b6d6dSopenharmony_ci<xliff version = "1.1" xmlns='urn:oasis:names:tc:xliff:document:1.1' 8842e5b6d6dSopenharmony_cixmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' 8852e5b6d6dSopenharmony_ci xsi:schemaLocation='urn:oasis:names:tc:xliff:document:1.1 8862e5b6d6dSopenharmony_cihttp://www.oasis-open.org/committees/xliff/documents/xliff-core-1.1.xsd'> 8872e5b6d6dSopenharmony_ci <file xml:space = "preserve" source-language = "en" target-language = "sh" 8882e5b6d6dSopenharmony_ci datatype = "x-icu-resource-bundle" original = "root.txt" 8892e5b6d6dSopenharmony_ci date = "2007-08-17T21:17:08Z"> 8902e5b6d6dSopenharmony_ci <header> 8912e5b6d6dSopenharmony_ci <tool tool-id = "genrb-3.3-icu-3.8" tool-name = "genrb"/> 8922e5b6d6dSopenharmony_ci </header> 8932e5b6d6dSopenharmony_ci <body> 8942e5b6d6dSopenharmony_ci <group id = "root" restype = "x-icu-table"> 8952e5b6d6dSopenharmony_ci <trans-unit id = "optionMessage" resname = "optionMessage"> 8962e5b6d6dSopenharmony_ci <source>unrecognized command line option:</source> 8972e5b6d6dSopenharmony_ci <target>nepoznata opcija na komandnoj liniji:</target> 8982e5b6d6dSopenharmony_ci </trans-unit> 8992e5b6d6dSopenharmony_ci <trans-unit id = "usage" resname = "usage"> 9002e5b6d6dSopenharmony_ci <source>usage: ufortune [-v] [-l locale]</source> 9012e5b6d6dSopenharmony_ci <target>upotreba: ufortune [-v] [-l lokal]</target> 9022e5b6d6dSopenharmony_ci </trans-unit> 9032e5b6d6dSopenharmony_ci </group> 9042e5b6d6dSopenharmony_ci </body> 9052e5b6d6dSopenharmony_ci </file> 9062e5b6d6dSopenharmony_ci</xliff> 9072e5b6d6dSopenharmony_ci``` 9082e5b6d6dSopenharmony_ci 9092e5b6d6dSopenharmony_ciIn order to convert this file to a set of resource bundle files, we need to use 9102e5b6d6dSopenharmony_ciICU4J's `com.ibm.icu.dev.tool.localeconverter.XLIFF2ICUConverter` class. 9112e5b6d6dSopenharmony_ci 9122e5b6d6dSopenharmony_ci> :point_right: **Note**: XLIFF2ICUConverter class relies on XML parser being 9132e5b6d6dSopenharmony_ci> available. JDK 1.4 and newer provide a XML parser out of box. For earlier 9142e5b6d6dSopenharmony_ci> versions, you will need to install xerces. 9152e5b6d6dSopenharmony_ci 9162e5b6d6dSopenharmony_ciCommand line for running XLIFF2ICUConverter should specify the file than needs 9172e5b6d6dSopenharmony_cito be converted, sh.xlf in this case. Optionally, you can specify input and 9182e5b6d6dSopenharmony_cioutput directories as well as the package name. After running this tool, two 9192e5b6d6dSopenharmony_cifiles will be produced: en.txt and sh.txt. This is how they would look like: 9202e5b6d6dSopenharmony_ci 9212e5b6d6dSopenharmony_ci``` 9222e5b6d6dSopenharmony_ci// *************************************************************************** 9232e5b6d6dSopenharmony_ci// * 9242e5b6d6dSopenharmony_ci// * Tool: com.ibm.icu.dev.tool.localeconverter.XLIFF2ICUConverter.java 9252e5b6d6dSopenharmony_ci// * Date & Time: 08/17/2007 11:33:54 AM HST 9262e5b6d6dSopenharmony_ci// * Source File: C:\trunk\icuhtml\userguide\xliff\sh.xlf 9272e5b6d6dSopenharmony_ci// * 9282e5b6d6dSopenharmony_ci// *************************************************************************** 9292e5b6d6dSopenharmony_cien:table{ 9302e5b6d6dSopenharmony_ci optionMessage:string{"unrecognized command line option:"} 9312e5b6d6dSopenharmony_ci usage:string{"usage: ufortune [-v] [-l locale]"} 9322e5b6d6dSopenharmony_ci} 9332e5b6d6dSopenharmony_ci``` 9342e5b6d6dSopenharmony_ci 9352e5b6d6dSopenharmony_ciand 9362e5b6d6dSopenharmony_ci 9372e5b6d6dSopenharmony_ci``` 9382e5b6d6dSopenharmony_ci// *************************************************************************** 9392e5b6d6dSopenharmony_ci// * 9402e5b6d6dSopenharmony_ci// * Tool: com.ibm.icu.dev.tool.localeconverter.XLIFF2ICUConverter.java 9412e5b6d6dSopenharmony_ci// * Date & Time: 08/17/2007 11:33:54 AM HST 9422e5b6d6dSopenharmony_ci// * Source File: C:\trunk\icuhtml\userguide\xliff\sh.xlf 9432e5b6d6dSopenharmony_ci// * 9442e5b6d6dSopenharmony_ci// *************************************************************************** 9452e5b6d6dSopenharmony_cish:table{ 9462e5b6d6dSopenharmony_ci optionMessage:string{"nepoznata opcija na komandnoj liniji:"} 9472e5b6d6dSopenharmony_ci usage:string{"upotreba: ufortune [-v] [-l lokal]"} 9482e5b6d6dSopenharmony_ci} 9492e5b6d6dSopenharmony_ci``` 9502e5b6d6dSopenharmony_ci 9512e5b6d6dSopenharmony_ciThese files can be then used as all the other resource bundle files. 952