Created
December 12, 2012 11:33
-
-
Save jhauge/4267119 to your computer and use it in GitHub Desktop.
Making current Umbraco/ASP.NET locale/language available in javascript
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
<%@ Master Language="C#" MasterPageFile="~/umbraco/masterpages/default.master" AutoEventWireup="true" | |
CodeBehind="Master.master.cs" Inherits="Web.masterpages.Master" %> | |
<asp:Content runat="server" ContentPlaceHolderID="ContentPlaceHolderDefault"><!doctype html> | |
<html class="no-js" lang="en"> | |
<head> | |
</head> | |
<body> | |
</body> | |
<!-- | |
Script to load a variable telling about the current language | |
Insert before other scripts | |
--> | |
<script> | |
// This script will create a variable with the two-letter language code | |
// The value will allways be available as UI.currentUiLanguage | |
var UI = UI || {}; // Namespacing | |
UI.currentUiLanguage = '<%= CurrentUiLanguage %>'; // Will be written out from Masters codebehind | |
</script> | |
</html> | |
</asp:Content> |
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
using System; | |
using System.Web.UI; | |
using umbraco.NodeFactory; | |
namespace Web.masterpages | |
{ | |
public partial class Master : MasterPage | |
{ | |
private readonly Node _currentNode = Node.GetCurrent(); | |
public Master() | |
{ | |
Init += PageInit; | |
} | |
public string CurrentUiLanguage { get; set; } | |
private void PageInit(object sender, EventArgs e) | |
{ | |
// Set the value of CurrentUiLanguae, using default ASP.NET access method | |
// This property is what the Umbraco API, sets when determining the language from | |
// assigned domains | |
CurrentUiLanguage = System.Threading.Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment