protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.contacts); _preferencesHelper = new PreferencesHelper(); _preferencesHelper.InitHepler(this); _version = FindViewById <TextView>(Resource.Id.appVersion); _lessons = FindViewById <TextView>(Resource.Id.lessons); _contactUs = FindViewById <TextView>(Resource.Id.contactUs); _supportUs = FindViewById <TextView>(Resource.Id.supportUs); _thanksButton = FindViewById <ImageButton>(Resource.Id.thanksButton); _lessonsLayout = FindViewById <View>(Resource.Id.lessonsLayout); _contactUsLayout = FindViewById <View>(Resource.Id.contactUsLayout); _supportUsLayout = FindViewById <View>(Resource.Id.supportUsLayout); _version.Text = $"{Resources.GetString(Resource.String.AppVersionLabel)} {PackageManager.GetPackageInfo(PackageName, PackageInfoFlags.Configurations).VersionName}"; _thanksButton.Click += OnThanksButtonClicked; var localizedPart = $"<font>{Resources.GetString(Resource.String.HaveQuestionsLabel)}</font><br>" + $"<font>{Resources.GetString(Resource.String.WriteUsLabel)} </font>"; string text = localizedPart + "<font color=#616161>[email protected]</font>"; _contactUs.SetText(Html.FromHtml(text), TextView.BufferType.Spannable); var selectedLocaleIndex = _preferencesHelper.GetSelectedLanguage(); if (selectedLocaleIndex != 0) { switch (selectedLocaleIndex) { case 1: _lessons.Text = "Language: English"; break; case 2: _lessons.Text = "Язык: Русский"; break; case 3: _lessons.Text = "Idioma: Español"; break; } } else { var currentLocale = Locale.Default; var enLocale = new Locale("en"); var ruLocale = new Locale("ru"); var esLocale = new Locale("es"); if (currentLocale.Language == enLocale.Language) { _lessons.Text = "Language: English"; } if (currentLocale.Language == ruLocale.Language) { _lessons.Text = "Язык: Русский"; } if (currentLocale.Language == esLocale.Language) { _lessons.Text = "Idioma: Español"; } } _supportUs.Text = Resources.GetString(Resource.String.SupportUsTitle); _lessonsLayout.Click += OnAppVersionClicked; _contactUsLayout.Click += OnContactUsClicked; _contactUsLayout.LongClick += OnContactUsLongClicked; _supportUsLayout.Click += OnSupportUsClicked; }
private void ApplyCulture() { var currentLocale = Locale.Default; var selectedLocaleIndex = _preferencesHelper.GetSelectedLanguage(); if (selectedLocaleIndex != 0) { switch (selectedLocaleIndex) { case 1: var enLocale = new Locale("en"); if (currentLocale.Language != enLocale.Language) { Locale.Default = enLocale; var config = new Configuration { Locale = enLocale }; BaseContext.Resources.UpdateConfiguration(config, BaseContext.Resources.DisplayMetrics); } break; case 2: var ruLocale = new Locale("ru"); if (currentLocale.Language != ruLocale.Language) { Locale.Default = ruLocale; var config1 = new Configuration { Locale = ruLocale }; BaseContext.Resources.UpdateConfiguration(config1, BaseContext.Resources.DisplayMetrics); } break; case 3: var esLocale = new Locale("es"); if (currentLocale.Language != esLocale.Language) { Locale.Default = esLocale; var config2 = new Configuration { Locale = esLocale }; BaseContext.Resources.UpdateConfiguration(config2, BaseContext.Resources.DisplayMetrics); } break; } return; } // Set default culture by phone culture var listOfRussianLocales = new List <Locale> { new Locale("ru"), new Locale("be"), new Locale("uk"), new Locale("az"), new Locale("hy"), new Locale("kk"), new Locale("ky"), new Locale("tt"), new Locale("uz") }; if (listOfRussianLocales.Any(t => t.Language == currentLocale.Language)) { var newLocale = new Locale("ru"); Locale.Default = newLocale; var config = new Configuration { Locale = newLocale }; BaseContext.Resources.UpdateConfiguration(config, BaseContext.Resources.DisplayMetrics); } var spanishLocale = new Locale("es"); if (currentLocale.Language == spanishLocale.Language) { Locale.Default = spanishLocale; var config = new Configuration { Locale = spanishLocale }; BaseContext.Resources.UpdateConfiguration(config, BaseContext.Resources.DisplayMetrics); } }