Audacity 3.2.0
Static Public Member Functions | Static Private Attributes | List of all members
Internat Class Reference

Internationalisation support. More...

#include <Internat.h>

Static Public Member Functions

static void Init ()
 Initialize internationalisation support. Call this once at program start. More...
 
static wxChar GetDecimalSeparator ()
 Get the decimal separator for the current locale. More...
 
static void SetCeeNumberFormat ()
 
static bool CompatibleToDouble (const wxString &stringToConvert, double *result)
 Convert a string to a number. More...
 
static double CompatibleToDouble (const wxString &stringToConvert)
 
static wxString ToString (double numberToConvert, int digitsAfterDecimalPoint=-1)
 Convert a number to a string, always uses the dot as decimal separator. More...
 
static wxString ToDisplayString (double numberToConvert, int digitsAfterDecimalPoint=-1)
 Convert a number to a string, uses the user's locale's decimal separator. More...
 
static TranslatableString FormatSize (wxLongLong size)
 Convert a number to a string while formatting it in bytes, KB, MB, GB. More...
 
static TranslatableString FormatSize (double size)
 
static bool SanitiseFilename (wxString &name, const wxString &sub)
 Check a proposed file name string for illegal characters and remove them return true iff name is "visibly" changed (not necessarily equivalent to character-wise changed) More...
 
static const wxArrayString & GetExcludedCharacters ()
 

Static Private Attributes

static wxChar mDecimalSeparator = wxT('.')
 
static wxArrayString exclude
 

Detailed Description

Internationalisation support.

This class is used to help internationalisation and in general compatibility with different locales and character sets. It deals mostly with converting numbers, but also has important functions to convert to/from UTF-8, which is used in XML files and on Mac OS X for the filesystem.

Definition at line 101 of file Internat.h.

Member Function Documentation

◆ CompatibleToDouble() [1/2]

double Internat::CompatibleToDouble ( const wxString &  stringToConvert)
static

Definition at line 119 of file Internat.cpp.

120{
121 double result = 0;
122 Internat::CompatibleToDouble(stringToConvert, &result);
123 return result;
124}
static bool CompatibleToDouble(const wxString &stringToConvert, double *result)
Convert a string to a number.
Definition: Internat.cpp:109

References CompatibleToDouble().

Here is the call graph for this function:

◆ CompatibleToDouble() [2/2]

bool Internat::CompatibleToDouble ( const wxString &  stringToConvert,
double *  result 
)
static

Convert a string to a number.

This function will accept BOTH point and comma as a decimal separator, regardless of the current locale. Returns 'true' on success, and 'false' if an error occurs.

Definition at line 109 of file Internat.cpp.

110{
111 // Regardless of the locale, always respect comma _and_ point
112 wxString s = stringToConvert;
113 // Convert to C locale decimal point for stable parsing.
114 s.Replace(wxT(","), wxT("."));
115 s.Replace(wxString(GetDecimalSeparator()), wxT("."));
116 return s.ToCDouble(result);
117}
wxT("CloseDown"))
static wxChar GetDecimalSeparator()
Get the decimal separator for the current locale.
Definition: Internat.cpp:104

References GetDecimalSeparator(), and wxT().

Referenced by CompatibleToDouble(), NyquistEffect::GetCtrlValue(), LabelStruct::Import(), LOFImportFileHandle::lofOpenFiles(), LadspaEditor::OnTextCtrl(), WrappedType::ReadAsDouble(), and WrappedType::WriteToAsString().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ FormatSize() [1/2]

TranslatableString Internat::FormatSize ( double  size)
static

Definition at line 188 of file Internat.cpp.

189{
190 TranslatableString sizeStr;
191
192 if (size == -1)
193 sizeStr = XO("Unable to determine");
194 else {
195 /* make it look nice, by formatting into k, MB, etc */
196 if (size < 1024.0)
197 sizeStr = XO("%s bytes").Format( ToDisplayString(size) );
198 else if (size < 1024.0 * 1024.0) {
199 /* i18n-hint: Abbreviation for Kilo bytes */
200 sizeStr = XO("%s KB").Format( ToDisplayString(size / 1024.0, 1) );
201 }
202 else if (size < 1024.0 * 1024.0 * 1024.0) {
203 /* i18n-hint: Abbreviation for Mega bytes */
204 sizeStr = XO("%s MB").Format( ToDisplayString(size / (1024.0 * 1024.0), 1) );
205 }
206 else {
207 /* i18n-hint: Abbreviation for Giga bytes */
208 sizeStr = XO("%s GB").Format( ToDisplayString(size / (1024.0 * 1024.0 * 1024.0), 1) );
209 }
210 }
211
212 return sizeStr;
213}
XO("Cut/Copy/Paste")
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:137
Holds a msgid for the translation catalog; may also bind format arguments.

