Audacity  3.0.3
LangChoice.cpp
Go to the documentation of this file.
1 /**********************************************************************
2 
3  Audacity: A Digital Audio Editor
4 
5  LangChoice.cpp
6 
7  Dominic Mazzoni
8 
9 *******************************************************************//*******************************************************************/
16 
17 
18 
19 #include "LangChoice.h"
20 
21 #include <wx/defs.h>
22 #include <wx/button.h>
23 #include <wx/choice.h>
24 #include <wx/intl.h>
25 #include <wx/sizer.h>
26 #include <wx/stattext.h>
27 
28 #include "Languages.h"
29 #include "ShuttleGui.h"
31 #include "widgets/wxPanelWrapper.h"
32 
33 class LangChoiceDialog final : public wxDialogWrapper {
34 public:
35  LangChoiceDialog(wxWindow * parent,
36  wxWindowID id,
37  const TranslatableString & title);
38 
39  wxString GetLang() { return mLang; }
40 
41 private:
42  void OnOk(wxCommandEvent & event);
43 
44  wxChoice *mChoice;
45  wxString mLang;
46 
47  int mNumLangs;
48  wxArrayString mLangCodes;
50 
51  DECLARE_EVENT_TABLE()
52 };
53 
54 wxString ChooseLanguage(wxWindow *parent)
55 {
56  wxString returnVal;
57 
58  /* i18n-hint: Title on a dialog indicating that this is the first
59  * time Audacity has been run. */
60  LangChoiceDialog dlog(parent, -1, XO("Audacity First Run"));
61  dlog.CentreOnParent();
62  dlog.ShowModal();
63  returnVal = dlog.GetLang();
64 
65  return returnVal;
66 }
67 
68 BEGIN_EVENT_TABLE(LangChoiceDialog, wxDialogWrapper)
71 
73  wxWindowID id,
74  const TranslatableString & title):
75  wxDialogWrapper(parent, id, title)
76 {
77  SetName();
78  const auto &paths = FileNames::AudacityPathList();
79  Languages::GetLanguages(paths, mLangCodes, mLangNames);
80  int lang = make_iterator_range( mLangCodes )
81  .index( Languages::GetSystemLanguageCode(paths) );
82 
83  ShuttleGui S(this, eIsCreating);
84 
85  S.StartVerticalLay(false);
86  {
88  {
89  S.SetBorder(15);
90  mChoice = S.AddChoice(XXO("Choose Language for Audacity to use:"),
91  mLangNames,
92  lang);
93  }
94  S.EndVerticalLay();
95 
96  S.SetBorder(0);
98  }
99  S.EndVerticalLay();
100 
101  Fit();
102 }
103 
104 void LangChoiceDialog::OnOk(wxCommandEvent & WXUNUSED(event))
105 {
106  int ndx = mChoice->GetSelection();
107  mLang = mLangCodes[ndx];
108 
109  auto slang =
111  int sndx = make_iterator_range( mLangCodes ).index( slang );
112  wxString sname;
113 
114  if (sndx == wxNOT_FOUND) {
115  const wxLanguageInfo *sinfo = wxLocale::FindLanguageInfo(slang);
116  if (sinfo) {
117  sname = sinfo->Description;
118  }
119  }
120  else {
121  sname = mLangNames[sndx].Translation();
122  }
123 
124  if (mLang.Left(2) != slang.Left(2)) {
125  /* i18n-hint: The %s's are replaced by translated and untranslated
126  * versions of language names. */
127  auto msg = XO("The language you have chosen, %s (%s), is not the same as the system language, %s (%s).")
128  .Format(mLangNames[ndx],
129  mLang,
130  sname,
131  slang);
132  if ( wxNO == AudacityMessageBox( msg, XO("Confirm"), wxYES_NO ) ) {
133  return;
134  }
135  }
136 
137  EndModal(true);
138 }
EVT_BUTTON
EVT_BUTTON(wxID_NO, DependencyDialog::OnNo) EVT_BUTTON(wxID_YES
TranslatableString
Holds a msgid for the translation catalog; may also bind format arguments.
Definition: TranslatableString.h:32
eIsCreating
@ eIsCreating
Definition: ShuttleGui.h:38
ShuttleGuiBase::AddChoice
wxChoice * AddChoice(const TranslatableString &Prompt, const TranslatableStrings &choices, int Selected=-1)
Definition: ShuttleGui.cpp:398
ShuttleGuiBase::StartVerticalLay
void StartVerticalLay(int iProp=1)
Definition: ShuttleGui.cpp:1184
AudacityMessageBox
int AudacityMessageBox(const TranslatableString &message, const TranslatableString &caption=XO("Message"), long style=wxOK|wxCENTRE, wxWindow *parent=NULL, int x=wxDefaultCoord, int y=wxDefaultCoord)
Definition: AudacityMessageBox.h:20
make_iterator_range
IteratorRange< Iterator > make_iterator_range(const Iterator &i1, const Iterator &i2)
Definition: MemoryX.h:549
LangChoiceDialog::mNumLangs
int mNumLangs
Definition: LangChoice.cpp:47
TranslatableStrings
std::vector< TranslatableString > TranslatableStrings
Definition: TranslatableString.h:295
XO
#define XO(s)
Definition: Internat.h:31
wxPanelWrapper.h
FileNames::AudacityPathList
AUDACITY_DLL_API const FilePaths & AudacityPathList()
A list of directories that should be searched for Audacity files (plug-ins, help files,...
LangChoiceDialog::GetLang
wxString GetLang()
Definition: LangChoice.cpp:39
LangChoiceDialog
A dialog used (at start up) to present the user with a choice of languages for Audacity.
Definition: LangChoice.cpp:33
ChooseLanguage
wxString ChooseLanguage(wxWindow *parent)
Definition: LangChoice.cpp:54
XXO
#define XXO(s)
Definition: Internat.h:44
ShuttleGuiBase::StartHorizontalLay
void StartHorizontalLay(int PositionFlags=wxALIGN_CENTRE, int iProp=1)
Definition: ShuttleGui.cpp:1167
LangChoiceDialog::mLangCodes
wxArrayString mLangCodes
Definition: LangChoice.cpp:48
ShuttleGuiBase::EndVerticalLay
void EndVerticalLay()
Definition: ShuttleGui.cpp:1203
LangChoiceDialog::mChoice
wxChoice * mChoice
Definition: LangChoice.cpp:44
Languages.h
LangChoiceDialog::mLangNames
TranslatableStrings mLangNames
Definition: LangChoice.cpp:49
LangChoice.h
ShuttleGui.h
title
static const auto title
Definition: UpdateNoticeDialog.cpp:23
LangChoiceDialog::OnOk
void OnOk(wxCommandEvent &event)
Definition: LangChoice.cpp:104
Languages::GetLanguages
void GetLanguages(FilePaths pathList, wxArrayString &langCodes, TranslatableStrings &langNames)
Definition: Languages.cpp:136
wxDialogWrapper
Definition: wxPanelWrapper.h:81
eOkButton
@ eOkButton
Definition: ShuttleGui.h:600
AudacityMessageBox.h
ShuttleGui::AddStandardButtons
void AddStandardButtons(long buttons=eOkButton|eCancelButton, wxWindow *extra=NULL)
Definition: ShuttleGui.cpp:2432
LangChoiceDialog::LangChoiceDialog
LangChoiceDialog(wxWindow *parent, wxWindowID id, const TranslatableString &title)
Definition: LangChoice.cpp:72
ShuttleGuiBase::SetBorder
void SetBorder(int Border)
Definition: ShuttleGui.h:489
Languages::GetSystemLanguageCode
wxString GetSystemLanguageCode(const FilePaths &pathList)
Definition: Languages.cpp:82
END_EVENT_TABLE
END_EVENT_TABLE()
LangChoiceDialog::mLang
wxString mLang
Definition: LangChoice.cpp:45
ShuttleGui
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:631