sl@0: /* sl@0: ********************************************************************** sl@0: * Copyright (c) 2003-2004, International Business Machines sl@0: * Corporation and others. All Rights Reserved. sl@0: ********************************************************************** sl@0: * Author: Alan Liu sl@0: * Created: March 19 2003 sl@0: * Since: ICU 2.6 sl@0: ********************************************************************** sl@0: */ sl@0: #ifndef UCAT_H sl@0: #define UCAT_H sl@0: sl@0: #include "unicode/utypes.h" sl@0: #include "unicode/ures.h" sl@0: sl@0: /** sl@0: * \file sl@0: * \brief C API: Message Catalog Wrappers sl@0: * sl@0: * This C API provides look-alike functions that deliberately resemble sl@0: * the POSIX catopen, catclose, and catgets functions. The underlying sl@0: * implementation is in terms of ICU resource bundles, rather than sl@0: * POSIX message catalogs. sl@0: * sl@0: * The ICU resource bundles obey standard ICU inheritance policies. sl@0: * To facilitate this, sets and messages are flattened into one tier. sl@0: * This is done by creating resource bundle keys of the form sl@0: * <set_num>%<msg_num> where set_num is the set number and msg_num is sl@0: * the message number, formatted as decimal strings. sl@0: * sl@0: * Example: Consider a message catalog containing two sets: sl@0: * sl@0: * Set 1: Message 4 = "Good morning." sl@0: * Message 5 = "Good afternoon." sl@0: * Message 7 = "Good evening." sl@0: * Message 8 = "Good night." sl@0: * Set 4: Message 14 = "Please " sl@0: * Message 19 = "Thank you." sl@0: * Message 20 = "Sincerely," sl@0: * sl@0: * The ICU resource bundle source file would, assuming it is named sl@0: * "greet.txt", would look like this: sl@0: * sl@0: * greet sl@0: * { sl@0: * 1%4 { "Good morning." } sl@0: * 1%5 { "Good afternoon." } sl@0: * 1%7 { "Good evening." } sl@0: * 1%8 { "Good night." } sl@0: * sl@0: * 4%14 { "Please " } sl@0: * 4%19 { "Thank you." } sl@0: * 4%20 { "Sincerely," } sl@0: * } sl@0: * sl@0: * The catgets function is commonly used in combination with functions sl@0: * like printf and strftime. ICU components like message format can sl@0: * be used instead, although they use a different format syntax. sl@0: * There is an ICU package, icuio, that provides some of sl@0: * the POSIX-style formatting API. sl@0: */ sl@0: sl@0: U_CDECL_BEGIN sl@0: sl@0: /** sl@0: * An ICU message catalog descriptor, analogous to nl_catd. sl@0: * sl@0: * @stable ICU 2.6 sl@0: */ sl@0: typedef UResourceBundle* u_nl_catd; sl@0: sl@0: /** sl@0: * Open and return an ICU message catalog descriptor. The descriptor sl@0: * may be passed to u_catgets() to retrieve localized strings. sl@0: * sl@0: * @param name string containing the full path pointing to the sl@0: * directory where the resources reside followed by the package name sl@0: * e.g. "/usr/resource/my_app/resources/guimessages" on a Unix system. sl@0: * If NULL, ICU default data files will be used. sl@0: * sl@0: * Unlike POSIX, environment variables are not interpolated within the sl@0: * name. sl@0: * sl@0: * @param locale the locale for which we want to open the resource. If sl@0: * NULL, the default ICU locale will be used (see uloc_getDefault). If sl@0: * strlen(locale) == 0, the root locale will be used. sl@0: * sl@0: * @param ec input/output error code. Upon output, sl@0: * U_USING_FALLBACK_WARNING indicates that a fallback locale was sl@0: * used. For example, 'de_CH' was requested, but nothing was found sl@0: * there, so 'de' was used. U_USING_DEFAULT_WARNING indicates that the sl@0: * default locale data or root locale data was used; neither the sl@0: * requested locale nor any of its fallback locales were found. sl@0: * sl@0: * @return a message catalog descriptor that may be passed to sl@0: * u_catgets(). If the ec parameter indicates success, then the caller sl@0: * is responsible for calling u_catclose() to close the message sl@0: * catalog. If the ec parameter indicates failure, then NULL will be sl@0: * returned. sl@0: * sl@0: * @stable ICU 2.6 sl@0: */ sl@0: U_STABLE u_nl_catd U_EXPORT2 sl@0: u_catopen(const char* name, const char* locale, UErrorCode* ec); sl@0: sl@0: /** sl@0: * Close an ICU message catalog, given its descriptor. sl@0: * sl@0: * @param catd a message catalog descriptor to be closed. May be NULL, sl@0: * in which case no action is taken. sl@0: * sl@0: * @stable ICU 2.6 sl@0: */ sl@0: U_STABLE void U_EXPORT2 sl@0: u_catclose(u_nl_catd catd); sl@0: sl@0: /** sl@0: * Retrieve a localized string from an ICU message catalog. sl@0: * sl@0: * @param catd a message catalog descriptor returned by u_catopen. sl@0: * sl@0: * @param set_num the message catalog set number. Sets need not be sl@0: * numbered consecutively. sl@0: * sl@0: * @param msg_num the message catalog message number within the sl@0: * set. Messages need not be numbered consecutively. sl@0: * sl@0: * @param s the default string. This is returned if the string sl@0: * specified by the set_num and msg_num is not found. It must be sl@0: * zero-terminated. sl@0: * sl@0: * @param len fill-in parameter to receive the length of the result. sl@0: * May be NULL, in which case it is ignored. sl@0: * sl@0: * @param ec input/output error code. May be U_USING_FALLBACK_WARNING sl@0: * or U_USING_DEFAULT_WARNING. U_MISSING_RESOURCE_ERROR indicates that sl@0: * the set_num/msg_num tuple does not specify a valid message string sl@0: * in this catalog. sl@0: * sl@0: * @return a pointer to a zero-terminated UChar array which lives in sl@0: * an internal buffer area, typically a memory mapped/DLL file. The sl@0: * caller must NOT delete this pointer. If the call is unsuccessful sl@0: * for any reason, then s is returned. This includes the situation in sl@0: * which ec indicates a failing error code upon entry to this sl@0: * function. sl@0: * sl@0: * @stable ICU 2.6 sl@0: */ sl@0: U_STABLE const UChar* U_EXPORT2 sl@0: u_catgets(u_nl_catd catd, int32_t set_num, int32_t msg_num, sl@0: const UChar* s, sl@0: int32_t* len, UErrorCode* ec); sl@0: sl@0: U_CDECL_END sl@0: sl@0: #endif /*UCAT_H*/ sl@0: /*eof*/