References size, ToDisplayString(), and XO().

Here is the call graph for this function:

◆ FormatSize() [2/2]

TranslatableString Internat::FormatSize ( wxLongLong  size)
static

Convert a number to a string while formatting it in bytes, KB, MB, GB.

Definition at line 179 of file Internat.cpp.

180{
181 /* wxLongLong contains no built-in conversion to double */
182 double dSize = size.GetHi() * pow(2.0, 32); // 2 ^ 32
183 dSize += size.GetLo();
184
185 return FormatSize(dSize);
186}
static TranslatableString FormatSize(wxLongLong size)
Convert a number to a string while formatting it in bytes, KB, MB, GB.
Definition: Internat.cpp:179

References FormatSize(), and size.

Referenced by ProjectFileManager::Compact(), HistoryDialog::DoUpdate(), FormatSize(), HistoryDialog::OnCompact(), DependencyDialog::OnCopyToClipboard(), DirectoriesPrefs::OnTempText(), and DependencyDialog::PopulateList().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetDecimalSeparator()

wxChar Internat::GetDecimalSeparator ( )
static

Get the decimal separator for the current locale.

Normally, this is a decimal point ('.'), but e.g. Germany uses a comma (',').

Definition at line 104 of file Internat.cpp.

105{
106 return mDecimalSeparator;
107}
static wxChar mDecimalSeparator
Definition: Internat.h:151

References mDecimalSeparator.

Referenced by CompatibleToDouble(), ToDisplayString(), and ToString().

Here is the caller graph for this function:

◆ GetExcludedCharacters()

static const wxArrayString & Internat::GetExcludedCharacters ( )
inlinestatic

Definition at line 147 of file Internat.h.

148 { return exclude; }
static wxArrayString exclude
Definition: Internat.h:153

◆ Init()

void Internat::Init ( )
static

Initialize internationalisation support. Call this once at program start.

Definition at line 53 of file Internat.cpp.

54{
55 // Save decimal point character
56 struct lconv * localeInfo = localeconv();
57 if (localeInfo)
58 mDecimalSeparator = wxString(wxSafeConvertMB2WX(localeInfo->decimal_point)).GetChar(0);
59
60// wxLogDebug(wxT("Decimal separator set to '%c'"), mDecimalSeparator);
61
62 // Setup list of characters that aren't allowed in file names
63 // Hey! The default wxPATH_NATIVE does not do as it should.
64#if defined(__WXMAC__)
65 wxPathFormat format = wxPATH_MAC;
66#elif defined(__WXGTK__)
67 wxPathFormat format = wxPATH_UNIX;
68#elif defined(__WXMSW__)
69 wxPathFormat format = wxPATH_WIN;
70#endif
71
72 // This is supposed to return characters not permitted in paths to files
73 // or to directories
74 auto forbid = wxFileName::GetForbiddenChars(format);
75
76 for (auto cc: forbid) {
77#if defined(__WXGTK__)
78 if (cc == wxT('*') || cc == wxT('?')) {
79 continue;
80 }
81#endif
82 exclude.push_back(wxString{ cc });
83 }
84
85 // The path separators may not be forbidden, so add them
86 //auto separators = wxFileName::GetPathSeparators(format);
87
88 // Bug 1441 exclude all separators from filenames on all platforms.
89 auto separators = wxString("\\/");
90
91 for(auto cc: separators) {
92 if (forbid.Find(cc) == wxNOT_FOUND)
93 exclude.push_back(wxString{ cc });
94 }
95}

References exclude, anonymous_namespace{ExportPCM.cpp}::format, mDecimalSeparator, and wxT().

Referenced by Languages::SetLang().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SanitiseFilename()

bool Internat::SanitiseFilename ( wxString &  name,
const wxString &  sub 
)
static

Check a proposed file name string for illegal characters and remove them return true iff name is "visibly" changed (not necessarily equivalent to character-wise changed)

Definition at line 215 of file Internat.cpp.

