Skip to content

Latest commit

 

History

History
41 lines (30 loc) · 1.55 KB

File metadata and controls

41 lines (30 loc) · 1.55 KB

XCTLocalizationDemo

App localization demo using Xamarin.CommunityToolkit

Useful links

How to use XCT localization?

  1. In App.xaml.cs
  • Initialize LocalizationResourceManager with your resouce manager and optionally initial culture;
  • Subscribe to PropertyChanged to ensure that culture for AppResources is updated when LocalizationResourceManager.Current.CurrentCulture is updated.
LocalizationResourceManager.Current.PropertyChanged += (_, _) => AppResources.Culture = LocalizationResourceManager.Current.CurrentCulture;
LocalizationResourceManager.Current.Init(AppResources.ResourceManager, initialCulture);
  1. For static strings that use xct:Translate.
<ContentPage Title="{xct:Translate AppName}">
  1. For dynamily generated strings use LocalizedString (currently in preview).
public LocalizedString AppVersion { get; } = new(() => string.Format(AppResources.Version, AppInfo.VersionString));
<Label Text="{Binding AppVersion.Localized}"/>
  1. That's it. Now just do this when you need to change current culture:
LocalizationResourceManager.Current.CurrrentCulture = newCulture;

And after that every resource string in the program will be automatically updated.