Skip to content

Instantly share code, notes, and snippets.

@hellraiser75
hellraiser75 / MetaAcceptLanguage.cs
Created July 17, 2013 08:54
Setting globalization in jQuery
namespace System.Web.Mvc
{
public static class LocalizationHelpers
{
public static IHtmlString MetaAcceptLanguage<t>(this HtmlHelper<t> html)
{
var acceptLanguage = HttpUtility.HtmlAttributeEncode(Threading.Thread.CurrentThread.CurrentUICulture.ToString());
return new HtmlString(String.Format("<meta name="\" accept-language\""="" content="\" {0}\""="">",acceptLanguage));
}
}
@hellraiser75
hellraiser75 / ChangeClientLanguage.js
Created July 17, 2013 08:30
Change default language in cookie
var mySiteNamespace = {}
mySiteNamespace.switchLanguage = function (lang) {
$.cookie('language', lang);
window.location.reload();
}
$(document).ready(function () {
// attach mySiteNamespace.switchLanguage to click events based on css classes
$('.lang-english').click(function () { mySiteNamespace.switchLanguage('en'); });
@hellraiser75
hellraiser75 / function parseUrl
Created June 19, 2013 10:02
Parses an url and returns an object with properties belonging to each part of the parsed Url
function parseUrl (url) {
var loc = {
href: url,
parts : url.replace('//','/').split('/')
};
loc.protocol = parts[0];
loc.host = parts[1];
parts[1] = parts[1].split(':');
@hellraiser75
hellraiser75 / string.prototype.format
Created June 19, 2013 09:56
string.prototype.format
if (!String.prototype.format) {
String.prototype.format = function () {
var args = arguments;
return this.replace(/{(\d+)}/g, function (match, number) {
return typeof args[number] != 'undefined'
? args[number]
: match
;
});
};