2 **********************************************************************
3 * Copyright (c) 2003-2004, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 **********************************************************************
7 * Created: March 19 2003
9 **********************************************************************
14 #include "unicode/utypes.h"
15 #include "unicode/ures.h"
19 * \brief C API: Message Catalog Wrappers
21 * This C API provides look-alike functions that deliberately resemble
22 * the POSIX catopen, catclose, and catgets functions. The underlying
23 * implementation is in terms of ICU resource bundles, rather than
24 * POSIX message catalogs.
26 * The ICU resource bundles obey standard ICU inheritance policies.
27 * To facilitate this, sets and messages are flattened into one tier.
28 * This is done by creating resource bundle keys of the form
29 * <set_num>%<msg_num> where set_num is the set number and msg_num is
30 * the message number, formatted as decimal strings.
32 * Example: Consider a message catalog containing two sets:
34 * Set 1: Message 4 = "Good morning."
35 * Message 5 = "Good afternoon."
36 * Message 7 = "Good evening."
37 * Message 8 = "Good night."
38 * Set 4: Message 14 = "Please "
39 * Message 19 = "Thank you."
40 * Message 20 = "Sincerely,"
42 * The ICU resource bundle source file would, assuming it is named
43 * "greet.txt", would look like this:
47 * 1%4 { "Good morning." }
48 * 1%5 { "Good afternoon." }
49 * 1%7 { "Good evening." }
50 * 1%8 { "Good night." }
53 * 4%19 { "Thank you." }
54 * 4%20 { "Sincerely," }
57 * The catgets function is commonly used in combination with functions
58 * like printf and strftime. ICU components like message format can
59 * be used instead, although they use a different format syntax.
60 * There is an ICU package, icuio, that provides some of
61 * the POSIX-style formatting API.
67 * An ICU message catalog descriptor, analogous to nl_catd.
71 typedef UResourceBundle
* u_nl_catd
;
74 * Open and return an ICU message catalog descriptor. The descriptor
75 * may be passed to u_catgets() to retrieve localized strings.
77 * @param name string containing the full path pointing to the
78 * directory where the resources reside followed by the package name
79 * e.g. "/usr/resource/my_app/resources/guimessages" on a Unix system.
80 * If NULL, ICU default data files will be used.
82 * Unlike POSIX, environment variables are not interpolated within the
85 * @param locale the locale for which we want to open the resource. If
86 * NULL, the default ICU locale will be used (see uloc_getDefault). If
87 * strlen(locale) == 0, the root locale will be used.
89 * @param ec input/output error code. Upon output,
90 * U_USING_FALLBACK_WARNING indicates that a fallback locale was
91 * used. For example, 'de_CH' was requested, but nothing was found
92 * there, so 'de' was used. U_USING_DEFAULT_WARNING indicates that the
93 * default locale data or root locale data was used; neither the
94 * requested locale nor any of its fallback locales were found.
96 * @return a message catalog descriptor that may be passed to
97 * u_catgets(). If the ec parameter indicates success, then the caller
98 * is responsible for calling u_catclose() to close the message
99 * catalog. If the ec parameter indicates failure, then NULL will be
104 U_STABLE u_nl_catd U_EXPORT2
105 u_catopen(const char* name
, const char* locale
, UErrorCode
* ec
);
108 * Close an ICU message catalog, given its descriptor.
110 * @param catd a message catalog descriptor to be closed. May be NULL,
111 * in which case no action is taken.
115 U_STABLE
void U_EXPORT2
116 u_catclose(u_nl_catd catd
);
119 * Retrieve a localized string from an ICU message catalog.
121 * @param catd a message catalog descriptor returned by u_catopen.
123 * @param set_num the message catalog set number. Sets need not be
124 * numbered consecutively.
126 * @param msg_num the message catalog message number within the
127 * set. Messages need not be numbered consecutively.
129 * @param s the default string. This is returned if the string
130 * specified by the set_num and msg_num is not found. It must be
133 * @param len fill-in parameter to receive the length of the result.
134 * May be NULL, in which case it is ignored.
136 * @param ec input/output error code. May be U_USING_FALLBACK_WARNING
137 * or U_USING_DEFAULT_WARNING. U_MISSING_RESOURCE_ERROR indicates that
138 * the set_num/msg_num tuple does not specify a valid message string
141 * @return a pointer to a zero-terminated UChar array which lives in
142 * an internal buffer area, typically a memory mapped/DLL file. The
143 * caller must NOT delete this pointer. If the call is unsuccessful
144 * for any reason, then s is returned. This includes the situation in
145 * which ec indicates a failing error code upon entry to this
150 U_STABLE
const UChar
* U_EXPORT2
151 u_catgets(u_nl_catd catd
, int32_t set_num
, int32_t msg_num
,
153 int32_t* len
, UErrorCode
* ec
);