forked from Sneeds-Feed-and-Seed/sneedacity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLangChoice.cpp
138 lines (107 loc) · 3.41 KB
/
LangChoice.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/**********************************************************************
Sneedacity: A Digital Audio Editor
LangChoice.cpp
Dominic Mazzoni
*******************************************************************//*!
\class LangChoiceDialog
\brief A dialog used (at start up) to present the user with a choice
of languages for Sneedacity.
*//*******************************************************************/
#include "LangChoice.h"
#include <wx/defs.h>
#include <wx/button.h>
#include <wx/choice.h>
#include <wx/intl.h>
#include <wx/sizer.h>
#include <wx/stattext.h>
#include "Languages.h"
#include "ShuttleGui.h"
#include "widgets/SneedacityMessageBox.h"
#include "widgets/wxPanelWrapper.h"
class LangChoiceDialog final : public wxDialogWrapper {
public:
LangChoiceDialog(wxWindow * parent,
wxWindowID id,
const TranslatableString & title);
wxString GetLang() { return mLang; }
private:
void OnOk(wxCommandEvent & event);
wxChoice *mChoice;
wxString mLang;
int mNumLangs;
wxArrayString mLangCodes;
TranslatableStrings mLangNames;
DECLARE_EVENT_TABLE()
};
wxString ChooseLanguage(wxWindow *parent)
{
wxString returnVal;
/* i18n-hint: Title on a dialog indicating that this is the first
* time Sneedacity has been run. */
LangChoiceDialog dlog(parent, -1, XO("Sneedacity First Run"));
dlog.CentreOnParent();
dlog.ShowModal();
returnVal = dlog.GetLang();
return returnVal;
}
BEGIN_EVENT_TABLE(LangChoiceDialog, wxDialogWrapper)
EVT_BUTTON(wxID_OK, LangChoiceDialog::OnOk)
END_EVENT_TABLE()
LangChoiceDialog::LangChoiceDialog(wxWindow * parent,
wxWindowID id,
const TranslatableString & title):
wxDialogWrapper(parent, id, title)
{
SetName();
const auto &paths = FileNames::SneedacityPathList();
Languages::GetLanguages(paths, mLangCodes, mLangNames);
int lang = make_iterator_range( mLangCodes )
.index( Languages::GetSystemLanguageCode(paths) );
ShuttleGui S(this, eIsCreating);
S.StartVerticalLay(false);
{
S.StartHorizontalLay();
{
S.SetBorder(15);
mChoice = S.AddChoice(XXO("Choose Language for Sneedacity to use:"),
mLangNames,
lang);
}
S.EndVerticalLay();
S.SetBorder(0);
S.AddStandardButtons(eOkButton);
}
S.EndVerticalLay();
Fit();
}
void LangChoiceDialog::OnOk(wxCommandEvent & WXUNUSED(event))
{
int ndx = mChoice->GetSelection();
mLang = mLangCodes[ndx];
auto slang =
Languages::GetSystemLanguageCode(FileNames::SneedacityPathList());
int sndx = make_iterator_range( mLangCodes ).index( slang );
wxString sname;
if (sndx == wxNOT_FOUND) {
const wxLanguageInfo *sinfo = wxLocale::FindLanguageInfo(slang);
if (sinfo) {
sname = sinfo->Description;
}
}
else {
sname = mLangNames[sndx].Translation();
}
if (mLang.Left(2) != slang.Left(2)) {
/* i18n-hint: The %s's are replaced by translated and untranslated
* versions of language names. */
auto msg = XO("The language you have chosen, %s (%s), is not the same as the system language, %s (%s).")
.Format(mLangNames[ndx],
mLang,
sname,
slang);
if ( wxNO == SneedacityMessageBox( msg, XO("Confirm"), wxYES_NO ) ) {
return;
}
}
EndModal(true);
}