Hi ,
As mentioned in xamarin-forms localization , we have implemented the Localization to support multiple languages and its working fine with device locale.
Now ,we need to change the Application locale manually based on the user selection from the picker control in login screen.
We have tried the below code but AppResources are not changing as per the user selection locale.
Kindly suggest for iOS platform and Android Platform for manually changing the locale.
PCL - ILocalize.cs
void SetLocale(string Language);
PCL - View Model:
private int _LocaleSelectedIndex = 0;
public int LocaleSelectedIndex
{
get { return this._LocaleSelectedIndex; }
set
{
this._LocaleSelectedIndex = value;
if (Device.OS != TargetPlatform.WinPhone)
{
if (LocaleDescription[_LocaleSelectedIndex].ToString().ToUpper().Contains("ARABIC"))
DependencyService.Get<ILocalize>().SetLocale("ar-AE");
else
DependencyService.Get<ILocalize>().SetLocale("en-US");
DependencyService.Get<ILocalize>().SetLocale();
var netLanguage = DependencyService.Get<ILocalize>().GetCurrent();
Resx.AppResources.Culture = new CultureInfo(netLanguage);
}
this.OnPropertyChanged("LocaleSelectedIndex");
}
}
Android - Localize.cs
public void SetLocale(string language = "")
{
Locale locale = String.IsNullOrEmpty(language) ? new Locale("en-US") : new Locale(language);
Locale.Default = locale;
var config = new global::Android.Content.Res.Configuration();
config.Locale = locale;
var context = global::Android.App.Application.Context;
context.Resources.UpdateConfiguration(config, context.Resources.DisplayMetrics);
}
iOS - Localize.cs :
? // Kindly suggest Dependency implementation for iOS platform.