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  GetLanguages(mLangCodes, mLangNames);
79  int lang =
80  make_iterator_range( mLangCodes ).index( GetSystemLanguageCode() );
81 
82  ShuttleGui S(this, eIsCreating);
83 
84  S.StartVerticalLay(false);
85  {
87  {
88  S.SetBorder(15);
89  mChoice = S.AddChoice(XXO("Choose Language for Audacity to use:"),
90  mLangNames,
91  lang);
92  }
93  S.EndVerticalLay();
94 
95  S.SetBorder(0);
97  }
98  S.EndVerticalLay();
99 
100  Fit();
101 }
102 
103 void LangChoiceDialog::OnOk(wxCommandEvent & WXUNUSED(event))
104 {
105  int ndx = mChoice->GetSelection();
106  mLang = mLangCodes[ndx];
107 
108  wxString slang = GetSystemLanguageCode();
109  int sndx = make_iterator_range( mLangCodes ).index( slang );
110  wxString sname;
111 
112  if (sndx == wxNOT_FOUND) {
113  const wxLanguageInfo *sinfo = wxLocale::FindLanguageInfo(slang);
114  if (sinfo) {
115  sname = sinfo->Description;
116  }
117  }
118  else {
119  sname = mLangNames[sndx].Translation();
120  }
121 
122  if (mLang.Left(2) != slang.Left(2)) {
123  /* i18n-hint: The %s's are replaced by translated and untranslated
124  * versions of language names. */
125  auto msg = XO("The language you have chosen, %s (%s), is not the same as the system language, %s (%s).")
126  .Format(mLangNames[ndx],
127  mLang,
128  sname,
129  slang);
130  if ( wxNO == AudacityMessageBox( msg, XO("Confirm"), wxYES_NO ) ) {
131  return;
132  }
133  }
134 
135  EndModal(true);
136 }
EVT_BUTTON
EVT_BUTTON(wxID_NO, DependencyDialog::OnNo) EVT_BUTTON(wxID_YES
TranslatableString
Definition: Types.h:290
eIsCreating
@ eIsCreating
Definition: ShuttleGui.h:36
ShuttleGuiBase::AddChoice
wxChoice * AddChoice(const TranslatableString &Prompt, const TranslatableStrings &choices, int Selected=-1)
Definition: ShuttleGui.cpp:391
ShuttleGuiBase::StartVerticalLay
void StartVerticalLay(int iProp=1)
Definition: ShuttleGui.cpp:1177
GetSystemLanguageCode
wxString GetSystemLanguageCode()
Definition: Languages.cpp:77
make_iterator_range
IteratorRange< Iterator > make_iterator_range(const Iterator &i1, const Iterator &i2)
Definition: MemoryX.h:625
LangChoiceDialog::mNumLangs
int mNumLangs
Definition: LangChoice.cpp:47
AudacityMessageBox
int AudacityMessageBox(const TranslatableString &message, const TranslatableString &caption=AudacityMessageBoxCaptionStr(), long style=wxOK|wxCENTRE, wxWindow *parent=NULL, int x=wxDefaultCoord, int y=wxDefaultCoord)
Definition: AudacityMessageBox.h:20
XO
#define XO(s)
Definition: Internat.h:32
wxPanelWrapper.h
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
eOkButton
@ eOkButton
Definition: ShuttleGui.h:607
TranslatableStrings
std::vector< TranslatableString > TranslatableStrings
Definition: Types.h:547
ChooseLanguage
wxString ChooseLanguage(wxWindow *parent)
Definition: LangChoice.cpp:54
XXO
#define XXO(s)
Definition: Internat.h:45
ShuttleGuiBase::StartHorizontalLay
void StartHorizontalLay(int PositionFlags=wxALIGN_CENTRE, int iProp=1)
Definition: ShuttleGui.cpp:1160
LangChoiceDialog::mLangCodes
wxArrayString mLangCodes
Definition: LangChoice.cpp:48
ShuttleGuiBase::EndVerticalLay
void EndVerticalLay()
Definition: ShuttleGui.cpp:1196
LangChoiceDialog::mChoice
wxChoice * mChoice
Definition: LangChoice.cpp:44
Languages.h
LangChoiceDialog::mLangNames
TranslatableStrings mLangNames
Definition: LangChoice.cpp:49
LangChoice.h
ShuttleGui.h
LangChoiceDialog::OnOk
void OnOk(wxCommandEvent &event)
Definition: LangChoice.cpp:103
wxDialogWrapper
Definition: wxPanelWrapper.h:81
GetLanguages
void GetLanguages(wxArrayString &langCodes, TranslatableStrings &langNames)
Definition: Languages.cpp:131
AudacityMessageBox.h
ShuttleGui::AddStandardButtons
void AddStandardButtons(long buttons=eOkButton|eCancelButton, wxWindow *extra=NULL)
Definition: ShuttleGui.cpp:2406
LangChoiceDialog::LangChoiceDialog
LangChoiceDialog(wxWindow *parent, wxWindowID id, const TranslatableString &title)
Definition: LangChoice.cpp:72
ShuttleGuiBase::SetBorder
void SetBorder(int Border)
Definition: ShuttleGui.h:497
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:638