Localization - Advanced
Switch Localization Resources at Runtime
If you need to switch the localization resources related to Semi Avalonia during the program's runtime, you can re-define the relevant string resources in the resource dictionary.
Semi Avalonia provides some helper functions to assist you in quickly achieving this switch.
Global Change
// Example method
public void ChangeCulture(CultureInfo culture)
{
SemiTheme.OverrideLocaleResources(Application.Current, new CultureInfo("zh-CN"));
}
Local Change
// Example method, executed within a control
public void ChangeCulture(CultureInfo culture)
{
SemiTheme.OverrideLocaleResources(this, new CultureInfo("zh-CN"));
}
Note: If the culture
you pass in is not defined in Semi Avalonia, no changes will be made to the resources. We welcome you to contribute code to Semi Avalonia and help us enrich the localization resources for other languages. You can refer to the example Add ja_jp Localization.