Skip to content

maxkoshevoi/XCTLocalizationDemo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

Localization demo using Xamarin.CommunityToolkit

Resources

Stars

Watchers

Forks

Languages