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