I have only the country name and I need the Culture. I tried by region:
Dim region As New RegionInfo("USA")
Is there a way to get Culture Info by country name only?
I have only the country name and I need the Culture. I tried by region:
Dim region As New RegionInfo("USA")
Is there a way to get Culture Info by country name only?
You could this class i've created only just (so not really tested):
public class CountryCultureInfo
{
static CountryCultureInfo()
{
countryCultures = new Dictionary<string, HashSet<CultureInfo>>(StringComparer.InvariantCultureIgnoreCase);
foreach (CultureInfo culture in CultureInfo.GetCultures(CultureTypes.SpecificCultures))
{
RegionInfo region = new RegionInfo(culture.Name);
HashSet<CultureInfo> cultures;
if (!countryCultures.TryGetValue(region.ThreeLetterISORegionName, out cultures))
cultures = new HashSet<CultureInfo>();
cultures.Add(culture);
countryCultures[region.ThreeLetterISORegionName] = cultures;
}
}
private static Dictionary<string, HashSet<CultureInfo>> countryCultures;
public static HashSet<CultureInfo> GetCultures(string threeLetterISORegionName)
{
HashSet<CultureInfo> cultures;
countryCultures.TryGetValue(threeLetterISORegionName, out cultures);
return cultures;
}
}
If you want to get all cultures in the USA:
var allCulturesInUSA = CountryCultureInfo.GetCultures("USA"); // en-US, es-US
or in brasil:
var allCulturesInBrasil = CountryCultureInfo.GetCultures("BRA"); // pt-BR
Edit: sorry, here's the VB.NET version (overlooked the tag):
Public Class CountryCultureInfo
Shared Sub New()
countryCultures = New Dictionary(Of String, HashSet(Of CultureInfo))(StringComparer.InvariantCultureIgnoreCase)
For Each culture As CultureInfo In CultureInfo.GetCultures(CultureTypes.SpecificCultures)
Dim region As New RegionInfo(culture.Name)
Dim cultures As HashSet(Of CultureInfo) = Nothing
If Not countryCultures.TryGetValue(region.ThreeLetterISORegionName, cultures) Then
cultures = New HashSet(Of CultureInfo)()
End If
cultures.Add(culture)
countryCultures(region.ThreeLetterISORegionName) = cultures
Next
End Sub
Private Shared countryCultures As Dictionary(Of String, HashSet(Of CultureInfo))
Public Shared Function GetCultures(threeLetterISORegionName As String) As HashSet(Of CultureInfo)
Dim cultures As HashSet(Of CultureInfo) = Nothing
countryCultures.TryGetValue(threeLetterISORegionName, cultures)
Return cultures
End Function
End Class