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

Member Function Documentation

◆ CompatibleToDouble() [1/2]

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

Definition at line 143 of file Internat.cpp.

144 {
145  double result = 0;
146  Internat::CompatibleToDouble(stringToConvert, &result);
147  return result;
148 }

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

135 {
136  // Regardless of the locale, always respect comma _and_ point
137  wxString s = stringToConvert;
138  s.Replace(wxT(","), wxString(GetDecimalSeparator()));
139  s.Replace(wxT("."), wxString(GetDecimalSeparator()));
140  return s.ToDouble(result);
141 }

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

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

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

204 {
205  /* wxLongLong contains no built-in conversion to double */
206  double dSize = size.GetHi() * pow(2.0, 32); // 2 ^ 32
207  dSize += size.GetLo();
208 
209  return FormatSize(dSize);
210 }

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

130 {
131  return mDecimalSeparator;
132 }

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

150  { 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 78 of file Internat.cpp.

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

References exclude, format, and mDecimalSeparator.

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

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

References exclude, and name.

Referenced by ExportMultipleDialog::MakeFileName().

Here is the caller graph for this function:

◆ SetCeeNumberFormat()

void Internat::SetCeeNumberFormat ( )
static

Definition at line 122 of file Internat.cpp.

123 {
124  wxSetlocale( LC_NUMERIC, "C" );
125  mDecimalSeparator = '.';
126 }

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

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

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

152 {
153  wxString result = ToDisplayString(
154  numberToConvert, digitsAfterDecimalPoint);
155 
156  result.Replace(wxString(GetDecimalSeparator()), wxT("."));
157 
158  return result;
159 }

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

Referenced by Init(), and SanitiseFilename().

◆ mDecimalSeparator

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

Definition at line 153 of file Internat.h.

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


The documentation for this class was generated from the following files:
TranslatableString
Holds a msgid for the translation catalog; may also bind format arguments.
Definition: TranslatableString.h:32
Internat::GetDecimalSeparator
static wxChar GetDecimalSeparator()
Get the decimal separator for the current locale.
Definition: Internat.cpp:129
XO
#define XO(s)
Definition: Internat.h:31
Internat::FormatSize
static TranslatableString FormatSize(wxLongLong size)
Convert a number to a string while formatting it in bytes, KB, MB, GB.
Definition: Internat.cpp:203
name
const TranslatableString name
Definition: Distortion.cpp:98
format
int format
Definition: ExportPCM.cpp:56
Internat::mDecimalSeparator
static wxChar mDecimalSeparator
Definition: Internat.h:153
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:161
Internat::exclude
static wxArrayString exclude
Definition: Internat.h:155
Internat::CompatibleToDouble
static bool CompatibleToDouble(const wxString &stringToConvert, double *result)
Convert a string to a number.
Definition: Internat.cpp:134