Audacity  2.2.2
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 #include <wx/arrstr.h>
16 #include <wx/string.h>
17 #include <wx/longlong.h>
18 
19 #include <algorithm>
20 
21 #ifndef IN_RC
22 #include "Audacity.h"
23 
24 class wxString;
25 
26 extern AUDACITY_DLL_API const wxString& GetCustomTranslation(const wxString& str1 );
27 extern AUDACITY_DLL_API const wxString& GetCustomSubstitution(const wxString& str1 );
28 
29 // Marks string for substitution only.
30 #define _TS( s ) GetCustomSubstitution( s )
31 
32 // Marks strings for extraction only...must use wxGetTranslation() to translate.
33 #define XO(s) wxT(s)
34 
35 #ifdef _
36  #undef _
37 #endif
38 
39 #if defined( __WXDEBUG__ )
40  // Force a crash if you misuse _ in a static initializer, so that translation
41  // is looked up too early and not found.
42 
43  #ifdef _MSC_VER
44 
45  #define _(s) ((wxTranslations::Get() || (DebugBreak(), true)), \
46  GetCustomTranslation((s)))
47 
48  #else
49 
50  #include <signal.h>
51  // Raise a signal because it's even too early to use wxASSERT for this.
52  #define _(s) ((wxTranslations::Get() || raise(SIGTRAP)), \
53  GetCustomTranslation((s)))
54 
55  #endif
56 
57 #else
58  #define _(s) GetCustomTranslation((s))
59 #endif
60 
61 #ifdef wxPLURAL
62  #undef wxPLURAL
63 #endif
64 
65 
66 // The two string arugments will go to the .pot file, as
67 // msgid sing
68 // msgid_plural plural
69 //
70 // (You must use plain string literals. Do not use _() or wxT() or L prefix,
71 // which (intentionally) will fail to compile. The macro inserts wxT).
72 //
73 // Note too: it seems an i18n-hint comment is not extracted if it precedes
74 // wxPLURAL directly. A workaround: after the comment, insert a line
75 // _("dummyStringXXXX");
76 // where for XXXX subsitute something making this dummy string unique in the
77 // program. Then check in your generated audacity.pot that the dummy is
78 // immediately before the singular/plural entry.
79 //
80 // Your i18n-comment should therefore say something like,
81 // "In the string after this one, ..."
82 #define wxPLURAL(sing, plur, n) wxGetTranslation( wxT(sing), wxT(plur), n)
83 
84 #endif
85 
86 class Internat
87 {
88 public:
91  static void Init();
92 
97  static wxChar GetDecimalSeparator();
98 
104  static bool CompatibleToDouble(const wxString& stringToConvert, double* result);
105 
106  // Function version of above.
107  static double CompatibleToDouble(const wxString& stringToConvert);
108 
111  static wxString ToString(double numberToConvert,
112  int digitsAfterDecimalPoint = -1);
113 
116  static wxString ToDisplayString(double numberToConvert,
117  int digitsAfterDecimalPoint = -1);
118 
121  static wxString FormatSize(wxLongLong size);
122  static wxString FormatSize(double size);
123 
126 #if defined(__WXMSW__)
127  static char *VerifyFilename(const wxString &s, bool input = true);
128 #endif
129 
135  static bool SanitiseFilename(wxString &name, const wxString &sub);
136 
144  static wxString StripAccelerators(const wxString& str);
145 
146  static const wxArrayString &GetExcludedCharacters()
147  { return exclude; }
148 
149 private:
150  static wxChar mDecimalSeparator;
151 
152  // stuff for file name sanitisation
153  static wxArrayString exclude;
154 
155  static wxCharBuffer mFilename;
156 };
157 
158 #define _NoAcc(X) Internat::StripAccelerators(_(X))
159 
160 // Use this macro to wrap all filenames and pathnames that get
161 // passed directly to a system call, like opening a file, creating
162 // a directory, checking to see that a file exists, etc...
163 #if defined(__WXMSW__)
164 // Note, on Windows we don't define an OSFILENAME() to prevent accidental use.
165 // See VerifyFilename() for an explanation.
166 #define OSINPUT(X) Internat::VerifyFilename(X, true)
167 #define OSOUTPUT(X) Internat::VerifyFilename(X, false)
168 #elif defined(__WXMAC__)
169 #define OSFILENAME(X) ((char *) (const char *)(X).fn_str())
170 #define OSINPUT(X) OSFILENAME(X)
171 #define OSOUTPUT(X) OSFILENAME(X)
172 #else
173 #define OSFILENAME(X) ((char *) (const char *)(X).mb_str())
174 #define OSINPUT(X) OSFILENAME(X)
175 #define OSOUTPUT(X) OSFILENAME(X)
176 #endif
177 
178 // Convert C strings to wxString
179 #define UTF8CTOWX(X) wxString((X), wxConvUTF8)
180 #define LAT1CTOWX(X) wxString((X), wxConvISO8859_1)
181 
183 wxArrayString LocalizedStrings(
184  const IdentInterfaceSymbol strings[], size_t nStrings);
185 
186 // This object pairs an internal string, maybe empty, with a translated string.
187 // Any internal string may be written to configuration or other files and,
188 // for compatibility, should not vary between Audacity versions.
189 // The translated string may be shown to users and may vary with locale, and
190 // Audacity version if it is decided to use a different user-visible message.
191 // Sometimes the translated string is derived from a msgid identical
192 // to the internal string. The translated string is not meant to persist.
194 {
195 public:
196 
197  TranslatedInternalString() = default;
198 
199  // One-argument constructor from a msgid
200  explicit TranslatedInternalString( const wxString &internal )
201  : mInternal{ internal }, mTranslated{ GetCustomTranslation( internal ) }
202  {}
203 
204  // Two-argument version, when translated does not derive from internal
205  TranslatedInternalString( const wxString &internal,
206  const wxString &translated )
207  : mInternal{ internal }, mTranslated{ translated }
208  {}
209 
210  const wxString &Internal() const { return mInternal; }
211  const wxString Translated() const
212  {
213  wxString Temp = mTranslated;
214  Temp.Replace( "&","" );
215  return Temp;
216  }
217  const wxString &TranslatedForMenu() const { return mTranslated; }
218 
219 private:
220  wxString mInternal;
221  wxString mTranslated;
222 };
223 
224 #endif
static wxString FormatSize(wxLongLong size)
Convert a number to a string while formatting it in bytes, KB, MB, GB.
Definition: Internat.cpp:191
TranslatedInternalString(const wxString &internal, const wxString &translated)
Definition: Internat.h:205
static wxString StripAccelerators(const wxString &str)
Remove accelerator charactors from strings.
Definition: Internat.cpp:290
Internationalisation support.
Definition: Internat.h:86
static const wxArrayString & GetExcludedCharacters()
Definition: Internat.h:146
static void Init()
Initialize internationalisation support. Call this once at program start.
Definition: Internat.cpp:82
static bool SanitiseFilename(wxString &name, const wxString &sub)
Protect against Unicode to multi-byte conversion failures on Windows.
Definition: Internat.cpp:267
wxArrayString LocalizedStrings(const IdentInterfaceSymbol strings[], size_t nStrings)
Definition: Internat.cpp:303
const wxString & TranslatedForMenu() const
Definition: Internat.h:217
const wxString & Internal() const
Definition: Internat.h:210
TranslatedInternalString()=default
static wxString ToString(double numberToConvert, int digitsAfterDecimalPoint=-1)
Convert a number to a string, always uses the dot as decimal separator.
Definition: Internat.cpp:138
static bool CompatibleToDouble(const wxString &stringToConvert, double *result)
Convert a string to a number.
Definition: Internat.cpp:122
AUDACITY_DLL_API const wxString & GetCustomSubstitution(const wxString &str1)
Definition: Internat.cpp:67
static wxArrayString exclude
Definition: Internat.h:153
TranslatedInternalString(const wxString &internal)
Definition: Internat.h:200
const wxString Translated() const
Definition: Internat.h:211
static wxChar mDecimalSeparator
Definition: Internat.h:150
IdentInterfaceSymbol pairs a persistent string identifier used internally with an optional...
const wxChar * name
Definition: Distortion.cpp:94
static wxString ToDisplayString(double numberToConvert, int digitsAfterDecimalPoint=-1)
Convert a number to a string, uses the user's locale's decimal separator.
Definition: Internat.cpp:149
static wxCharBuffer mFilename
Definition: Internat.h:155
static wxChar GetDecimalSeparator()
Get the decimal separator for the current locale.
Definition: Internat.cpp:117
AUDACITY_DLL_API const wxString & GetCustomTranslation(const wxString &str1)
Definition: Internat.cpp:75