Skip to content

I18N Internationalization

Required Configuration

The following configuration is needed to enable:

  • <AutoGenerateI18N> set to true in Tools.Config.props file
  • Create Strings folder in project file with language files:
    - 📁Strings
      - 📁zh-cn
        - 🗒️Resources.resw
      - 📁en-us
        - 🗒️Resources.resw
    The Resources.resw file usage is consistent with WinUI3 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 strings
    • I18N Helper class that directly returns localized strings
    • ResourceKey Keys automatically generated from resw files
    • LocaleExtension Localization helper class for xaml

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}" />