Created
February 21, 2018 22:17
-
-
Save matthewrdev/fe6b3dc9e34c4fad46029e26a0b1f25a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
#endregion | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment