Audacity  3.0.3
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 104 of file Internat.h.

Member Function Documentation

◆ CompatibleToDouble() [1/2]

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

Definition at line 148 of file Internat.cpp.

149 {
150  double result = 0;
151  Internat::CompatibleToDouble(stringToConvert, &result);
152  return result;
153 }

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 139 of file Internat.cpp.

140 {
141  // Regardless of the locale, always respect comma _and_ point
142  wxString s = stringToConvert;
143  s.Replace(wxT(","), wxString(GetDecimalSeparator()));
144  s.Replace(wxT("."), wxString(GetDecimalSeparator()));
145  return s.ToDouble(result);
146 }

References GetDecimalSeparator().

Referenced by PCMAliasBlockFile::BuildFromXML(), SimpleBlockFile::BuildFromXML(), CompatibleToDouble(), NyquistEffect::GetCtrlValue(), AUPImportFileHandle::HandleImport(), AUPImportFileHandle::HandleProject(), SelectedRegion::HandleXMLAttribute(), EffectEqualization::HandleXMLTag(), VSTEffect::HandleXMLTag(), EnvPoint::HandleXMLTag(), NoteTrack::HandleXMLTag(), ProjectFileIO::HandleXMLTag(), TimeTrack::HandleXMLTag(), WaveClip::HandleXMLTag(), WaveTrack::HandleXMLTag(), LabelStruct::Import(), LOFImportFileHandle::lofOpenFiles(), LadspaEffect::OnTextCtrl(), WrappedType::ReadAsDouble(), ViewInfo::ReadXMLAttribute(), 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 217 of file Internat.cpp.

218 {
219  TranslatableString sizeStr;
220 
221  if (size == -1)
222  sizeStr = XO("Unable to determine");
223  else {
224  /* make it look nice, by formatting into k, MB, etc */
225  if (size < 1024.0)
226  sizeStr = XO("%s bytes").Format( ToDisplayString(size) );
227  else if (size < 1024.0 * 1024.0) {
228  /* i18n-hint: Abbreviation for Kilo bytes */
229  sizeStr = XO("%s KB").Format( ToDisplayString(size / 1024.0, 1) );
230  }
231  else if (size < 1024.0 * 1024.0 * 1024.0) {
232  /* i18n-hint: Abbreviation for Mega bytes */
233  sizeStr = XO("%s MB").Format( ToDisplayString(size / (1024.0 * 1024.0), 1) );
234  }
235  else {
236  /* i18n-hint: Abbreviation for Giga bytes */
237  sizeStr = XO("%s GB").Format( ToDisplayString(size / (1024.0 * 1024.0 * 1024.0), 1) );
238  }
239  }
240 
241  return sizeStr;
242 }

References 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 208 of file Internat.cpp.

209 {
210  /* wxLongLong contains no built-in conversion to double */
211  double dSize = size.GetHi() * pow(2.0, 32); // 2 ^ 32
212  dSize += size.GetLo();
213 
214  return FormatSize(dSize);
215 }

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

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 134 of file Internat.cpp.

135 {
136  return mDecimalSeparator;
137 }

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 150 of file Internat.h.

151  { return exclude; }

Referenced by ExportMultipleDialog::MakeFileName().

Here is the caller graph for this function:

◆ Init()

void Internat::Init ( )
static

Initialize internationalisation support. Call this once at program start.

Definition at line 83 of file Internat.cpp.

84 {
85  // Save decimal point character
86  struct lconv * localeInfo = localeconv();
87  if (localeInfo)
88  mDecimalSeparator = wxString(wxSafeConvertMB2WX(localeInfo->decimal_point)).GetChar(0);
89 
90 // wxLogDebug(wxT("Decimal separator set to '%c'"), mDecimalSeparator);
91 
92  // Setup list of characters that aren't allowed in file names
93  // Hey! The default wxPATH_NATIVE does not do as it should.
94 #if defined(__WXMAC__)
95  wxPathFormat format = wxPATH_MAC;
96 #elif defined(__WXGTK__)
97  wxPathFormat format = wxPATH_UNIX;
98 #elif defined(__WXMSW__)
99  wxPathFormat format = wxPATH_WIN;
100 #endif
101 
102  // This is supposed to return characters not permitted in paths to files
103  // or to directories
104  auto forbid = wxFileName::GetForbiddenChars(format);
105 
106  for (auto cc: forbid) {
107 #if defined(__WXGTK__)
108  if (cc == wxT('*') || cc == wxT('?')) {
109  continue;
110  }
111 #endif
112  exclude.push_back(wxString{ cc });
113  }
114 
115  // The path separators may not be forbidden, so add them
116  //auto separators = wxFileName::GetPathSeparators(format);
117 
118  // Bug 1441 exclude all separators from filenames on all platforms.
119  auto separators = wxString("\\/");
120 
121  for(auto cc: separators) {
122  if (forbid.Find(cc) == wxNOT_FOUND)
123  exclude.push_back(wxString{ cc });
124  }
125 }

