Skip to main content

Localization in Umbraco, Item Page field localization




Umbraco is one of the most deployed Web Content Management Systems on the Microsoft stack. It's in the top five most popular server applications and among the ten most popular open source tools in general.

You can directly download and start using it from http://www.umbraco.com

If you have not used the application yet, its always worth trying it once. I am sure you will love it.

Well, for the first time users, Umbraco provide step by step instruction for initial set up, once you are done you can use some sample template or create a blank website.


To know more on umbraco, Please refer below links
http://our.umbraco.org/wiki/how-tos/a-complete-newbie's-guide-to-umbraco
http://umbraco.com/help-and-support/video-tutorials/getting-started?freeVideos=1
http://our.umbraco.org/wiki/how-tos/getting-started-with-umbraco-what-is-next-after-you-install
http://our.umbraco.org/wiki/install-and-setup


I have created a blank website, Now we will go step by step.

  • First create the home page template.

  • I created the document type with same name, and some properties, like, Page title, and page content, with two tabs, one for English and one for Malayalam
  • Now you are Good to go for localization, but with few changes in your properties, You can insert the page field of your property using umbraco page field utility.
                      <umbraco:Item field="pageTitle" runat="server" />

  • To apply the localization on fields, we have to customize our on item field as below, 
    • Write a class Item by implementing umbraco.presentation.templateControls.Item
  public class Item : umbraco.presentation.templateControls.Item
    {
        [Bindable(true)]
        [Category("Umbraco")]
        [DefaultValue("")]
        [Localizable(true)]
        public new string Field
        {
            get
            {
                return base.Field;
            }
            set
            {
                umbraco.cms.businesslogic.web.Document objCurrentDocument = new umbraco.cms.businesslogic.web.Document(umbraco.NodeFactory.Node.GetCurrent().Id);
                string locale = Utils.GetLanguageCode(HttpContext.Current.Request["locale"]);
                if (locale == "ENG")
                {
                    locale = "";
                }
                else
                {
                    locale = "_" + locale;
                }
                string sNewField = string.Format("{0}{1}", value, locale);
                if (objCurrentDocument.getProperty(sNewField) != null && objCurrentDocument.getProperty(sNewField).Value != null && !string.IsNullOrEmpty(objCurrentDocument.getProperty(sNewField).Value.ToString()))
                {
                    value = sNewField;
                }
                base.Field = value;
            }
        }
    }
  • Register this class on the template as below 
    <%@ Register Assembly="site" Namespace="site.UmbracoUsercontrols"
    TagPrefix="Cumbraco" %>
  •  Well, Now you can directly use the utility  as below.
<title><Cumbraco:Item field="pageTitle" runat="server" /></title>
  •  Now we can create  home page as below content 
 
The localized page can be seen as below
Umbraco one of the fastest growing platforms for building websites. I suggest to just use it, I am sure you will love it.

Comments

Popular posts from this blog

Why not to have a static const in c#

This is just a thought, that I was thinking why can't we have a constant with static in C#, and the answer is 'NO'; That we cannot have a static constant; e.g: I created a class as below: public class Constants1 { public const string Const1 = "Hello"; public const string Const2 = "World"; public static string Static1 = "Hello Static"; } When we compile the program into IL, the C# compiler does a magic in IL, that the constants converts into static literals, of course it has to, that's why we are able to access the constants as Constants1.Const1

Beyond Solo Assistants: Google's Vision for AI Teamwork (Agent-to-Agent Collaboration)

We talk a lot about AI assistants like Google Assistant or chatbots answering our questions. They're pretty smart on their own, right? But imagine if they could team up, combine their unique skills, and tackle really complex problems together, just like a human team does. That's the core idea behind a super exciting area Google and others in the AI world are exploring: Agent-to-Agent (A2A) communication and collaboration. Think of it less as a single product called "Agent2Agent" and more as the science and engineering of building AI teams. Ready to explore why this is such a big deal? Let's break it down! First Off: What Even is an AI Agent? Think of an AI agent as a specialized digital helper. It's a piece of software designed to: Perceive: Understand its environment (text, images, data, user requests). Reason: Figure out the best course of action based on its goals and knowledge. Act: Perform tasks (answer questions, writ...

Create Document Dynamically (Umbraco)

You can create document and publish the content during run time, Below code snippets helps you to do it. public class UmbracoUtils { /// <summary> /// Create and publish the document programatically /// </summary> /// <param name="nodeName"></param> /// <param name="properties"></param> /// <param name="documentType"></param> /// <param name="parentId"></param> /// <returns>node id</returns> public static int CreateDocument(string nodeName, Dictionary<string, string> properties, int documentType, int parentId, List<string> roles = null) { DocumentType dt = new DocumentType(documentType); umbraco.BusinessLogic.User u = new umbraco.BusinessLogic.User(0); // Create the document Document d = Document.MakeNew(nodeName, dt, u, parentId); // Add values...