Xie Steven
Xie Steven

Reputation: 8591

How to initialize `LocalizationResourceManager`

I found the LocalizationResourceManager class. It enables users to respond to culture changes at runtime. But I found that it need to initialize with just one ResourceManager LocalizationResourceManager.Current.Init(AppResources.ResourceManager);. It doesn't make sense.

In my app, there're many pages and I also create many resx files for the specific page. For example,

-- Resx

----Main

--------MainResource.resx

--------MainResource.en-US.resx

--------MainResource.es.resx

--------MainResource.ja.resx

----Setting

--------SettingResource.resx

--------SettingResource.en-US.resx

--------SettingResource.ja.resx

......

In this case, How to initialize LocalizationResourceManager?

Upvotes: 1

Views: 557

Answers (1)

ColeX
ColeX

Reputation: 14475

Here AppResources represents your resource file , modify your code as below

LocalizationResourceManager.Current.PropertyChanged += (sender, e) => MainResource.Culture = LocalizationResourceManager.Current.CurrentCulture;
LocalizationResourceManager.Current.Init(MainResource.ResourceManager);
LocalizationResourceManager.Current.CurrentCulture = new CultureInfo("en");

Check official sample :

enter image description here

https://github.com/xamarin/XamarinCommunityToolkit/tree/main/samples .

Upvotes: 1

Related Questions