[MRTCore] Add Microsoft.Windows.Globalization.ApplicationLanguages class#4181
[MRTCore] Add Microsoft.Windows.Globalization.ApplicationLanguages class#4181stefansjfw wants to merge 12 commits intomicrosoft:mainfrom
Conversation
|
/azp run |
|
Commenter does not have sufficient privileges for PR 4181 in repo microsoft/WindowsAppSDK |
|
while doubtful /azp run |
|
/azp run |
|
Commenter does not have sufficient privileges for PR 4181 in repo microsoft/WindowsAppSDK |
|
This is needed for PowerToys to fully enable language override |
| static hstring PrimaryLanguageOverride(); | ||
|
|
||
| private: | ||
| static hstring m_language; |
There was a problem hiding this comment.
wil::srwlock could be used to protect access to this variable.
...soft.Windows.ApplicationModel.Resources/src/Microsoft.Windows.ApplicationModel.Resources.idl
Show resolved
Hide resolved
...soft.Windows.ApplicationModel.Resources/src/Microsoft.Windows.ApplicationModel.Resources.idl
Show resolved
Hide resolved
...soft.Windows.ApplicationModel.Resources/src/Microsoft.Windows.ApplicationModel.Resources.idl
Show resolved
Hide resolved
jeffstall
left a comment
There was a problem hiding this comment.
I've added comments. Please address and update.
dev/MRTCore/mrt/Microsoft.Windows.ApplicationModel.Resources/src/ApplicationLanguages.cpp
Outdated
Show resolved
Hide resolved
eafa77e to
410c575
Compare
...soft.Windows.ApplicationModel.Resources/src/Microsoft.Windows.ApplicationModel.Resources.idl
Outdated
Show resolved
Hide resolved
Thread safe PrimaryLanguageOverride for un-packaged Use W.G.PrimaryLanguageOverride for packaged
dev/MRTCore/mrt/Microsoft.Windows.ApplicationModel.Resources/src/ApplicationLanguages.cpp
Show resolved
Hide resolved
| winrt::check_hresult(MrmSetQualifier(m_resourceContext, eachValue.Key().c_str(), eachValue.Value().c_str())); | ||
| } | ||
| } | ||
| if (!ApplicationLanguages::PrimaryLanguageOverride().empty()) |
There was a problem hiding this comment.
With W.G.PrimaryLanguageOverride set, newly created ResourceContext takes PrimaryLanguageOverride into account, i.e. does not override language QualifierValue to default language.
There was a problem hiding this comment.
e.g. if default language is "en-US", PrimaryLanguageOverride is "de-DE", and ResourceContext["Lanauge"]="fr-FR", what's the language that will take effect? I'd think "fr-FR"
There was a problem hiding this comment.
according to this logic, no, PrimaryLanguageOverride should take precedence over ResourceContext["Language"]. GetLangugageContext returns Windows::Globalization::ApplicationLanguages::Languages() which is affected if W.G.PrimaryLanguageOverride is set. This behavior remains the same with this change
There was a problem hiding this comment.
I think in that logic ResourceContext["Language"] still takes precedence. It would be strange to the caller that an explicit request is not honored
There was a problem hiding this comment.
Got it now. You're right. Fixed by latest change. Now explicit set of context Language is not overridden by PrimaryLanguageOverride.
I tested with this WinAppSDK sample. Default language is PrimaryLanguageOverride - de-DE, but fetching resources with m_overrideResourceContext passed is fetching it-IT resources:
Check if valid language tag is passed to PrimaryLanguageOverride
|
note: changing namespace to Microsoft.Windows.Globalization.ApplicationLanguages is in progress (as decided during API review) |
change pushed |
|
|
||
| THROW_HR_IF_MSG(E_INVALIDARG, !isValidLanguageTag, "The parameter is incorrect"); | ||
|
|
||
| static wil::srwlock lock; |
There was a problem hiding this comment.
You have to use the same lock for reading and writing. Otherwise the setter could take an exclusive lock, but another thread could still read the data.
| return GetDefaultPriFileForCurentModule(isPackaged, filePath); | ||
| } | ||
|
|
||
| bool IsWellFormedLanguageTag(const wchar_t* languageTag) |
There was a problem hiding this comment.
There was a problem hiding this comment.
done. I don't have this header, so I reused the logic to load the DLL manually as in platform.h/.cpp. Tested. Works as expected.
There was a problem hiding this comment.
the header should be in SDK. The LoadLibrary code was written before it's added into SDK.
There was a problem hiding this comment.
according to the docs it should be there since Windows 10 Build 17763, but I don't have it on machine (OS version 10.0.22631 Build 22631), VS 22 installed with multiple SDK versions. I double-checked on another machine with the same software versions
There was a problem hiding this comment.
I double-checked again, the header is present in SDK v10.0.20348.0 (and later), even though docs says it should be there before
There was a problem hiding this comment.
Is bumping WindowsTargetPlatformVersion to 10.0.20348.0 for this specific project ok to do ?
There was a problem hiding this comment.
I pushed the change (including WindowsTargetPlatformVersion bump). I'll revert if it's not ok
6f37f5c to
2d1c892
Compare
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
This has been merged as #4523 |

Changing the application language using PrimaryLanguageOverride property from
Windows.Globalization.ApplicationLanguagesnamespace is not supported for WindowsAppSDK unpackaged apps, only for packaged. To support language change for un-packaged applicationsMicrosoft.Windows.Globalization.ApplicationLanguages.ApplicationLanguagestype is introduced in MRTCore.Microsoft.Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverrideproperty is supported both for packaged and un-packaged WindowsAppSDK apps.Sample app used to verify the change: https://github.com/stefansjfw/testwasdk/blob/master/testlocalwinappsdk/App.xaml.cs#L36
A microsoft employee must use /azp run to validate using the pipelines below.
WARNING:
Comments made by azure-pipelines bot maybe inaccurate.
Please see pipeline link to verify that the build is being ran.
For status checks on the main branch, please use TransportPackage-Foundation-PR
(https://microsoft.visualstudio.com/ProjectReunion/_build?definitionId=81063&_a=summary)
and run the build against your PR branch with the default parameters.