Skip to content

Commit

Permalink
Hardcode the language list for the package manifest and settings drop…
Browse files Browse the repository at this point in the history
…down (#12375)

The `x-generate` statement seems to have fallen apart somewhere and is no longer generating the valid list of languages for display. This hardcodes the list into the manifest to restore it, which is a valid option per the documentation.

We also hardcode the limited subset of languages into the Settings application because the main application supports fewer languages than we have been translated into for the shell extensions for Windows Explorer and Start Menu integration.

## PR Checklist
* [x] Closes #12351
* [x] I work here.
* [x] Manual tests below

## Validation Steps Performed
- [x] Clean built locally with `msbuild.exe openconsole.sln /p:Configuration=Release /p:Platform=x64 /p:WindowsTerminalBranding=Release /t:Terminal\CascadiaPackage /m /bl:log4.binlog` and checked that the `appxmanifest.xml` that popped out the other side contained the same languages that it used to contain.
- [x] Built in the release pipeline
- [x] Installed release and preview branded packages. Changed my machine language to Polish (pl-PL) which is not one of the fully localized languages, but is one of the limited ones. Checked the start menu and right-click menus and saw Polish text for Terminal and Terminal Preview. Checked the Settings page in our app and saw only the limited 14 language list for the application itself.
  • Loading branch information
miniksa authored and DHowett committed Feb 9, 2022
1 parent 25e67fe commit 4eaeaad
Show file tree
Hide file tree
Showing 5 changed files with 214 additions and 35 deletions.
7 changes: 7 additions & 0 deletions .github/actions/spelling/expect/expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,7 @@ cygwin
CYHSCROLL
CYMIN
CYPADDEDBORDER
CYRL
CYSIZE
CYSIZEFRAME
CYSMICON
Expand Down Expand Up @@ -1237,12 +1238,14 @@ KLF
KLMNO
KLMNOPQRST
KLMNOPQRSTQQQQQ
KOK
KPRIORITY
KVM
langid
LANGUAGELIST
lasterror
lastexitcode
LATN
LAYOUTRTL
LBN
LBound
Expand Down Expand Up @@ -1789,6 +1792,9 @@ placeholders
platforming
playsound
plist
PLOC
PLOCA
PLOCM
PLOGICAL
plugin
PMv
Expand Down Expand Up @@ -1922,6 +1928,7 @@ qsort
queryable
QUESTIONMARK
quickedit
QUZ
QWER
qzmp
RAII
Expand Down
2 changes: 1 addition & 1 deletion src/cascadia/CascadiaPackage/Package-Dev.appxmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
</Dependencies>

<Resources>
<Resource Language="x-generate"/>
<Resource Language="EN-US" />
</Resources>

<Applications>
Expand Down
90 changes: 89 additions & 1 deletion src/cascadia/CascadiaPackage/Package-Pre.appxmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,95 @@
</Dependencies>

<Resources>
<Resource Language="x-generate"/>
<Resource Language="EN-US" />
<Resource Language="EN-GB" />
<Resource Language="AF-ZA" />
<Resource Language="AM-ET" />
<Resource Language="AR-SA" />
<Resource Language="AS-IN" />
<Resource Language="AZ-LATN-AZ" />
<Resource Language="BG-BG" />
<Resource Language="BN-IN" />
<Resource Language="BS-LATN-BA" />
<Resource Language="CA-ES" />
<Resource Language="CA-ES-VALENCIA" />
<Resource Language="CS-CZ" />
<Resource Language="CY-GB" />
<Resource Language="DA-DK" />
<Resource Language="DE-DE" />
<Resource Language="EL-GR" />
<Resource Language="ES-ES" />
<Resource Language="ES-MX" />
<Resource Language="ET-EE" />
<Resource Language="EU-ES" />
<Resource Language="FA-IR" />
<Resource Language="FI-FI" />
<Resource Language="FIL-PH" />
<Resource Language="FR-CA" />
<Resource Language="FR-FR" />
<Resource Language="GA-IE" />
<Resource Language="GD-GB" />
<Resource Language="GL-ES" />
<Resource Language="GU-IN" />
<Resource Language="HE-IL" />
<Resource Language="HI-IN" />
<Resource Language="HR-HR" />
<Resource Language="HU-HU" />
<Resource Language="HY-AM" />
<Resource Language="ID-ID" />
<Resource Language="IS-IS" />
<Resource Language="IT-IT" />
<Resource Language="JA-JP" />
<Resource Language="KA-GE" />
<Resource Language="KK-KZ" />
<Resource Language="KM-KH" />
<Resource Language="KN-IN" />
<Resource Language="KO-KR" />
<Resource Language="KOK-IN" />
<Resource Language="LB-LU" />
<Resource Language="LO-LA" />
<Resource Language="LT-LT" />
<Resource Language="LV-LV" />
<Resource Language="MI-NZ" />
<Resource Language="MK-MK" />
<Resource Language="ML-IN" />
<Resource Language="MR-IN" />
<Resource Language="MS-MY" />
<Resource Language="MT-MT" />
<Resource Language="NB-NO" />
<Resource Language="NE-NP" />
<Resource Language="NL-NL" />
<Resource Language="NN-NO" />
<Resource Language="OR-IN" />
<Resource Language="PA-IN" />
<Resource Language="PL-PL" />
<Resource Language="PT-BR" />
<Resource Language="PT-PT" />
<Resource Language="QPS-PLOC" />
<Resource Language="QPS-PLOCA" />
<Resource Language="QPS-PLOCM" />
<Resource Language="QUZ-PE" />
<Resource Language="RO-RO" />
<Resource Language="RU-RU" />
<Resource Language="SK-SK" />
<Resource Language="SL-SI" />
<Resource Language="SQ-AL" />
<Resource Language="SR-CYRL-BA" />
<Resource Language="SR-CYRL-RS" />
<Resource Language="SR-LATN-RS" />
<Resource Language="SV-SE" />
<Resource Language="TA-IN" />
<Resource Language="TE-IN" />
<Resource Language="TH-TH" />
<Resource Language="TR-TR" />
<Resource Language="TT-RU" />
<Resource Language="UG-CN" />
<Resource Language="UK-UA" />
<Resource Language="UR-PK" />
<Resource Language="UZ-LATN-UZ" />
<Resource Language="VI-VN" />
<Resource Language="ZH-CN" />
<Resource Language="ZH-TW" />
</Resources>

<Applications>
Expand Down
90 changes: 89 additions & 1 deletion src/cascadia/CascadiaPackage/Package.appxmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,95 @@
</Dependencies>

<Resources>
<Resource Language="x-generate"/>
<Resource Language="EN-US" />
<Resource Language="EN-GB" />
<Resource Language="AF-ZA" />
<Resource Language="AM-ET" />
<Resource Language="AR-SA" />
<Resource Language="AS-IN" />
<Resource Language="AZ-LATN-AZ" />
<Resource Language="BG-BG" />
<Resource Language="BN-IN" />
<Resource Language="BS-LATN-BA" />
<Resource Language="CA-ES" />
<Resource Language="CA-ES-VALENCIA" />
<Resource Language="CS-CZ" />
<Resource Language="CY-GB" />
<Resource Language="DA-DK" />
<Resource Language="DE-DE" />
<Resource Language="EL-GR" />
<Resource Language="ES-ES" />
<Resource Language="ES-MX" />
<Resource Language="ET-EE" />
<Resource Language="EU-ES" />
<Resource Language="FA-IR" />
<Resource Language="FI-FI" />
<Resource Language="FIL-PH" />
<Resource Language="FR-CA" />
<Resource Language="FR-FR" />
<Resource Language="GA-IE" />
<Resource Language="GD-GB" />
<Resource Language="GL-ES" />
<Resource Language="GU-IN" />
<Resource Language="HE-IL" />
<Resource Language="HI-IN" />
<Resource Language="HR-HR" />
<Resource Language="HU-HU" />
<Resource Language="HY-AM" />
<Resource Language="ID-ID" />
<Resource Language="IS-IS" />
<Resource Language="IT-IT" />
<Resource Language="JA-JP" />
<Resource Language="KA-GE" />
<Resource Language="KK-KZ" />
<Resource Language="KM-KH" />
<Resource Language="KN-IN" />
<Resource Language="KO-KR" />
<Resource Language="KOK-IN" />
<Resource Language="LB-LU" />
<Resource Language="LO-LA" />
<Resource Language="LT-LT" />
<Resource Language="LV-LV" />
<Resource Language="MI-NZ" />
<Resource Language="MK-MK" />
<Resource Language="ML-IN" />
<Resource Language="MR-IN" />
<Resource Language="MS-MY" />
<Resource Language="MT-MT" />
<Resource Language="NB-NO" />
<Resource Language="NE-NP" />
<Resource Language="NL-NL" />
<Resource Language="NN-NO" />
<Resource Language="OR-IN" />
<Resource Language="PA-IN" />
<Resource Language="PL-PL" />
<Resource Language="PT-BR" />
<Resource Language="PT-PT" />
<Resource Language="QPS-PLOC" />
<Resource Language="QPS-PLOCA" />
<Resource Language="QPS-PLOCM" />
<Resource Language="QUZ-PE" />
<Resource Language="RO-RO" />
<Resource Language="RU-RU" />
<Resource Language="SK-SK" />
<Resource Language="SL-SI" />
<Resource Language="SQ-AL" />
<Resource Language="SR-CYRL-BA" />
<Resource Language="SR-CYRL-RS" />
<Resource Language="SR-LATN-RS" />
<Resource Language="SV-SE" />
<Resource Language="TA-IN" />
<Resource Language="TE-IN" />
<Resource Language="TH-TH" />
<Resource Language="TR-TR" />
<Resource Language="TT-RU" />
<Resource Language="UG-CN" />
<Resource Language="UK-UA" />
<Resource Language="UR-PK" />
<Resource Language="UZ-LATN-UZ" />
<Resource Language="VI-VN" />
<Resource Language="ZH-CN" />
<Resource Language="ZH-TW" />
</Resources>

<Applications>
Expand Down
60 changes: 28 additions & 32 deletions src/cascadia/TerminalSettingsEditor/GlobalAppearance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,23 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
// --> "und" is synonymous for "Use system language".
constexpr std::wstring_view systemLanguageTag{ L"und" };

static constexpr std::array appLanguageTags{
L"en-US",
L"de-DE",
L"es-ES",
L"fr-FR",
L"it-IT",
L"ja",
L"ko",
L"pt-BR",
L"qps-PLOC",
L"qps-PLOCA",
L"qps-PLOCM",
L"ru",
L"zh-Hans-CN",
L"zh-Hant-TW",
};

GlobalAppearance::GlobalAppearance()
{
InitializeComponent();
Expand Down Expand Up @@ -88,43 +105,22 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
// [1]:
{
// ManifestLanguages contains languages the app ships with.
//
// Languages is a computed list that merges the ManifestLanguages with the
// user's ranked list of preferred languages taken from the system settings.
// As is tradition the API documentation is incomplete though, as it can also
// contain regional language variants. If our app supports en-US, but the user
// has en-GB or en-DE in their system's preferred language list, Languages will
// contain those as well, as they're variants from a supported language. We should
// allow a user to select those, as regional formattings can vary significantly.
const std::array tagSources{
winrt::Windows::Globalization::ApplicationLanguages::ManifestLanguages(),
winrt::Windows::Globalization::ApplicationLanguages::Languages()
};

// tags will hold all the flattened results from tagSources.
// We resize() the vector to the proper size in order to efficiently GetMany() all items.
tags.resize(std::accumulate(
tagSources.begin(),
tagSources.end(),
// tags[0] will be "und" - the "Use system language" item
// tags[1..n] will contain tags from tagSources.
// --> totalTags is offset by 1
1,
[](uint32_t sum, const auto& v) -> uint32_t {
return sum + v.Size();
}));
// Unfortunately, we cannot use this source. Our manifest must contain the
// ~100 languages that are localized for the shell extension and start menu
// presentation so we align with Windows display languages for those surfaces.
// However, the actual content of our application is limited to a much smaller
// subset of approximately 14 languages. As such, we will code the limited
// subset of languages that we support for selection within the Settings
// dropdown to steer users towards the ones that we can display in the app.

// As per the function definition, the first item
// is always "Use system language" ("und").
auto data = tags.data();
*data++ = systemLanguageTag;
tags.emplace_back(systemLanguageTag);

// Finally GetMany() all the tags from tagSources.
for (const auto& v : tagSources)
// Add our hardcoded languages after the system definition.
for (const auto& v : appLanguageTags)
{
const auto size = v.Size();
v.GetMany(0, winrt::array_view(data, size));
data += size;
tags.push_back(v);
}
}

Expand Down

0 comments on commit 4eaeaad

Please sign in to comment.