#How to test WinUI 3 app different languages?
1 messages · Page 1 of 1 (latest)
You could add a feature to your app that allows you to change only the app's language, however you'll need a library for that, there's one I saw called WinUI3Localizer
Winuicommunity templates as an add extension in vs code has a great localization of strings .
public static class DynamicLocalizerHelper
{
private static string StringsFolderPath { get; set; } = string.Empty;
public static async Task InitializeLocalizer(params string[] languages)
{
// Initialize a "Strings" folder in the "LocalFolder" for the packaged app.
if (PackageHelper.IsPackaged)
{
// Create string resources file from app resources if doesn't exists.
StorageFolder localFolder = ApplicationData.Current.LocalFolder;
StorageFolder stringsFolder = await localFolder.CreateFolderAsync(
"Strings",
CreationCollisionOption.OpenIfExists);
string resourceFileName = "Resources.resw";
foreach (var item in languages)
{
await LocalizerBuilder.CreateStringResourceFileIfNotExists(stringsFolder, item, resourceFileName);
}
StringsFolderPath = stringsFolder.Path;
}
else
{
// Initialize a "Strings" folder in the executables folder.
StringsFolderPath = Path.Combine(AppContext.BaseDirectory, "Strings");
var stringsFolder = await StorageFolder.GetFolderFromPathAsync(StringsFolderPath);
}
ILocalizer localizer = await new LocalizerBuilder()
.AddStringResourcesFolderForLanguageDictionaries(StringsFolderPath)
.SetOptions(options =>
{
options.DefaultLanguage = "en-US";
})
.Build();
}
}
Call this in your app.xaml.cs
await DynamicLocalizerHelper.InitializeLocalizer("en-US");