WindowsAppSDK icon indicating copy to clipboard operation
WindowsAppSDK copied to clipboard

Support PrimaryLanguageOverride from unpackaged apps

Open shelllet opened this issue 3 years ago • 25 comments

when calling the following code from an unpackaged app, it throws an error. This is needed to be able to use x:Uid localization in XAML and control the language it picks.

App::App()
{
    ...
    Windows::Globalization::ApplicationLanguages::PrimaryLanguageOverride(...)
    ...
}

shelllet avatar Oct 30 '21 10:10 shelllet

Hi @shelllet, this API isn't intended to work from an unpackaged context.

btueffers avatar Nov 01 '21 19:11 btueffers

Additionally, we've started a list of APIs like this that don't work from unpackaged apps that we need to either (1) document better with warnings so you know before you try using it, or (2) add new WinAppSDK APIs that work for unpackaged apps: #1702

andrewleader avatar Nov 01 '21 19:11 andrewleader

So what Api should I call to set the defualt language?

shelllet avatar Nov 01 '21 23:11 shelllet

@axelandrejs how should unpackaged apps set their default language for resolving resources and XAML localization?

andrewleader avatar Nov 01 '21 23:11 andrewleader

MRTCore determines the default language using Windows::Globalization::ApplicationLanguages::Languages (https://github.com/microsoft/WindowsAppSDK/blob/main/dev/MRTCore/mrt/Microsoft.Windows.ApplicationModel.Resources/src/ResourceContext.cpp#L106-L113)

huichen123 avatar Nov 02 '21 22:11 huichen123

@huichen123 but how should unpackaged apps change the default language for their app? As shelllet pointed out, in a packaged app, developers can call ApplicationLanguages::PrimaryLanguageOverride('en-us') to override the default language, but that API doesn't work for unpackaged apps. How should unpackaged apps override the default language when using MRT Core?

Many apps (including my own) allow the user to pick their own language independent from the OS language.

andrewleader avatar Nov 02 '21 23:11 andrewleader

Before PrimaryLanguageOverride is fixed, you may have to pass in a ResourceContext, and set its Language qualifier value to the desired value.

huichen123 avatar Nov 03 '21 16:11 huichen123

Before PrimaryLanguageOverride is fixed, you may have to pass in a ResourceContext, and set its Language qualifier value to the desired value.

Will these unpackaged API be fixed before GA version? This breaks x:Uid localization and seems to have no workaround.

seven-mile avatar Nov 11 '21 09:11 seven-mile

sorry, it will not be fixed for GA.

huichen123 avatar Nov 11 '21 20:11 huichen123

Re-opening this, as it's something we should implement at least someday so that unpackaged apps can use XAML x:Uid localization and control the language the app uses.

Tagging it as a bug too, this definitely is somewhere between bug and "feature", but since the overall scenario of localizing your unpackaged app with control over the language doesn't work, I'll add the bug tag.

andrewleader avatar Dec 06 '21 17:12 andrewleader

Hi @andrewleader any news? can we expect this feature/bugfix in WASDK 1.1/preview/experimental?

ghost1372 avatar Mar 15 '22 08:03 ghost1372

@huichen123 is the owner of this feature/bug and maybe can speak toward whether this would be in 1.1.

And FYI Mahdi, I moved to a different project in Microsoft, the right person to contact with general WinAppSDK questions would be marb2000. Thanks!

andrewleader avatar Mar 15 '22 18:03 andrewleader

@huichen123 Hi! Any news on this? Convenient globalization is an indispensable feature for unpackaged apps to use WinAppSDK. 😋

seven-mile avatar Apr 10 '22 11:04 seven-mile

Windows.Globalization.ApplicationLanguages was designed for packaged app. Instead of inventing local settings for unpackaged app, it might be easier WinUI can take ResourceManager/ResourceContext from app. @evelynwu-msft ?

huichen123 avatar Apr 11 '22 16:04 huichen123

Windows.Globalization.ApplicationLanguages was designed for packaged app. Instead of inventing local settings for unpackaged app, it might be easier WinUI can take ResourceManager/ResourceContext from app. @evelynwu-msft ?

Agreed with this. Language is not the only interesting setting here. EG, what about scale or theme? The way to set these is via the context, so that context should be exposed.

axelandrejs avatar Apr 11 '22 16:04 axelandrejs

Windows.Globalization.ApplicationLanguages was designed for packaged app. Instead of inventing local settings for unpackaged app, it might be easier WinUI can take ResourceManager/ResourceContext from app. @evelynwu-msft ?

Agreed with this. Language is not the only interesting setting here. EG, what about scale or theme? The way to set these is via the context, so that context should be exposed.

That's still on the books for 1.2ish (http://task.ms/37146452), but nothing is planned in this space for 1.1.

evelynwu-msft avatar Apr 11 '22 21:04 evelynwu-msft

Hello, is there any update on when will this be implemented? Currently, there is no easy way to localize the strings in XAML for an unpackaged app, which is very frustrating😞

Iris0905 avatar May 23 '22 23:05 Iris0905

As a workaround, I published a NuGet package called WinUI3Localizer (nuget.org/GitHub) that also works with unpackaged apps. It uses the general Resources.resw strings, so you should be able to switch back when the WinUI team comes with a solution 😎

AndrewKeepCoding avatar Jul 28 '22 01:07 AndrewKeepCoding

I am hitting this issue when attempting to support language changes from an unpackaged XAML islands (non-WinUI 3) app. The API works as expected when the app is packaged. What should I do? I don't think system XAML uses MRTCore.

sylveon avatar Feb 02 '23 00:02 sylveon

Is anyone working on this?

Blinue avatar Feb 21 '23 15:02 Blinue

any news? @evelynwu-msft we are in 1.4-preview1 and we cant change app language!

ghost1372 avatar Aug 03 '23 21:08 ghost1372

good news https://github.com/microsoft/WindowsAppSDK/pull/4181

ghost1372 avatar Feb 13 '24 09:02 ghost1372

Doesn't solve my problem :(

sylveon avatar Feb 13 '24 10:02 sylveon

I am hitting this issue when attempting to support language changes from an unpackaged XAML islands (non-WinUI 3) app. The API works as expected when the app is packaged. What should I do? I don't think system XAML uses MRTCore.

@sylveon Can you provide a sample app? Thanks.

stefansjfw avatar Feb 14 '24 09:02 stefansjfw

Any app using system XAML islands will fail when trying to use Windows::Globalization::ApplicationLanguages::PrimaryLanguageOverride without being packaged. WASDK cannot solve this without a complete migration to WinUI 3, which is non-trivial.

sylveon avatar Feb 14 '24 22:02 sylveon