question

ApptacularApps-8305 avatar image
0 Votes"
ApptacularApps-8305 asked agentbanking-51060210-0299 Suspended answered

How to use Windows system-provided "OK" string resource as CloseButtonText in ContentDialog

Is there a way to use the 'OK' string resource the Windows operating system provides for dialogs containing an OK button? Using hard coding isn't professional when translating to languages that don't use "OK" as the text for an OK button.

 private async void DisplayNoWifiDialog()
 {
     ContentDialog noWifiDialog = new ContentDialog
     {
         Title = "No wifi connection",
         Content = "Check your connection and try again.",
         CloseButtonText = "OK"
     };
    
     ContentDialogResult result = await noWifiDialog.ShowAsync();
 }


windows-uwp
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hello, do you have any other questions?

0 Votes 0 ·

1 Answer

RichardZhang-MSFT avatar image
1 Vote"
RichardZhang-MSFT answered

Hello,

Welcome to Microsoft Q&A.

If you want to use multiple languages (localization) in UWP, you need to create a text resource file (.resw). Currently, there is no API to obtain the built-in text resources of the system by name.

How to build your multilingual text resource file, please refer to this document: Make your app localizable.

After creating the text resource file, you can get the text resource currently being used by the application through the following code, and get the corresponding value by name:

 public string GetLocalizationTextFromResource(string key)
 {
     var loader = ResourceLoader.GetForCurrentView();
     var language = loader.GetString(key);
     return language;
 }

Then we can use:

 ContentDialog noWifiDialog = new ContentDialog
 {
     Title = "No wifi connection",
     Content = "Check your connection and try again.",
     CloseButtonText = GetLocalizationTextFromResource("OK")
 };

Thanks.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.