You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

128 lines
3.4 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /* Internationalization support routines header.
  2. Copyright by Salvador E. Tropea (SET) (2003)
  3. Covered by the GPL license. */
  4. /* The dummies are in nointl.h to make this header less complex */
  5. #ifndef TVIntl_Included
  6. #define TVIntl_Included
  7. #ifdef FORCE_INTL_SUPPORT
  8. #define HAVE_INTL_SUPPORT 1
  9. #else
  10. #include <tv/configtv.h>
  11. #endif
  12. #ifndef HAVE_INTL_SUPPORT
  13. #include <tv/nointl.h>
  14. #else
  15. #ifdef __cplusplus
  16. struct stTVIntl
  17. {
  18. char *translation;
  19. int cp;
  20. };
  21. class TVIntl
  22. {
  23. public:
  24. TVIntl() {};
  25. // Set the domain or catalog of translations (usually the name of the program)
  26. static const char *textDomain(const char *domainname);
  27. // Indicate a directory to search for catalogs
  28. static const char *bindTextDomain(const char *domainname, const char *dirname);
  29. // Translate the message
  30. static const char *getText(const char *msgid);
  31. // What we think is a good way to initialize the domain
  32. static int autoInit(const char *package, const char *localeDir=NULL);
  33. // Special (and tricky members)
  34. // Set the encoding for the catalog
  35. static void setCatalogEncoding(int cp) { forcedCatalogEncoding=cp; };
  36. // Dis/Enable translations
  37. static void enableTranslations() { initialize(); };
  38. static void disableTranslations() { translate=0; };
  39. // Returns a newly allocated string and translated (if enabled)
  40. static char *getTextNew(const char *msgid, Boolean onlyIntl=False);
  41. static const char *getText(const char *msgid, stTVIntl *&cache);
  42. static void freeSt(stTVIntl *&cache);
  43. static stTVIntl *emptySt();
  44. static stTVIntl *dontTranslateSt();
  45. // Replacements that translates and recodes the format string
  46. static int snprintf(char *dest, size_t sz, const char *fmt, ...);
  47. #ifdef Uses_intl_fprintf
  48. static int fprintf(FILE *f, const char *fmt, ...);
  49. #endif
  50. protected:
  51. // Enable translations
  52. static char translate;
  53. // Class already initialized
  54. static char initialized;
  55. // Indicates if the catalog must be recoded to match the application code page.
  56. static char needsRecode;
  57. // Used to change the implicit encoding
  58. static int forcedCatalogEncoding;
  59. // Assumed catalog encoding. This is OS independent and is an arbitrary
  60. // criteria for TV. It makes easier to create portable programs.
  61. static int catalogEncoding;
  62. // Default encodings used for TV. Defined only for the available translations.
  63. static const char *defaultEncodingNames[];
  64. static int defaultEncodings[];
  65. static void *previousCPCallBack;
  66. static uchar recodeTable[256];
  67. static void initialize();
  68. static void codePageCB(ushort *map);
  69. static void recodeStr(char *str, int len);
  70. };
  71. #ifndef _
  72. #define _(msg) TVIntl::getText(msg)
  73. #endif
  74. #ifndef __
  75. #define __(msg) (msg)
  76. #endif
  77. #ifndef BINDTEXTDOMAIN
  78. #define BINDTEXTDOMAIN(a,b) TVIntl::bindTextDomain(a,b)
  79. #endif
  80. #ifndef TEXTDOMAIN
  81. #define TEXTDOMAIN(a) TVIntl::textDomain(a)
  82. #endif
  83. #else /* __cplusplus */
  84. #ifndef _
  85. #ifdef HAVE_INTL_SUPPORT
  86. char *gettext(const char *msgid);
  87. #define _(msg) gettext(msg)
  88. #else
  89. #define _(msg) (msg)
  90. #endif
  91. #endif
  92. #ifndef __
  93. #define __(msg) (msg)
  94. #endif
  95. #ifndef BINDTEXTDOMAIN
  96. char *bindtextdomain(const char *domainname, const char *dirname);
  97. #define BINDTEXTDOMAIN(a,b) bindtextdomain(a,b)
  98. #endif
  99. #ifndef TEXTDOMAIN
  100. char *textdomain(const char *domainname);
  101. #define TEXTDOMAIN(a) textdomain(a)
  102. #endif
  103. #endif /* __cplusplus */
  104. #endif /* HAVE_INTL_SUPPORT */
  105. #endif /* TVIntl_Included */