I18N Internationalization
Required Configuration
The following configuration is needed to enable:
<AutoGenerateI18N>
set totrue
in Tools.Config.props file- Create
Strings
folder in project file with language files:The- 📁Strings - 📁zh-cn - 🗒️Resources.resw - 📁en-us - 🗒️Resources.resw
Resources.resw
file usage is consistent withWinUI3
projects.
Generation
After the required configuration, build the project once.
The following classes will be automatically generated:
{Project Namespace}.I18n
ResourcesHelper
Helper class for reading localized stringsI18N
Helper class that directly returns localized stringsResourceKey
Keys automatically generated fromresw
filesLocaleExtension
Localization helper class forxaml
ResourcesHelper
Example usage:
csharp
// Use the Download value from resw
string downloadStr = ResourcesHelper.GetString(ResourceKey.Download);
I18N
Example usage:
csharp
// Use the Download value from resw
string downloadStr = I18N.Download;
Note
I18N.Download
is equivalent to ResourcesHelper.GetString(ResourceKey.Download)
LocaleExtension
Example usage:
Reference namespace at the top of xaml
file:
xmlns:ex="using:ShadowViewer.I18n"
xml
<TextBlock Text="{ex:Locale Key=Download}" />