Audacity  2.2.2
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 #include "Audacity.h"
19 
20 #include <wx/defs.h>
21 #include <wx/button.h>
22 #include <wx/choice.h>
23 #include <wx/intl.h>
24 #include <wx/sizer.h>
25 #include <wx/stattext.h>
26 
27 #include "LangChoice.h"
28 #include "Languages.h"
29 #include "ShuttleGui.h"
30 #include "widgets/wxPanelWrapper.h"
31 #include "widgets/ErrorDialog.h"
32 #include "Internat.h"
33 
34 class LangChoiceDialog final : public wxDialogWrapper {
35 public:
36  LangChoiceDialog(wxWindow * parent,
37  wxWindowID id,
38  const wxString & title);
39 
40  wxString GetLang() { return mLang; }
41 
42 private:
43  void OnOk(wxCommandEvent & event);
44 
45  wxChoice *mChoice;
46  wxString mLang;
47 
48  int mNumLangs;
49  wxArrayString mLangCodes;
50  wxArrayString mLangNames;
51 
52  DECLARE_EVENT_TABLE()
53 };
54 
55 wxString ChooseLanguage(wxWindow *parent)
56 {
57  wxString returnVal;
58 
59  /* i18n-hint: Title on a dialog indicating that this is the first
60  * time Audacity has been run. */
61  LangChoiceDialog dlog(parent, -1, _("Audacity First Run"));
62  dlog.CentreOnParent();
63  dlog.ShowModal();
64  returnVal = dlog.GetLang();
65 
66  return returnVal;
67 }
68 
69 BEGIN_EVENT_TABLE(LangChoiceDialog, wxDialogWrapper)
70  EVT_BUTTON(wxID_OK, LangChoiceDialog::OnOk)
72 
74  wxWindowID id,
75  const wxString & title):
76  wxDialogWrapper(parent, id, title)
77 {
78  SetName(GetTitle());
79  GetLanguages(mLangCodes, mLangNames);
80  int ndx = mLangCodes.Index(GetSystemLanguageCode());
81  wxString lang;
82 
83  if (ndx != wxNOT_FOUND) {
84  lang = mLangNames[ndx];
85  }
86 
87  ShuttleGui S(this, eIsCreating);
88 
89  S.StartVerticalLay(false);
90  {
92  {
93  S.SetBorder(15);
94  mChoice = S.AddChoice(_("Choose Language for Audacity to use:"),
95  lang,
96  &mLangNames);
97  }
98  S.EndVerticalLay();
99 
100  S.SetBorder(0);
102  }
103  S.EndVerticalLay();
104 
105  Fit();
106 }
107 
108 void LangChoiceDialog::OnOk(wxCommandEvent & WXUNUSED(event))
109 {
110  int ndx = mChoice->GetSelection();
111  mLang = mLangCodes[ndx];
112 
113  wxString slang = GetSystemLanguageCode();
114  int sndx = mLangCodes.Index(slang);
115  wxString sname;
116 
117  if (sndx == wxNOT_FOUND) {
118  const wxLanguageInfo *sinfo = wxLocale::FindLanguageInfo(slang);
119  if (sinfo) {
120  sname = sinfo->Description;
121  }
122  }
123  else {
124  sname = mLangNames[sndx];
125  }
126 
127  if (mLang.Left(2) != slang.Left(2)) {
128  wxString msg;
129  /* i18n-hint: The %s's are replaced by translated and untranslated
130  * versions of language names. */
131  msg.Printf(_("The language you have chosen, %s (%s), is not the same as the system language, %s (%s)."),
132  mLangNames[ndx],
133  mLang,
134  sname,
135  slang);
136  if (AudacityMessageBox(msg, _("Confirm"), wxYES_NO) == wxNO) {
137  return;
138  }
139  }
140 
141  EndModal(true);
142 }
wxArrayString mLangNames
Definition: LangChoice.cpp:50
A dialog used (at start up) to present the user with a choice of languages for Audacity.
Definition: LangChoice.cpp:34
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI...
Definition: ShuttleGui.h:366
wxArrayString mLangCodes
Definition: LangChoice.cpp:49
void OnOk(wxCommandEvent &event)
Definition: LangChoice.cpp:108
int AudacityMessageBox(const wxString &message, const wxString &caption=AudacityMessageBoxCaptionStr(), long style=wxOK|wxCENTRE, wxWindow *parent=NULL, int x=wxDefaultCoord, int y=wxDefaultCoord)
Definition: ErrorDialog.h:92
void EndVerticalLay()
Definition: ShuttleGui.cpp:991
void StartHorizontalLay(int PositionFlags=wxALIGN_CENTRE, int iProp=1)
Definition: ShuttleGui.cpp:966
wxChoice * AddChoice(const wxString &Prompt, const wxString &Selected, const wxArrayString *pChoices)
Definition: ShuttleGui.cpp:331
wxString GetLang()
Definition: LangChoice.cpp:40
EVT_BUTTON(wxID_NO, DependencyDialog::OnNo) EVT_BUTTON(wxID_YES
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown"))), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop"))), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom"))), OnMoveTrack) void TrackMenuTable::OnSetName(wxCommandEvent &)
LangChoiceDialog(wxWindow *parent, wxWindowID id, const wxString &title)
Definition: LangChoice.cpp:73
wxString GetSystemLanguageCode()
Definition: Languages.cpp:78
void GetLanguages(wxArrayString &langCodes, wxArrayString &langNames)
Definition: Languages.cpp:132
wxString ChooseLanguage(wxWindow *parent)
Definition: LangChoice.cpp:55
void AddStandardButtons(long buttons=eOkButton|eCancelButton, wxButton *extra=NULL)
END_EVENT_TABLE()
void SetBorder(int Border)
Definition: ShuttleGui.h:251
wxChoice * mChoice
Definition: LangChoice.cpp:45
void StartVerticalLay(int iProp=1)
Definition: ShuttleGui.cpp:982