Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code Tidyup #13

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using System.Threading;

public static class CultureHelper {
private static readonly IList<string> _validCultures = new List<string> { "af", "af-ZA", "sq", "sq-AL", "gsw-FR", "am-ET", "ar", "ar-DZ", "ar-BH", "ar-EG", "ar-IQ", "ar-JO", "ar-KW", "ar-LB", "ar-LY", "ar-MA", "ar-OM", "ar-QA", "ar-SA", "ar-SY", "ar-TN", "ar-AE", "ar-YE", "hy", "hy-AM", "as-IN", "az", "az-Cyrl-AZ", "az-Latn-AZ", "ba-RU", "eu", "eu-ES", "be", "be-BY", "bn-BD", "bn-IN", "bs-Cyrl-BA", "bs-Latn-BA", "br-FR", "bg", "bg-BG", "ca", "ca-ES", "zh-HK", "zh-MO", "zh-CN", "zh-Hans", "zh-SG", "zh-TW", "zh-Hant", "co-FR", "hr", "hr-HR", "hr-BA", "cs", "cs-CZ", "da", "da-DK", "prs-AF", "div", "div-MV", "nl", "nl-BE", "nl-NL", "en", "en-AU", "en-BZ", "en-CA", "en-029", "en-IN", "en-IE", "en-JM", "en-MY", "en-NZ", "en-PH", "en-SG", "en-ZA", "en-TT", "en-GB", "en-US", "en-ZW", "et", "et-EE", "fo", "fo-FO", "fil-PH", "fi", "fi-FI", "fr", "fr-BE", "fr-CA", "fr-FR", "fr-LU", "fr-MC", "fr-CH", "fy-NL", "gl", "gl-ES", "ka", "ka-GE", "de", "de-AT", "de-DE", "de-LI", "de-LU", "de-CH", "el", "el-GR", "kl-GL", "gu", "gu-IN", "ha-Latn-NG", "he", "he-IL", "hi", "hi-IN", "hu", "hu-HU", "is", "is-IS", "ig-NG", "id", "id-ID", "iu-Latn-CA", "iu-Cans-CA", "ga-IE", "xh-ZA", "zu-ZA", "it", "it-IT", "it-CH", "ja", "ja-JP", "kn", "kn-IN", "kk", "kk-KZ", "km-KH", "qut-GT", "rw-RW", "sw", "sw-KE", "kok", "kok-IN", "ko", "ko-KR", "ky", "ky-KG", "lo-LA", "lv", "lv-LV", "lt", "lt-LT", "wee-DE", "lb-LU", "mk", "mk-MK", "ms", "ms-BN", "ms-MY", "ml-IN", "mt-MT", "mi-NZ", "arn-CL", "mr", "mr-IN", "moh-CA", "mn", "mn-MN", "mn-Mong-CN", "ne-NP", "no", "nb-NO", "nn-NO", "oc-FR", "or-IN", "ps-AF", "fa", "fa-IR", "pl", "pl-PL", "pt", "pt-BR", "pt-PT", "pa", "pa-IN", "quz-BO", "quz-EC", "quz-PE", "ro", "ro-RO", "rm-CH", "ru", "ru-RU", "smn-FI", "smj-NO", "smj-SE", "se-FI", "se-NO", "se-SE", "sms-FI", "sma-NO", "sma-SE", "sa", "sa-IN", "sr", "sr-Cyrl-BA", "sr-Cyrl-SP", "sr-Latn-BA", "sr-Latn-SP", "nso-ZA", "tn-ZA", "si-LK", "sk", "sk-SK", "sl", "sl-SI", "es", "es-AR", "es-BO", "es-CL", "es-CO", "es-CR", "es-DO", "es-EC", "es-SV", "es-GT", "es-HN", "es-MX", "es-NI", "es-PA", "es-PY", "es-PE", "es-PR", "es-ES", "es-US", "es-UY", "es-VE", "sv", "sv-FI", "sv-SE", "syr", "syr-SY", "tg-Cyrl-TJ", "tzm-Latn-DZ", "ta", "ta-IN", "tt", "tt-RU", "te", "te-IN", "th", "th-TH", "bo-CN", "tr", "tr-TR", "tk-TM", "ug-CN", "uk", "uk-UA", "wen-DE", "ur", "ur-PK", "uz", "uz-Cyrl-UZ", "uz-Latn-UZ", "vi", "vi-VN", "cy-GB", "wo-SN", "sah-RU", "ii-CN", "yo-NG" };
// This is a list of cultures supported by your application
private static readonly IList<string> _cultures = new List<string> {
"en-GB", // first culture is the DEFAULT
"fr",
Expand All @@ -20,10 +20,10 @@
return GetDefaultCulture(); // return Default culture
if (_getImplementedCultureCache.ContainsKey(name))
return _getImplementedCultureCache[name]; // we have worked this out before and cached the result. Send it back.
if (_validCultures.Count(c => c.Equals(name, StringComparison.InvariantCultureIgnoreCase)) == 0)
return CacheCulture(name, GetDefaultCulture()); // return Default culture if it is invalid
if (_cultures.Count(c => c.Equals(name, StringComparison.InvariantCultureIgnoreCase)) > 0)
return CacheCulture(name, name); // accept it
if (_cultures.Any(c => c.Equals(name, StringComparison.InvariantCultureIgnoreCase)))
return CacheCulture(name, name); // the culture is in our supported list, accept it

// We did not get an exact culture match. Fallback to a language match, eg en-AU == en-US by matching the en prefix.
var n = GetNeutralCulture(name);
foreach (var c in _cultures)
if (c.StartsWith(n))
Expand All @@ -39,7 +39,6 @@

public static string GetDefaultCulture() {
return _cultures[0]; // return Default culture

}

public static string GetCurrentCulture() {
Expand All @@ -51,7 +50,7 @@
}

public static string GetNeutralCulture(string name) {
if (name.Length < 2)
if (name.Length <= 2)
return name;

return name.Substring(0, 2); // Read first two chars only. E.g. "en", "es"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,73 +1,17 @@


#languageselection
{
}
#languages
{
margin-top: 5px;
display: none;
padding-top: 10px;
padding-left: 10px;
padding-right: 10px;
height: 40px;
background-color: #efefef;
}
#languages h4
{
letter-spacing: normal;
font-size: 11px;
text-transform: capitalize;
font-weight: bold;
color: #606060;
margin-top: -7px;
}
#languages UL
{
margin-left: -40px;
list-style: none;
display: block;
padding-top: 5px;
}
#languages LI
{
float: left;
border-right: 1px dotted #cecece;
padding-right: 5px;
margin-right: 5px;
margin-top: -16px;
}
#languages LI:last-child
{
border-right: none;
}
.language
.language
{
padding-bottom: 2px;
background-position: left;
background-position: left 7px;
background-repeat: no-repeat;
margin-left: 5px;
padding-left: 20px;
text-align: left;
}
#currentlanguageSelection
{
margin-left: 15px;
}
.language A
{
line-height: 10px;
font-size: 12px;
}
#currentlanguage
{
padding: 5px;
}
#currentlanguageSelection_icon
{
float: left;
margin-top: 2px;
}
#i18n-options-container
{
width:200px;
Expand All @@ -76,25 +20,18 @@
#i18n-options
{
z-index: 1000;
text-align: right;
font-size: 75%;
padding: 10px;
text-align: right;
font-size: 75%;
padding: 10px;
}
#i18n-regions
{
height: 30px;
margin: 0 auto;
position: relative;
padding: 10px;
padding: 10px;
display: none;
}
#i18n-regions h4
{
height: 25px;
position: absolute;
top: 15px;
width: 160px;
}
#i18n-regions ul
{
list-style: none outside none;
Expand Down Expand Up @@ -132,22 +69,6 @@
text-transform: none;
white-space: nowrap;
}
.language
{
background-position: left 7px;
background-repeat: no-repeat;
margin-left: 5px;
padding-left: 20px;
text-align: left;
}
#currentlanguageSelection
{
margin-left: 15px;
}
.language A
{
line-height: 10px;
}
.language_EN
{
background-image: url(/content/code52.i18n/images/flags/gb.png);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,43 +10,7 @@

[OutputCache(Duration = 60, VaryByCustom = "culture")]
public class LanguageController : Controller
{
public RedirectResult Change(string customer, string token, string language)
{
if (string.IsNullOrWhiteSpace(language))
Response.Redirect("/", true);
if (!string.IsNullOrWhiteSpace(language))
{
switch (language.ToLower())
{
case "fr":
SetCulture("fr");
break;
case "pl":
SetCulture("pl");
break;
case "en-US":
SetCulture("en-US");
break;
default:
SetCulture("en-GB");
break;
}
}
return new RedirectResult(string.Format("/{0}/{1}/verify", customer, token));
}

protected void SetCulture(string name)
{
var cultureCookie = Request.Cookies["_culture"] ?? new HttpCookie("_culture");
cultureCookie.Value = name;
// NOTE: you should specify the domain for the cookie.
// cultureCookie.Domain = Request.Url.Host;
cultureCookie.Expires = DateTime.Now.AddYears(1);
cultureCookie.Path = "/";
Response.Cookies.Add(cultureCookie);
}

{
public JavaScriptResult Language()
{
return GetResourceScript(Resources.Language.ResourceManager);
Expand Down
2 changes: 1 addition & 1 deletion src/Code52.i18n.MVC/NuSpec/Content/Scripts/Code52.i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
},
Init: function (culture) {
Globalize.culture(culture);
instance = new i18n();
window.Code52.Language.instance = new i18n();
}
};
})(window);
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
</li>
<li class="lang">
<div class="language language_FR">
<a title="français" href="#" class="fr-FR" href="#">Français</a>
<a title="français" class="fr-FR" href="#">Français</a>
</div>
</li>
<li class="lang">
<div class="language language_FR">
<a title="français" href="#" class="pl-PL" href="#">Polish</a>
<a title="français" class="pl-PL" href="#">Polish</a>
</div>
</li>
</ol>
Expand Down