Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
using System;
using System.Globalization;
using System.Linq;
using System.Threading;
using Java.Util;
using MyApp.Droid;
using MyApp.il8n;
using Xamarin.Forms;
[assembly: Dependency(typeof(Localize))]
namespace MyApp.Droid
public class Localize : ILocalize
#region Public Methods
public CultureInfo GetCurrentCultureInfo()
var androidLocale = Locale.Default;
var language = androidLocale.ToString().Replace("_", "-");
var cultures = CultureInfo.GetCultures(CultureTypes.AllCultures);
if (!cultures.Any(c => c.Name == language))
language = "en";
return new CultureInfo(language);
public void SetLocale()
var culture = GetCurrentCultureInfo();
Thread.CurrentThread.CurrentCulture = culture;
Thread.CurrentThread.CurrentUICulture = culture;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment