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