ucat.h 5.2 KB

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