KWWidgets
vtkKWInternationalization.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Module: $RCSfile: vtkKWInternationalization.h,v $
4 
5  Copyright (c) Kitware, Inc.
6  All rights reserved.
7  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
8 
9  This software is distributed WITHOUT ANY WARRANTY; without even
10  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11  PURPOSE. See the above copyright notice for more information.
12 
13 =========================================================================*/
14 #ifndef __vtkKWInternationalization_h
15 #define __vtkKWInternationalization_h
16 
17 #include "vtkObject.h"
18 #include "vtkKWWidgets.h" // Needed for export symbols directives
19 
20 /* ----------------------------------------------------------------------
21  If Internationalization is supported, provide simple macros to
22  map gettext function calls.
23  Some macros rely on the GETTEXT_DOMAIN symbol to be defined as the quoted
24  name of the text domain that applies to the compilation unit.
25  This is done automatically by the KWWidgets_CREATE_GETTEXT_TARGETS
26  macro (KWWidgetsInternationalizationMacros.cmake) so that the below macros
27  can be used directly and expand to the right text domain automatically.
28  */
29 
30 #ifdef KWWidgets_USE_INTERNATIONALIZATION
31 # include <libintl.h> // Bring gettext
32 # undef _
33 # define _(string) gettext(string)
34 # undef k_
35 # define k_(string) dgettext(GETTEXT_DOMAIN, string)
36 #else
37 # undef _
38 # define _(string) string
39 # undef k_
40 # define k_(string) string
41 # undef gettext
42 # define gettext(string) string
43 # undef dgettext
44 # define dgettext(domain,string) string
45 #endif
46 
47 #ifndef GETTEXT_DOMAIN
48 #define GETTEXT_DOMAIN ""
49 #endif
50 
51 #define gettext_noop(string) string
52 #define N_(string) gettext_noop(string)
53 
54 /* ----------------------------------------------------------------------
55  Declare some gettext functions that support enlengthen strings.
56  Enlengthen strings make use of a special *separator* as a mean
57  to provide more context and disambiguate short GUI strings.
58  Example: "Menu|File|Open" instead of "Open"
59  See gettext "10.2.6 How to use gettext in GUI programs".
60 */
61 
62 //BTX
63 KWWidgets_EXTERN KWWidgets_EXPORT char* kww_sgettext(const char *msgid);
64 KWWidgets_EXTERN KWWidgets_EXPORT char* kww_sdgettext(const char *domain_name, const char *msgid);
65 //ETX
66 
67 #define s_(string) kww_sgettext(string)
68 #define ks_(string) kww_sdgettext(GETTEXT_DOMAIN, string)
69 
70 /* ---------------------------------------------------------------------- */
71 
72 class KWWidgets_EXPORT vtkKWInternationalization : public vtkObject
73 {
74 public:
75  static vtkKWInternationalization* New();
76  vtkTypeRevisionMacro(vtkKWInternationalization,vtkObject);
77  void PrintSelf(ostream& os, vtkIndent indent);
78 
79  // Description:
80  // Set/Get the current global domain of the LC_MESSAGES category.
81  // This domain specifies where the internationalized/translated strings
82  // are coming from.
83  // The argument is a null-terminated string, whose characters must be legal
84  // in the use in filenames.
85  static void SetCurrentTextDomain(const char *domain_name);
86  static const char* GetCurrentTextDomain();
87 
88  // Description:
89  // Set/Get the binding between a domain and a message catalog directory.
90  // The directory should be top-most directory containing the sub-directories
91  // for each locale/language (ex: fr, zh_CN). Each language subdirectory has
92  // a LC_MESSAGES subdirectory where the message catalog for that specific
93  // domain can be found (ex: dir/fr/LC_MESSAGES/myapp.mo).
94  static void SetTextDomainBinding(const char *domain_name, const char *dir);
95  static const char* GetTextDomainBinding(const char *domain_name);
96 
97  // Description:
98  // This method tries *really* hard to find *and* set a message catalog
99  // directory for a specific domain.
100  // Another signature accepts a semi-colon separated list of directories
101  // to search message catalogs for.
102  // Returns catalog directory if it was found, NULL otherwise.
103  static const char* FindTextDomainBinding(const char *domain_name);
104  static const char* FindTextDomainBinding(
105  const char *domain_name, const char *dirs_to_search);
106 
107 protected:
110 
111 private:
112  vtkKWInternationalization(const vtkKWInternationalization&); // Not implemented
113  void operator=(const vtkKWInternationalization&); // Not implemented
114 };
115 
116 #endif