i18n.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. /** BEGIN COPYRIGHT BLOCK
  2. * This Program is free software; you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation; version 2 of the License.
  5. *
  6. * This Program is distributed in the hope that it will be useful, but WITHOUT
  7. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  8. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  9. *
  10. * You should have received a copy of the GNU General Public License along with
  11. * this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
  12. * Place, Suite 330, Boston, MA 02111-1307 USA.
  13. *
  14. * In addition, as a special exception, Red Hat, Inc. gives You the additional
  15. * right to link the code of this Program with code not covered under the GNU
  16. * General Public License ("Non-GPL Code") and to distribute linked combinations
  17. * including the two, subject to the limitations in this paragraph. Non-GPL Code
  18. * permitted under this exception must only link to the code of this Program
  19. * through those well defined interfaces identified in the file named EXCEPTION
  20. * found in the source code files (the "Approved Interfaces"). The files of
  21. * Non-GPL Code may instantiate templates or use macros or inline functions from
  22. * the Approved Interfaces without causing the resulting work to be covered by
  23. * the GNU General Public License. Only Red Hat, Inc. may make changes or
  24. * additions to the list of Approved Interfaces. You must obey the GNU General
  25. * Public License in all respects for all of the Program code and other code used
  26. * in conjunction with the Program except the Non-GPL Code covered by this
  27. * exception. If you modify this file, you may extend this exception to your
  28. * version of the file, but you are not obligated to do so. If you do not wish to
  29. * provide this exception without modification, you must delete this exception
  30. * statement from your version and license this file solely under the GPL without
  31. * exception.
  32. *
  33. *
  34. * Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
  35. * Copyright (C) 2005 Red Hat, Inc.
  36. * All rights reserved.
  37. * END COPYRIGHT BLOCK **/
  38. #ifdef HAVE_CONFIG_H
  39. # include <config.h>
  40. #endif
  41. #ifndef I18N_H
  42. #define I18N_H
  43. /* Make NSAPI_PUBLIC available */
  44. #include "base/systems.h"
  45. /* This stuff was copied from libadminutil/resource.h so we could
  46. remove the dependency on adminutil which is not being open sourced
  47. this first round.
  48. */
  49. #ifndef COPIED_FROM_LIBADMINUTIL_RESOURCE_H
  50. /* Resource contains the name of the
  51. property file w/ paht information
  52. */
  53. typedef struct
  54. {
  55. char *path;
  56. char *package;
  57. void *propset;
  58. } Resource;
  59. /*******************************************************************************/
  60. /*
  61. * this table contains library name
  62. * (stored in the first string entry, with id=0),
  63. * and the id/string pairs which are used by library
  64. */
  65. typedef struct res_RESOURCE_TABLE
  66. {
  67. int id;
  68. char *str;
  69. } res_RESOURCE_TABLE;
  70. /*******************************************************************************/
  71. /*
  72. * resource global contains resource table list which is used
  73. * to generate the database.
  74. * Also used for "in memory" version of XP_GetStringFromDatabase()
  75. */
  76. typedef struct res_RESOURCE_GLOBAL
  77. {
  78. res_RESOURCE_TABLE *restable;
  79. } res_RESOURCE_GLOBAL;
  80. /*******************************************************************************/
  81. /*
  82. * Define the ResDef macro to simplify the maintenance of strings which are to
  83. * be added to the library or application header file (dbtxxx.h). This enables
  84. * source code to refer to the strings by theit TokenNames, and allows the
  85. * strings to be stored in the database.
  86. *
  87. * Usage: ResDef(TokenName,TokenValue,String)
  88. *
  89. * Example: ResDef(DBT_HelloWorld_, \
  90. * 1,"Hello, World!")
  91. * ResDef(DBT_TheCowJumpedOverTheMoon_, \
  92. * 2,"The cow jumped over the moon.")
  93. * ResDef(DBT_TheValueOfPiIsAbout31415926536_, \
  94. * 3,"The value of PI is about 3.1415926536."
  95. *
  96. * RESOURCE_STR is used by makstrdb.c only. It is not used by getstrdb.c or
  97. * in library or application source code.
  98. */
  99. #ifdef RESOURCE_STR
  100. #define BEGIN_STR(argLibraryName) \
  101. RESOURCE_TABLE argLibraryName[] = { 0, #argLibraryName,
  102. #define ResDef(argToken,argID,argString) \
  103. argID, argString,
  104. #define END_STR(argLibraryName) \
  105. 0, 0 };
  106. #else
  107. #define BEGIN_STR(argLibraryName) \
  108. enum {
  109. #define ResDef(argToken,argID,argString) \
  110. argToken = argID,
  111. #define END_STR(argLibraryName) \
  112. argLibraryName ## top };
  113. #endif
  114. #endif /* COPIED_FROM_LIBADMINUTIL_RESOURCE_H */
  115. typedef res_RESOURCE_TABLE RESOURCE_TABLE;
  116. typedef res_RESOURCE_GLOBAL RESOURCE_GLOBAL;
  117. /*******************************************************************************/
  118. /*
  119. * In accordance with the recommendations in the
  120. * "Netscape Coding Standard for Server Internationalization",
  121. * the following aliases are defined for fprintf, et al., and
  122. * these aliases should be used to clearly indicate the intended
  123. * destination for output.
  124. */
  125. #define AdminFprintf fprintf
  126. #define DebugFprintf fprintf
  127. #define ClientSprintf sprintf
  128. #define AdminSprintf sprintf
  129. #define DebugSprintf sprintf
  130. #define ClientFputs fputs
  131. #define AdminFputs fputs
  132. #define DebugFputs fputs
  133. /* more #define, as needed */
  134. /*******************************************************************************/
  135. /*
  136. * Function prototypes for application and libraries
  137. */
  138. #ifdef __cplusplus
  139. extern "C"
  140. {
  141. #endif
  142. /***************************/
  143. /* XP_InitStringDatabase() */
  144. /***************************/
  145. NSAPI_PUBLIC
  146. void
  147. XP_InitStringDatabase(char* pathCWD, char* databaseName);
  148. /* Initialize the resource string database */
  149. /******************************/
  150. /* XP_GetStringFromDatabase() */
  151. /******************************/
  152. NSAPI_PUBLIC
  153. extern char*
  154. XP_GetStringFromDatabase(char* strLibraryName,
  155. char* strLanguage,
  156. int iToken);
  157. /* Given the LibraryName, Language and Token, extracts the string corresponding
  158. to that library and token from the database in the language requested and
  159. returns a pointer to the string. Note: Use the macros XP_GetClientStr() and
  160. XP_GetAdminStr() defined below to simplify source code. */
  161. /*****************/
  162. /* SetLanguage() */
  163. /*****************/
  164. enum
  165. {
  166. CLIENT_LANGUAGE,
  167. ADMIN_LANGUAGE,
  168. DEFAULT_LANGUAGE
  169. };
  170. NSAPI_PUBLIC
  171. extern void
  172. SetLanguage(int type, char *language);
  173. /* Set language for Client, Admin and Default, XP_GetStringFromDatabase will
  174. base on the setting to retrieve correct string for specific language */
  175. /***********************/
  176. /* GetClientLanguage() */
  177. /***********************/
  178. NSAPI_PUBLIC
  179. extern char*
  180. GetClientLanguage(void);
  181. /* Returns a pointer to a string with the name of the language requested by
  182. the current client; intended to be passed to XP_GetStringFromDatabase()
  183. and used by the front end macro XP_GetClientStr(). */
  184. /**********************/
  185. /* GetAdminLanguage() */
  186. /**********************/
  187. NSAPI_PUBLIC
  188. extern char*
  189. GetAdminLanguage(void);
  190. /* Returns a pointer to a string with the name of the language requested by
  191. the administrator; intended to be passed to XP_GetStringFromDatabase()
  192. and used by the front end macro XP_GetAdminStr(). */
  193. /************************/
  194. /* GetDefaultLanguage() */
  195. /************************/
  196. NSAPI_PUBLIC
  197. extern char*
  198. GetDefaultLanguage(void);
  199. /* Returns a pointer to a string with the name of the default language
  200. for the installation from the configuration file. */
  201. /************************/
  202. /* GetFileForLanguage() */
  203. /************************/
  204. NSAPI_PUBLIC
  205. int
  206. GetFileForLanguage(char* filepath,char* language,char* existingFilepath);
  207. /* Looks for a file in the appropriate language.
  208. Input: filePath,language
  209. filePath is of the form "/xxx/xxx/$$LANGDIR/xxx/xxx/filename"
  210. or of the form "/xxx/xxx/xxx/xxx/filename".
  211. filename may or may not have an extension.
  212. language is an Accept-Language list; each language-range will be
  213. tried as a subdirectory name and possibly as a filename modifier.
  214. "*" is ignored - default always provided if needed.
  215. "-" is replaced by "_".
  216. $$LANGDIR is a special string replaced by language. It is optional.
  217. For the default case, $$LANGDIR/ is replaced by nothing
  218. (so // is not created).
  219. Returned: existingPath
  220. existingFilePath is the path of a satisfactory, existing file.
  221. if no file is found, an empty string "" is returned.
  222. int returned: -1 if no file found (existingFilePath = "")
  223. 0 if default file is returned
  224. 1 if language file is returned (any in list) */
  225. /********************/
  226. /* XP_AccLangList() */
  227. /********************/
  228. #define MAX_ACCEPT_LANGUAGE 16
  229. #define MAX_ACCEPT_LENGTH 18
  230. typedef char ACCEPT_LANGUAGE_LIST[MAX_ACCEPT_LANGUAGE][MAX_ACCEPT_LENGTH];
  231. NSAPI_PUBLIC
  232. int
  233. XP_AccLangList(char* AcceptLanguage,
  234. ACCEPT_LANGUAGE_LIST AcceptLanguageList);
  235. #ifdef __cplusplus
  236. }
  237. #endif
  238. /*******************************************************************************/
  239. /*
  240. * Function prototypes for building string database
  241. */
  242. extern int XP_MakeStringDatabase(void);
  243. /* Used to create the string database at build time; not used by the application
  244. itself. Returns 0 is successful. */
  245. extern void XP_PrintStringDatabase(void);
  246. /* DEBUG: Prints out entire string database to standard output. */
  247. /*******************************************************************************/
  248. /*
  249. * Macros to simplify calls to XP_GetStringFromDatabase
  250. * (need one argument instead of three)
  251. */
  252. #define XP_GetClientStr(DBTTokenName) \
  253. XP_GetStringFromDatabase(LIBRARY_NAME, \
  254. GetClientLanguage(), \
  255. DBTTokenName)
  256. #define XP_GetAdminStr(DBTTokenName) \
  257. XP_GetStringFromDatabase(LIBRARY_NAME, \
  258. "en", \
  259. DBTTokenName)
  260. /*******************************************************************************/
  261. #endif