References format, and mDecimalSeparator.

Referenced by GUIPrefs::SetLang().

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 244 of file Internat.cpp.

245 {
246  bool result = false;
247  for(const auto &item : exclude)
248  {
249  if(name.Contains(item))
250  {
251  name.Replace(item, sub);
252  result = true;
253  }
254  }
255 
256 #ifdef __WXMAC__
257  // Special Mac stuff
258  // '/' is permitted in file names as seen in dialogs, even though it is
259  // the path separator. The "real" filename as seen in the terminal has ':'.
260  // Do NOT return true if this is the only substitution.
261  name.Replace(wxT("/"), wxT(":"));
262 #endif
263 
264  return result;
265 }

References exclude, and name.

Referenced by ExportMultipleDialog::MakeFileName().

Here is the caller graph for this function:

◆ SetCeeNumberFormat()

void Internat::SetCeeNumberFormat ( )
static

Definition at line 127 of file Internat.cpp.

128 {
129  wxSetlocale( LC_NUMERIC, "C" );
130  mDecimalSeparator = '.';
131 }

References mDecimalSeparator.

Referenced by GUIPrefs::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 166 of file Internat.cpp.

168 {
169  wxString decSep = wxString(GetDecimalSeparator());
170  wxString result;
171 
172  if (digitsAfterDecimalPoint == -1)
173  {
174  result.Printf(wxT("%f"), numberToConvert);
175 
176  // Not all libcs respect the decimal separator, so always convert
177  // any dots found to the decimal separator.
178  result.Replace(wxT("."), decSep);
179 
180  if (result.Find(decSep) != -1)
181  {
182  // Strip trailing zeros, but leave one, and decimal separator.
183  int pos = result.length() - 1;
184  while ((pos > 1) &&
185  (result.GetChar(pos) == wxT('0')) &&
186  (result.GetChar(pos - 1) != decSep))
187  pos--;
188  // (Previous code removed all of them and decimal separator.)
189  // if (result.GetChar(pos) == decSep)
190  // pos--; // strip point before empty fractional part
191  result = result.Left(pos+1);
192  }
193  }
194  else
195  {
196  wxString format;
197  format.Printf(wxT("%%.%if"), digitsAfterDecimalPoint);
198  result.Printf(format, numberToConvert);
199 
200  // Not all libcs respect the decimal separator, so always convert
201  // any dots found to the decimal separator
202  result.Replace(wxT("."), decSep);
203  }
204 
205  return result;
206 }

References format, and GetDecimalSeparator().

Referenced by LV2Effect::BuildPlain(), FormatSize(), EffectAutoDuckPanel::OnPaint(), LadspaEffect::OnSlider(), VampEffect::PopulateOrExchange(), LadspaEffect::PopulateUI(), LadspaEffect::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 155 of file Internat.cpp.

157 {
158  wxString result = ToDisplayString(
159  numberToConvert, digitsAfterDecimalPoint);
160 
161  result.Replace(wxString(GetDecimalSeparator()), wxT("."));
162 
163  return result;
164 }

References GetDecimalSeparator(), and ToDisplayString().

Referenced by LabelStruct::Export(), 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 156 of file Internat.h.

Referenced by SanitiseFilename().

◆ mDecimalSeparator

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

Definition at line 154 of file Internat.h.

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


The documentation for this class was generated from the following files:
TranslatableString
Definition: Types.h:290
Internat::GetDecimalSeparator
static wxChar GetDecimalSeparator()
Get the decimal separator for the current locale.
Definition: Internat.cpp:134
XO
#define XO(s)
Definition: Internat.h:32
Internat::FormatSize
static TranslatableString FormatSize(wxLongLong size)
Convert a number to a string while formatting it in bytes, KB, MB, GB.
Definition: Internat.cpp:208
name
const TranslatableString name
Definition: Distortion.cpp:98
format
int format
Definition: ExportPCM.cpp:54
Internat::mDecimalSeparator
static wxChar mDecimalSeparator
Definition: Internat.h:154
Internat::ToDisplayString
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:166
Internat::exclude
static wxArrayString exclude
Definition: Internat.h:156
Internat::CompatibleToDouble
static bool CompatibleToDouble(const wxString &stringToConvert, double *result)
Convert a string to a number.
Definition: Internat.cpp:139