ucat.h 5.3 KB

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