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#include "LangChoice.h"
17#include "IteratorX.h"
18
19#include <wx/defs.h>
20#include <wx/choice.h>
21#include <wx/stattext.h>
22
23#include "Languages.h"
24#include "ShuttleGui.h"
25#include "AudacityMessageBox.h"
26#include "wxPanelWrapper.h"
27
28class LangChoiceDialog final : public wxDialogWrapper {
29public:
30 LangChoiceDialog(wxWindow * parent,
31 wxWindowID id,
33
34 wxString GetLang() { return mLang; }
35
36private:
37 void OnOk(wxCommandEvent & event);
38
39 wxChoice *mChoice;
40 wxString mLang;
41
43 wxArrayString mLangCodes;
45
46 DECLARE_EVENT_TABLE()
47};
48
49wxString ChooseLanguage(wxWindow *parent)
50{
51 wxString returnVal;
52
53 /* i18n-hint: Title on a dialog indicating that this is the first
54 * time Audacity has been run. */
55 LangChoiceDialog dlog(parent, -1, XO("Audacity First Run"));
56 dlog.CentreOnParent();
57 dlog.ShowModal();
58 returnVal = dlog.GetLang();
59
60 return returnVal;
61}
62
63BEGIN_EVENT_TABLE(LangChoiceDialog, wxDialogWrapper)
66
68 wxWindowID id,
70 wxDialogWrapper(parent, id, title)
71{
72 SetName();
73 const auto &paths = FileNames::AudacityPathList();
74 Languages::GetLanguages(paths, mLangCodes, mLangNames);
75 int lang = make_iterator_range( mLangCodes )
76 .index( Languages::GetSystemLanguageCode(paths) );
77
79
80 S.StartVerticalLay(false);
81 {
82 S.StartHorizontalLay();
83 {
84 S.SetBorder(15);
85 mChoice = S.AddChoice(XXO("Choose Language for Audacity to use:"),
86 mLangNames,
87 lang);
88 }
89 S.EndVerticalLay();
90
91 S.SetBorder(0);
92 S.AddStandardButtons(eOkButton);
93 }
94 S.EndVerticalLay();
95
96 Fit();
97}
98
99void LangChoiceDialog::OnOk(wxCommandEvent & WXUNUSED(event))
100{
101 int ndx = mChoice->GetSelection();
102 mLang = mLangCodes[ndx];
103
104 auto slang =
106 int sndx = make_iterator_range( mLangCodes ).index( slang );
107 wxString sname;
108
109 if (sndx == wxNOT_FOUND) {
110 const wxLanguageInfo *sinfo = wxLocale::FindLanguageInfo(slang);
111 if (sinfo) {
112 sname = sinfo->Description;
113 }
114 }
115 else {
116 sname = mLangNames[sndx].Translation();
117 }
118
119 if (mLang.Left(2) != slang.Left(2)) {
120 /* i18n-hint: The %s's are replaced by translated and untranslated
121 * versions of language names. */
122 auto msg = XO("The language you have chosen, %s (%s), is not the same as the system language, %s (%s).")
123 .Format(mLangNames[ndx],
124 mLang,
125 sname,
126 slang);
127 if ( wxNO == AudacityMessageBox( msg, XO("Confirm"), wxYES_NO ) ) {
128 return;
129 }
130 }
131
132 EndModal(true);
133}
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")
IteratorRange< Iterator > make_iterator_range(const Iterator &i1, const Iterator &i2)
Definition: IteratorX.h:210
wxString ChooseLanguage(wxWindow *parent)
Definition: LangChoice.cpp:49
static const auto title
@ eIsCreating
Definition: ShuttleGui.h:37
@ eOkButton
Definition: ShuttleGui.h:609
#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:28
TranslatableStrings mLangNames
Definition: LangChoice.cpp:44
LangChoiceDialog(wxWindow *parent, wxWindowID id, const TranslatableString &title)
Definition: LangChoice.cpp:67
void OnOk(wxCommandEvent &event)
Definition: LangChoice.cpp:99
wxString GetLang()
Definition: LangChoice.cpp:34
wxArrayString mLangCodes
Definition: LangChoice.cpp:43
wxChoice * mChoice
Definition: LangChoice.cpp:39
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:640
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