Skip to content
This repository has been archived by the owner on Dec 10, 2020. It is now read-only.

Commit

Permalink
Fix default language set as cs and datatime format bugs.
Browse files Browse the repository at this point in the history
  • Loading branch information
zzcodework committed Jun 15, 2016
1 parent 99607fe commit 92dbf03
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions Web/Helpers/CultureHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,35 @@ public static CultureInfo GetClosestCulture(string cultureName)
return GetDefaultCulture(); // return Default culture if it is invalid
}

// if it is implemented, accept it
if (ImplementedCultureNames.Any(culture => culture.Equals(cultureName, StringComparison.InvariantCultureIgnoreCase)))
// Get the neutral culture of specific culture passed in
var neutralCultureName = GetNeutralCultureName(cultureName);

// If the neutral culture is implemented, accept the specific culture
if (ImplementedCultureNames.Any(culture => culture.StartsWith(neutralCultureName, StringComparison.Ordinal)))
{
return new CultureInfo(cultureName); // accept it
}

// Find a close match. For example, if you have "en-US" defined and the user requests "en-GB",
// the function will return closes match that is "en-US" because at least the language is the same (ie English)
var neutralCultureName = GetNeutralCultureName(cultureName);
var closestCultureName = ImplementedCultureNames.FirstOrDefault(culture => culture.StartsWith(neutralCultureName));
var closestCultureName = ImplementedCultureNames.FirstOrDefault(culture => culture.StartsWith(neutralCultureName, StringComparison.Ordinal));

return closestCultureName != null ? new CultureInfo(closestCultureName) : GetDefaultCulture();
}

public static CultureInfo GetDefaultCulture()
{
return new CultureInfo(ImplementedCultureNames.First()); // return Default culture
// The first culture in implemented list is cs, change default culture to en if it's exist
var defaultCulture = "en";

if (ImplementedCultureNames.Any(x => x.Equals(defaultCulture, StringComparison.InvariantCultureIgnoreCase)))
{
return new CultureInfo(defaultCulture);
}
else
{
return new CultureInfo(ImplementedCultureNames.First());
}
}

public static CultureInfo GetCurrentCulture()
Expand Down

0 comments on commit 92dbf03

Please sign in to comment.