Created
August 31, 2016 17:34
-
-
Save ChaseFlorell/8341e126e234aa11afdca330785c01ed to your computer and use it in GitHub Desktop.
Xamarin Forms Localization
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
// iOS | |
public class Localize : ILocalize | |
{ | |
private static CultureInfo _currentCulture; | |
public CultureInfo GetCurrentCultureInfo() | |
{ | |
if (_currentCulture != null) | |
{ | |
return _currentCulture; | |
} | |
var netLanguage = "en"; | |
if (NSLocale.PreferredLanguages.Length > 0) | |
{ | |
var pref = NSLocale.PreferredLanguages[0]; | |
if (pref == "pt") | |
pref = "pt-BR"; // get the correct Brazilian language strings from the PCL RESX | |
//(note the local iOS folder is still "pt") | |
netLanguage = pref.Replace("_", "-"); // turns es_ES into es-ES | |
} | |
if (CultureInfo.GetCultures(CultureTypes.AllCultures).Any(x => x.Name == netLanguage)) | |
{ | |
return _currentCulture = new CultureInfo(netLanguage); | |
} | |
return _currentCulture = new CultureInfo("en-US"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment