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