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 #ifndef IN_RC
20 
21 class wxString;
22 
23 extern const wxString& GetCustomTranslation(const wxString& str1 );
24 extern const wxString& GetCustomSubstitution(const wxString& str1 );
25 
26 // Marks string for substitution only.
27 #define _TS( s ) GetCustomSubstitution( s )
28 
29 // Marks strings for extraction only...must use wxGetTranslation() to translate.
30 #define XO(s) wxT(s)
31 
32 #if defined( __WXDEBUG__ )
33  // Force a crash if you misuse _ in a static initializer, so that translation
34  // is looked up too early and not found.
35 
36  #ifdef _MSC_VER
37 
38  #define _(s) ((wxTranslations::Get() || (DebugBreak(), true)), \
39  GetCustomTranslation((s)))
40 
41  #else
42 
43  #include <signal.h>
44  // Raise a signal because it's even too early to use wxASSERT for this.
45  #define _(s) ((wxTranslations::Get() || raise(SIGTRAP)), \
46  GetCustomTranslation((s)))
47 
48  #endif
49 
50 #else
51  #define _(s) GetCustomTranslation((s))
52 #endif
53 
54 // The two string arugments will go to the .pot file, as
55 // msgid sing
56 // msgid_plural plural
57 //
58 // (You must use plain string literals. Do not use _() or wxT() or L prefix,
59 // which (intentionally) will fail to compile. The macro inserts wxT).
60 //
61 // Note too: it seems an i18n-hint comment is not extracted if it precedes
62 // wxPLURAL directly. A workaround: after the comment, insert a line
63 // _("dummyStringXXXX");
64 // where for XXXX subsitute something making this dummy string unique in the
65 // program. Then check in your generated audacity.pot that the dummy is
66 // immediately before the singular/plural entry.
67 //
68 // Your i18n-comment should therefore say something like,
69 // "In the string after this one, ..."
70 #define wxPLURAL(sing, plur, n) wxGetTranslation( wxT(sing), wxT(plur), n)
71 
72 #endif
73 
74 class Internat
75 {
76 public:
79  static void Init();
80 
85  static wxChar GetDecimalSeparator();
86 
92  static bool CompatibleToDouble(const wxString& stringToConvert, double* result);
93 
94  // Function version of above.
95  static double CompatibleToDouble(const wxString& stringToConvert);
96 
99  static wxString ToString(double numberToConvert,
100  int digitsAfterDecimalPoint = -1);
101 
104  static wxString ToDisplayString(double numberToConvert,
105  int digitsAfterDecimalPoint = -1);
106 
109  static wxString FormatSize(wxLongLong size);
110  static wxString FormatSize(double size);
111 
114 #if defined(__WXMSW__)
115  static char *VerifyFilename(const wxString &s, bool input = true);
116 #endif
117 
123  static bool SanitiseFilename(wxString &name, const wxString &sub);
124 
132  static wxString StripAccelerators(const wxString& str);
133 
134  static const wxArrayString &GetExcludedCharacters()
135  { return exclude; }
136 
137 private:
138  static wxChar mDecimalSeparator;
139 
140  // stuff for file name sanitisation
141  static wxArrayString exclude;
142 
143  static wxCharBuffer mFilename;
144 };
145 
146 #define _NoAcc(X) Internat::StripAccelerators(_(X))
147 
148 // Use this macro to wrap all filenames and pathnames that get
149 // passed directly to a system call, like opening a file, creating
150 // a directory, checking to see that a file exists, etc...
151 #if defined(__WXMSW__)
152 // Note, on Windows we don't define an OSFILENAME() to prevent accidental use.
153 // See VerifyFilename() for an explanation.
154 #define OSINPUT(X) Internat::VerifyFilename(X, true)
155 #define OSOUTPUT(X) Internat::VerifyFilename(X, false)
156 #elif defined(__WXMAC__)
157 #define OSFILENAME(X) ((char *) (const char *)(X).fn_str())
158 #define OSINPUT(X) OSFILENAME(X)
159 #define OSOUTPUT(X) OSFILENAME(X)
160 #else
161 #define OSFILENAME(X) ((char *) (const char *)(X).mb_str())
162 #define OSINPUT(X) OSFILENAME(X)
163 #define OSOUTPUT(X) OSFILENAME(X)
164 #endif
165 
166 // Convert C strings to wxString
167 #define UTF8CTOWX(X) wxString((X), wxConvUTF8)
168 #define LAT1CTOWX(X) wxString((X), wxConvISO8859_1)
169 
170 #endif
static wxString FormatSize(wxLongLong size)
Convert a number to a string while formatting it in bytes, KB, MB, GB.
Definition: Internat.cpp:190
static wxString StripAccelerators(const wxString &str)
Remove accelerator charactors from strings.
Definition: Internat.cpp:289
Internationalisation support.
Definition: Internat.h:74
static const wxArrayString & GetExcludedCharacters()
Definition: Internat.h:134
static void Init()
Initialize internationalisation support. Call this once at program start.
Definition: Internat.cpp:81
static bool SanitiseFilename(wxString &name, const wxString &sub)
Protect against Unicode to multi-byte conversion failures on Windows.
Definition: Internat.cpp:266
const wxString & GetCustomSubstitution(const wxString &str1)
Definition: Internat.cpp:66
static wxString ToString(double numberToConvert, int digitsAfterDecimalPoint=-1)
Convert a number to a string, always uses the dot as decimal separator.
Definition: Internat.cpp:137
static bool CompatibleToDouble(const wxString &stringToConvert, double *result)
Convert a string to a number.
Definition: Internat.cpp:121
static wxArrayString exclude
Definition: Internat.h:141
static wxChar mDecimalSeparator
Definition: Internat.h:138
const wxString & GetCustomTranslation(const wxString &str1)
Definition: Internat.cpp:74
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:148
static wxCharBuffer mFilename
Definition: Internat.h:143
static wxChar GetDecimalSeparator()
Get the decimal separator for the current locale.
Definition: Internat.cpp:116