216{
217 bool result = false;
218 for(const auto &item : exclude)
219 {
220 if(name.Contains(item))
221 {
222 name.Replace(item, sub);
223 result = true;
224 }
225 }
226
227#ifdef __WXMAC__
228 // Special Mac stuff
229 // '/' is permitted in file names as seen in dialogs, even though it is
230 // the path separator. The "real" filename as seen in the terminal has ':'.
231 // Do NOT return true if this is the only substitution.
232 name.Replace(wxT("/"), wxT(":"));
233#endif
234
235 return result;
236}
const TranslatableString name
Definition: Distortion.cpp:76

References exclude, name, and wxT().

Referenced by ExportAudioDialog::UpdateLabelExportSettings(), and ExportAudioDialog::UpdateTrackExportSettings().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetCeeNumberFormat()

void Internat::SetCeeNumberFormat ( )
static

Definition at line 97 of file Internat.cpp.

98{
99 wxSetlocale( LC_NUMERIC, "C" );
100 mDecimalSeparator = '.';
101}

References mDecimalSeparator.

Referenced by GUISettings::SetLang().

Here is the caller graph for this function:

◆ ToDisplayString()

wxString Internat::ToDisplayString ( double  numberToConvert,
int  digitsAfterDecimalPoint = -1 
)
static

Convert a number to a string, uses the user's locale's decimal separator.

Definition at line 137 of file Internat.cpp.

139{
140 wxString decSep = wxString(GetDecimalSeparator());
141 wxString result;
142
143 if (digitsAfterDecimalPoint == -1)
144 {
145 result.Printf(wxT("%f"), numberToConvert);
146
147 // Not all libcs respect the decimal separator, so always convert
148 // any dots found to the decimal separator.
149 result.Replace(wxT("."), decSep);
150
151 if (result.Find(decSep) != -1)
152 {
153 // Strip trailing zeros, but leave one, and decimal separator.
154 int pos = result.length() - 1;
155 while ((pos > 1) &&
156 (result.GetChar(pos) == wxT('0')) &&
157 (result.GetChar(pos - 1) != decSep))
158 pos--;
159 // (Previous code removed all of them and decimal separator.)
160 // if (result.GetChar(pos) == decSep)
161 // pos--; // strip point before empty fractional part
162 result = result.Left(pos+1);
163 }
164 }
165 else
166 {
167 wxString format;
168 format.Printf(wxT("%%.%if"), digitsAfterDecimalPoint);
169 result.Printf(format, numberToConvert);
170
171 // Not all libcs respect the decimal separator, so always convert
172 // any dots found to the decimal separator
173 result.Replace(wxT("."), decSep);
174 }
175
176 return result;
177}

References anonymous_namespace{ExportPCM.cpp}::format, GetDecimalSeparator(), and wxT().

Referenced by LV2Editor::BuildPlain(), FormatSize(), EffectAutoDuck::Panel::OnPaint(), LadspaEditor::OnSlider(), VampEffect::PopulateOrExchange(), LadspaEditor::PopulateUI(), LadspaEditor::RefreshControls(), and ToString().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ToString()

wxString Internat::ToString ( double  numberToConvert,
int  digitsAfterDecimalPoint = -1 
)
static

Convert a number to a string, always uses the dot as decimal separator.

Definition at line 126 of file Internat.cpp.

128{
129 wxString result = ToDisplayString(
130 numberToConvert, digitsAfterDecimalPoint);
131
132 result.Replace(wxString(GetDecimalSeparator()), wxT("."));
133
134 return result;
135}

References GetDecimalSeparator(), ToDisplayString(), and wxT().

Referenced by LabelStruct::Export(), anonymous_namespace{Nyquist.cpp}::GetClipBoundaries(), Sequence::HandleXMLEndTag(), Sequence::Paste(), NyquistEffect::Process(), NyquistEffect::ProcessOne(), XMLWriter::WriteAttr(), and Sequence::WriteXML().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ exclude

wxArrayString Internat::exclude
staticprivate

Definition at line 153 of file Internat.h.

Referenced by Init(), and SanitiseFilename().

◆ mDecimalSeparator

wxChar Internat::mDecimalSeparator = wxT('.')
staticprivate

Definition at line 151 of file Internat.h.

Referenced by GetDecimalSeparator(), Init(), and SetCeeNumberFormat().


The documentation for this class was generated from the following files: