Audacity  3.0.3
Internat.h
Go to the documentation of this file.
1 /**********************************************************************
2 
3  Audacity: A Digital Audio Editor
4 
5  Internat.h
6 
7  Markus Meyer
8  Dominic Mazzoni (Mac OS X code)
9 
10 **********************************************************************/
11 
12 #ifndef __AUDACITY_INTERNAT__
13 #define __AUDACITY_INTERNAT__
14 
15 
16 
17 #include <wx/longlong.h>
18 
19 #include "audacity/Types.h"
20 
21 class wxArrayString;
22 class wxArrayStringEx;
23 
24 extern AUDACITY_DLL_API const wxString& GetCustomTranslation(const wxString& str1 );
25 extern AUDACITY_DLL_API const wxString& GetCustomSubstitution(const wxString& str1 );
26 
27 // Marks string for substitution only.
28 #define _TS( s ) GetCustomSubstitution( s )
29 
30 // Marks strings for extraction only... use .Translate() to translate.
31 // '&', preceding menu accelerators, should NOT occur in the argument.
32 #define XO(s) (TranslatableString{ wxT(s), {} })
33 
34 // Alternative taking a second context argument. A context is a string literal,
35 // which is not translated, but serves to disambiguate uses of the first string
36 // that might need differing translations, such as "Light" meaning not-heavy in
37 // one place but not-dark elsewhere.
38 #define XC(s, c) (TranslatableString{ wxT(s), {} }.Context(c))
39 
40 // Marks strings for extraction only, where '&', preceding menu accelerators, MAY
41 // occur.
42 // For now, expands exactly as macro XO does, but in future there will be a
43 // type distinction - for example XXO should be used for menu item names that
44 // might use the & character for shortcuts.
45 #define XXO(s) XO(s)
46 
47 // Corresponds to XC as XXO does to XO
48 #define XXC(s, c) XC(s, c)
49 
50 #ifdef _
51  #undef _
52 #endif
53 
54 #if defined( _DEBUG )
55  // Force a crash if you misuse _ in a static initializer, so that translation
56  // is looked up too early and not found.
57 
58  #ifdef __WXMSW__
59 
60  // Eventually pulls in <windows.h> which indirectly defines DebugBreak(). Can't
61  // include <windows.h> directly since it then causes "MemoryX.h" to spew errors.
62  #include <wx/app.h>
63  #define _(s) ((wxTranslations::Get() || (DebugBreak(), true)), \
64  GetCustomTranslation((s)))
65 
66  #else
67 
68  #include <signal.h>
69  // Raise a signal because it's even too early to use wxASSERT for this.
70  #define _(s) ((wxTranslations::Get() || raise(SIGTRAP)), \
71  GetCustomTranslation((s)))
72 
73  #endif
74 
75 #else
76  #define _(s) GetCustomTranslation((s))
77 #endif
78 
79 #ifdef XP
80  #undef XP
81 #endif
82 
83 
84 // The two string arguments will go to the .pot file, as
85 // msgid sing
86 // msgid_plural plural
87 //
88 // (You must use plain string literals. Do not use _() or wxT() or L prefix,
89 // which (intentionally) will fail to compile. The macro inserts wxT).
90 //
91 // Note too: The i18n-hint comment must be on the line preceding the first
92 // string. That might be inside the parentheses of the macro call.
93 //
94 // The macro call is then followed by a sequence of format arguments in
95 // parentheses. The third argument of the macro call is the zero-based index
96 // of the format argument that selects singular or plural
97 #define XP(sing, plur, n) \
98  TranslatableString{ wxT(sing), {} }.Plural<(n)>( wxT(plur) )
99 
100 // Like XP but with an additional context argument, as for XC
101 #define XPC(sing, plur, n, c) \
102  TranslatableString{ wxT(sing), {} }.Context(c).Plural<(n)>( wxT(plur) )
103 
104 class AUDACITY_DLL_API Internat
105 {
106 public:
109  static void Init();
110 
115  static wxChar GetDecimalSeparator();
116  static void SetCeeNumberFormat();
117 
123  static bool CompatibleToDouble(const wxString& stringToConvert, double* result);
124 
125  // Function version of above.
126  static double CompatibleToDouble(const wxString& stringToConvert);
127 
130  static wxString ToString(double numberToConvert,
131  int digitsAfterDecimalPoint = -1);
132 
135  static wxString ToDisplayString(double numberToConvert,
136  int digitsAfterDecimalPoint = -1);
137 
140  static TranslatableString FormatSize(wxLongLong size);
141  static TranslatableString FormatSize(double size);
142 
148  static bool SanitiseFilename(wxString &name, const wxString &sub);
149 
150  static const wxArrayString &GetExcludedCharacters()
151  { return exclude; }
152 
153 private:
154  static wxChar mDecimalSeparator;
155 
156  static wxArrayString exclude;
157 };
158 
159 // Convert C strings to wxString
160 #define UTF8CTOWX(X) wxString((X), wxConvUTF8)
161 #define LAT1CTOWX(X) wxString((X), wxConvISO8859_1)
162 
164 AUDACITY_DLL_API TranslatableStrings Msgids(
165  const EnumValueSymbol strings[], size_t nStrings);
166 AUDACITY_DLL_API TranslatableStrings Msgids( const std::vector<EnumValueSymbol> &strings );
167 
168 // Whether disambiguationg contexts are supported
169 // If not, then the program builds and runs, but strings in the catalog with
170 // contexts will fail to translate
171 #define HAS_I18N_CONTEXTS wxCHECK_VERSION(3, 1, 1)
172 
173 #endif
TranslatableString
Definition: Types.h:290
Internat
Internationalisation support.
Definition: Internat.h:105
GetCustomTranslation
AUDACITY_DLL_API const wxString & GetCustomTranslation(const wxString &str1)
Definition: Internat.cpp:76
wxArrayStringEx
Definition: MemoryX.h:663
ComponentInterfaceSymbol
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
Definition: ComponentInterface.h:60
TranslatableStrings
std::vector< TranslatableString > TranslatableStrings
Definition: Types.h:555
GetCustomSubstitution
AUDACITY_DLL_API const wxString & GetCustomSubstitution(const wxString &str1)
Definition: Internat.cpp:68
Msgids
AUDACITY_DLL_API TranslatableStrings Msgids(const EnumValueSymbol strings[], size_t nStrings)
Definition: Internat.cpp:267
name
const TranslatableString name
Definition: Distortion.cpp:98
Types.h
Internat::GetExcludedCharacters
static const wxArrayString & GetExcludedCharacters()
Definition: Internat.h:150
Internat::mDecimalSeparator
static wxChar mDecimalSeparator
Definition: Internat.h:154
Internat::exclude
static wxArrayString exclude
Definition: Internat.h:156