English
I18N Internationalization
To show your plugin in different languages, use .resw files just as you would in a normal WinUI project. The tool generates helpers for reading the text.
Prepare the language files
Set AutoGenerateI18N to true in Tools.Config.props, then create a folder for each language:
text
Strings/
en-us/
Resources.resw
zh-cn/
Resources.reswAdd a Download key to both Resources.resw files and give it a translation in each language. Keys become C# properties, so use valid identifiers such as Download.
Read text in code
Build the project once to generate helpers under {assembly name}.I18n. All three examples below read Download:
csharp
using ShadowExample.Plugin.Emoji.I18n;
string first = ResourcesHelper.GetString(ResourceKey.Download);
string second = ResourcesHelper.GetString("Download");
string third = I18N.Download;I18N.Download is usually the easiest option. Use ResourcesHelper.GetString(...) when you have a key name as a string at runtime.
Read text in XAML
Import the generated namespace and use Locale:
xml
<UserControl
x:Class="ShadowExample.Plugin.Emoji.Controls.UserControl1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:i18n="using:ShadowExample.Plugin.Emoji.I18n">
<TextBlock Text="{i18n:Locale Key=Download}" />
</UserControl>The namespace follows the assembly name. If you rename the assembly, update the code and XAML imports too.
Locale reads the text when XAML loads. If your app switches languages while running, refresh any text already on screen yourself.
When packaging
External plugins read their own resources, so load the plugin before using these helpers. Keep generated PRI and resource files in the package.
SDKs and built-in plugins marked [MainPlugin(BuiltIn = true)] read from the app's resources. Make sure those resources are deployed with the app.