7
7
#include " EnumEntry.h"
8
8
9
9
#include < LibraryResources.h>
10
- #include < WtExeUtils.h>
11
10
12
11
using namespace winrt ;
13
12
using namespace winrt ::Windows::UI::Xaml;
@@ -18,28 +17,6 @@ using namespace winrt::Windows::Foundation::Collections;
18
17
19
18
namespace winrt ::Microsoft::Terminal::Settings::Editor::implementation
20
19
{
21
- // For ComboBox an empty SelectedItem string denotes no selection.
22
- // What we want instead is for "Use system language" to be selected by default.
23
- // --> "und" is synonymous for "Use system language".
24
- constexpr std::wstring_view systemLanguageTag{ L" und" };
25
-
26
- static constexpr std::array appLanguageTags{
27
- L" en-US" ,
28
- L" de-DE" ,
29
- L" es-ES" ,
30
- L" fr-FR" ,
31
- L" it-IT" ,
32
- L" ja" ,
33
- L" ko" ,
34
- L" pt-BR" ,
35
- L" qps-PLOC" ,
36
- L" qps-PLOCA" ,
37
- L" qps-PLOCM" ,
38
- L" ru" ,
39
- L" zh-Hans" ,
40
- L" zh-Hant" ,
41
- };
42
-
43
20
constexpr std::wstring_view systemThemeName{ L" system" };
44
21
constexpr std::wstring_view darkThemeName{ L" dark" };
45
22
constexpr std::wstring_view lightThemeName{ L" light" };
@@ -56,146 +33,6 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
56
33
_UpdateThemeList ();
57
34
}
58
35
59
- winrt::hstring GlobalAppearanceViewModel::LanguageDisplayConverter (const winrt::hstring& tag)
60
- {
61
- if (tag == systemLanguageTag)
62
- {
63
- return RS_ (L" Globals_LanguageDefault" );
64
- }
65
-
66
- winrt::Windows::Globalization::Language language{ tag };
67
- return language.NativeName ();
68
- }
69
-
70
- // Returns whether the language selector is available/shown.
71
- //
72
- // winrt::Windows::Globalization::ApplicationLanguages::PrimaryLanguageOverride()
73
- // doesn't work for unpackaged applications. The corresponding code in TerminalApp is disabled.
74
- // It would be confusing for our users if we presented a dysfunctional language selector.
75
- bool GlobalAppearanceViewModel::LanguageSelectorAvailable ()
76
- {
77
- return IsPackaged ();
78
- }
79
-
80
- // Returns the list of languages the user may override the application language with.
81
- // The returned list are BCP 47 language tags like {"und", "en-US", "de-DE", "es-ES", ...}.
82
- // "und" is short for "undefined" and is synonymous for "Use system language" in this code.
83
- winrt::Windows::Foundation::Collections::IObservableVector<winrt::hstring> GlobalAppearanceViewModel::LanguageList ()
84
- {
85
- if (_languageList)
86
- {
87
- return _languageList;
88
- }
89
-
90
- if (!LanguageSelectorAvailable ())
91
- {
92
- _languageList = {};
93
- return _languageList;
94
- }
95
-
96
- // In order to return the language list this code does the following:
97
- // [1] Get all possible languages we want to allow the user to choose.
98
- // We have to acquire languages from multiple sources, creating duplicates. See below at [1].
99
- // [2] Sort languages by their ASCII tags, forcing the UI in a consistent/stable order.
100
- // I wanted to sort the localized language names initially, but it turned out to be complex.
101
- // [3] Remove potential duplicates in our language list from [1].
102
- // We don't want to have en-US twice in the list, do we?
103
- // [4] Optionally remove unwanted language tags (like pseudo-localizations).
104
-
105
- std::vector<winrt::hstring> tags;
106
-
107
- // [1]:
108
- {
109
- // ManifestLanguages contains languages the app ships with.
110
- // Unfortunately, we cannot use this source. Our manifest must contain the
111
- // ~100 languages that are localized for the shell extension and start menu
112
- // presentation so we align with Windows display languages for those surfaces.
113
- // However, the actual content of our application is limited to a much smaller
114
- // subset of approximately 14 languages. As such, we will code the limited
115
- // subset of languages that we support for selection within the Settings
116
- // dropdown to steer users towards the ones that we can display in the app.
117
-
118
- // As per the function definition, the first item
119
- // is always "Use system language" ("und").
120
- tags.emplace_back (systemLanguageTag);
121
-
122
- // Add our hard-coded languages after the system definition.
123
- for (const auto & v : appLanguageTags)
124
- {
125
- tags.push_back (v);
126
- }
127
- }
128
-
129
- // NOTE: The size of tags is always >0, due to tags[0] being hard-coded to "und".
130
- const auto tagsBegin = ++tags.begin ();
131
- const auto tagsEnd = tags.end ();
132
-
133
- // [2]:
134
- std::sort (tagsBegin, tagsEnd);
135
-
136
- // I'd love for both, std::unique and std::remove_if, to occur in a single loop,
137
- // but the code turned out to be complex and even less maintainable, so I gave up.
138
- {
139
- // [3] part 1:
140
- auto it = std::unique (tagsBegin, tagsEnd);
141
-
142
- // The qps- languages are useful for testing ("pseudo-localization").
143
- // --> Leave them in if debug features are enabled.
144
- if (!_GlobalSettings.DebugFeaturesEnabled ())
145
- {
146
- // [4] part 1:
147
- it = std::remove_if (tagsBegin, it, [](const winrt::hstring& tag) -> bool {
148
- return til::starts_with (tag, L" qps-" );
149
- });
150
- }
151
-
152
- // [3], [4] part 2 (completing the so called "erase-remove idiom"):
153
- tags.erase (it, tagsEnd);
154
- }
155
-
156
- _languageList = winrt::single_threaded_observable_vector (std::move (tags));
157
- return _languageList;
158
- }
159
-
160
- winrt::Windows::Foundation::IInspectable GlobalAppearanceViewModel::CurrentLanguage ()
161
- {
162
- if (_currentLanguage)
163
- {
164
- return _currentLanguage;
165
- }
166
-
167
- if (!LanguageSelectorAvailable ())
168
- {
169
- _currentLanguage = {};
170
- return _currentLanguage;
171
- }
172
-
173
- // NOTE: PrimaryLanguageOverride throws if this instance is unpackaged.
174
- auto currentLanguage = winrt::Windows::Globalization::ApplicationLanguages::PrimaryLanguageOverride ();
175
- if (currentLanguage.empty ())
176
- {
177
- currentLanguage = systemLanguageTag;
178
- }
179
-
180
- _currentLanguage = winrt::box_value (currentLanguage);
181
- return _currentLanguage;
182
- }
183
-
184
- void GlobalAppearanceViewModel::CurrentLanguage (const winrt::Windows::Foundation::IInspectable& tag)
185
- {
186
- _currentLanguage = tag;
187
-
188
- const auto currentLanguage = winrt::unbox_value<winrt::hstring>(_currentLanguage);
189
- if (currentLanguage == systemLanguageTag)
190
- {
191
- _GlobalSettings.ClearLanguage ();
192
- }
193
- else
194
- {
195
- _GlobalSettings.Language (currentLanguage);
196
- }
197
- }
198
-
199
36
// Function Description:
200
37
// - Updates the list of all themes available to choose from.
201
38
void GlobalAppearanceViewModel::_UpdateThemeList ()
0 commit comments