public static Task SetCultureAsync(Culture culture) { return(Task.Run(() => { _currentCultureIndex = (int)culture; //TODO: ver o que pode ser feito na parte de baixo para atualizar o idioma quando trocar de opção no picker switch (culture) { default: case Culture.English: //Lang.Lang.Culture = new CultureInfo("en-US"); _service.SetLocale(new CultureInfo("en-US")); break; case Culture.Portuguese: //Lang.Lang.Culture = new CultureInfo("pt-BR"); _service.SetLocale(new CultureInfo("pt-BR")); break; } var bdCollection = App.liteDB.GetCollection <SettingsPreferences>(); var settings = bdCollection.FindById(0); settings.SelectedLanguageIndex = _currentCultureIndex; bdCollection.Upsert(0, settings); })); }
void UpdateLanguage() { var langCode = Settings.SelectedLanguageCode; var ci = new CultureInfo(langCode); AppResources.Culture = ci; // set the RESX for resource localization _localize.SetLocale(ci); // set the Thread for locale-aware methods RaisePropertyChanged(nameof(AppName)); RaisePropertyChanged(nameof(ContactButton)); }
public App(IPlatformInitializer initializer = null) : base(initializer) { var localize = Container.Resolve <ILocalize>(); _localize = localize; if (Device.OS == TargetPlatform.iOS || Device.OS == TargetPlatform.Android) { LanguageSettings.CurrentCulture = _localize.GetCurrentCultureInfo(); AppResources.Culture = LanguageSettings.CurrentCulture; // set the RESX for resource localization _localize.SetLocale(LanguageSettings.CurrentCulture); // set the Thread for locale-aware methods } }
public App() { this.InitializeComponent(); // Setting language display in following: https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/localization?tabs=vswin#displaying-the-correct-language ILocalize localize = ViewModelLocator.Resolve <ILocalize>(); CultureInfo ci = localize.GetCurrentCultureInfo(); // Set the RESX for resource localization Resx.AppResources.Culture = ci; // Set the Thread for locale-aware methods localize.SetLocale(ci); }