Audacity 3.2.0
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#include "MemoryX.h"
21
22#include <wx/defs.h>
23#include <wx/choice.h>
24#include <wx/stattext.h>
25
26#include "Languages.h"
27#include "ShuttleGui.h"
28#include "AudacityMessageBox.h"
29#include "wxPanelWrapper.h"
30
31class LangChoiceDialog final : public wxDialogWrapper {
32public:
33 LangChoiceDialog(wxWindow * parent,
34 wxWindowID id,
36
37 wxString GetLang() { return mLang; }
38
39private:
40 void OnOk(wxCommandEvent & event);
41
42 wxChoice *mChoice;
43 wxString mLang;
44
46 wxArrayString mLangCodes;
48
49 DECLARE_EVENT_TABLE()
50};
51
52wxString ChooseLanguage(wxWindow *parent)
53{
54 wxString returnVal;
55
56 /* i18n-hint: Title on a dialog indicating that this is the first
57 * time Audacity has been run. */
58 LangChoiceDialog dlog(parent, -1, XO("Audacity First Run"));
59 dlog.CentreOnParent();
60 dlog.ShowModal();
61 returnVal = dlog.GetLang();
62
63 return returnVal;
64}
65
66BEGIN_EVENT_TABLE(LangChoiceDialog, wxDialogWrapper)
69
71 wxWindowID id,
73 wxDialogWrapper(parent, id, title)
74{
75 SetName();
76 const auto &paths = FileNames::AudacityPathList();
77 Languages::GetLanguages(paths, mLangCodes, mLangNames);
78 int lang = make_iterator_range( mLangCodes )
79 .index( Languages::GetSystemLanguageCode(paths) );
80
82
83 S.StartVerticalLay(false);
84 {
85 S.StartHorizontalLay();
86 {
87 S.SetBorder(15);
88 mChoice = S.AddChoice(XXO("Choose Language for Audacity to use:"),
89 mLangNames,
90 lang);
91 }
92 S.EndVerticalLay();
93
94 S.SetBorder(0);
95 S.AddStandardButtons(eOkButton);
96 }
97 S.EndVerticalLay();
98
99 Fit();
100}
101
102void LangChoiceDialog::OnOk(wxCommandEvent & WXUNUSED(event))
103{
104 int ndx = mChoice->GetSelection();
105 mLang = mLangCodes[ndx];
106
107 auto slang =
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}
int AudacityMessageBox(const TranslatableString &message, const TranslatableString &caption, long style, wxWindow *parent, int x, int y)
END_EVENT_TABLE()
EVT_BUTTON(wxID_NO, DependencyDialog::OnNo) EVT_BUTTON(wxID_YES
XO("Cut/Copy/Paste")
XXO("&Cut/Copy/Paste Toolbar")
wxString ChooseLanguage(wxWindow *parent)
Definition: LangChoice.cpp:52
IteratorRange< Iterator > make_iterator_range(const Iterator &i1, const Iterator &i2)
Definition: MemoryX.h:448
static const auto title
@ eIsCreating
Definition: ShuttleGui.h:37
@ eOkButton
Definition: ShuttleGui.h:599
#define S(N)
Definition: ToChars.cpp:64
std::vector< TranslatableString > TranslatableStrings
A dialog used (at start up) to present the user with a choice of languages for Audacity.
Definition: LangChoice.cpp:31
TranslatableStrings mLangNames
Definition: LangChoice.cpp:47
LangChoiceDialog(wxWindow *parent, wxWindowID id, const TranslatableString &title)
Definition: LangChoice.cpp:70
void OnOk(wxCommandEvent &event)
Definition: LangChoice.cpp:102
wxString GetLang()
Definition: LangChoice.cpp:37
wxArrayString mLangCodes
Definition: LangChoice.cpp:46
wxChoice * mChoice
Definition: LangChoice.cpp:42
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:630
Holds a msgid for the translation catalog; may also bind format arguments.
FILES_API const FilePaths & AudacityPathList()
A list of directories that should be searched for Audacity files (plug-ins, help files,...
wxString GetSystemLanguageCode(const FilePaths &pathList)
Definition: Languages.cpp:83
void GetLanguages(FilePaths pathList, wxArrayString &langCodes, TranslatableStrings &langNames)
Definition: Languages.cpp:140