Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • JonRS 4 posts 20 karma points
    Jul 18, 2009 @ 13:13
    JonRS
    0

    Multilingual 1:1 site in Umbraco 4

    Hi,

    I'm am trying to build a multilingual 1:1 site as described in http://umbraco.org/documentation/books/multilingual-11-sites on an Umbraco 4.0.1. However I run into some problems in the process, so I wonder if this method only will work in Umbraco 3 or if I am making some other mistake? I am not able to  add properties with the same name but different aliases to the document type. Trying to add 3 properties with name: MainContent and localizeded aliases: MainContent_en, MainContent_da and MainContent_sv) gives me the error "Property type already exists" when adding the second and third property. I am however able to create them with different names and then rename them afterwards to the same name. The properties are all of type Richtext Editor. In the template I use <umbraco:Item field="MainContent" runat="server"></umbraco:Item> to get the content.

    Nevertheless, when browsing the website, adding a querystring of the form "?lang=en" the localized content does not appear on the pages. If I remove the localized alias from one of the fields and just use the name, the content appears, but of course it is the same regardless of the language chosen.

    Any suggestions are welcome.

    thanks

    Jon

     

  • Thomas Höhler 1237 posts 1709 karma points MVP
    Jul 18, 2009 @ 14:59
    Thomas Höhler
    0

    In one of our company sites we are using a bit different approach: using a session variable saving the language and using xslts and xslt-extensions to get the values. If you want I can give you the code at monday.

    btw: we are using v4 at this site without problems.

    Thomas

  • JonRS 4 posts 20 karma points
    Jul 18, 2009 @ 16:12
    JonRS
    0

    Thanks for the answer. I've realized that what I need is to get the <umbraco:Item field="MainContent" runat="server"></umbraco:Item> to recognize the localized aliases. The problem is that I have the content in RichText fields that often will contain a mixture of text and UserControl-macros. I've tried to use an xslt-macro instead of the umbraco:Item-tag to extract the content, but when I do that the UserControl-macros are not executed, just rendered as macro-tags to the browser. If you think you have a solution to this, I would be very interested.

    Jon

  • Thomas Höhler 1237 posts 1709 karma points MVP
    Jul 18, 2009 @ 18:05
    Thomas Höhler
    0

    I will come back to you at monday.

    Cheer, Thomas

  • Thomas Höhler 1237 posts 1709 karma points MVP
    Jul 20, 2009 @ 16:43
    Thomas Höhler
    0

    Ok, here is our approach.

    First I created a class which is managing all the session stuff

    public class mylib
    {

    public static string GetSessionLanguage()
    {
    string lang = "de";
    try
    {
    if (string.IsNullOrEmpty(Convert.ToString(HttpContext.Current.Session["lang"])))
    foreach (string s in HttpContext.Current.Request.UserLanguages)
    {
    if (s.ToLower().StartsWith("de"))
    {
    lang = "de";
    HttpContext.Current.Session["lang"] = lang;
    return lang;
    }
    else
    {
    if (s.ToLower().StartsWith("en"))
    {
    lang = "en";
    HttpContext.Current.Session["lang"] = lang;
    return lang;
    }
    }
    }
    else
    lang = Convert.ToString(HttpContext.Current.Session["lang"]);
    }
    catch (Exception)
    {
    umbraco.BusinessLogic.Log.Add(umbraco.BusinessLogic.LogTypes.Error, -1, ex.Message + "\n\n" + ex.StackTrace);
    }
    return lang;
    }

    public static string GetDictionaryItemById(int id)
    {
    umbraco.cms.businesslogic.language.Language umbracoLanguage = umbraco.cms.businesslogic.language.Language.GetByCultureCode(Library.GetSessionLanguage());
    umbraco.cms.businesslogic.Dictionary.DictionaryItem dic = new umbraco.cms.businesslogic.Dictionary.DictionaryItem(id);
    return dic.Value(umbracoLanguage.id);
    }

    public static string GetDictionaryItemByKey(string key)
    {
    umbraco.cms.businesslogic.language.Language umbracoLanguage = umbraco.cms.businesslogic.language.Language.GetByCultureCode(Library.GetSessionLanguage());
    umbraco.cms.businesslogic.Dictionary.DictionaryItem dic = new umbraco.cms.businesslogic.Dictionary.DictionaryItem(key);
    return dic.Value(umbracoLanguage.id);
    }
    }

    We are using this mainly for different bodyText properties, but also for dictionary items.

    Then I added the mylib to the xslt extensions config and created a new xslt:

    <xsl:stylesheet 
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxml="urn:schemas-microsoft-com:xslt"
    xmlns:umbraco.library="urn:umbraco.library"
    xmlns:mylib="urn:mylib"
    exclude-result-prefixes="msxml umbraco.library mylib">

    <xsl:output method="xml" omit-xml-declaration="yes"/>
    <xsl:param name="currentPage"/>
    <xsl:param name="propertyname" select="/macro/propertyname"></xsl:param>
    <xsl:param name="lang" select="mylib:GetSessionLanguage()"></xsl:param>

    <xsl:template match="/">
    <xsl:choose>
    <xsl:when test="$propertyname = ''">
    <xsl:value-of select="$currentPage/data [@alias=concat('bodyText_', $lang)]" disable-output-escaping="yes" />
    </xsl:when>
    <xsl:otherwise>
    <xsl:value-of select="$currentPage/data [@alias=concat($propertyname, $lang)]" disable-output-escaping="yes" />
    </xsl:otherwise>
    </xsl:choose>
    </xsl:template>
    </xsl:stylesheet>

    In the backend I have created for every node a tab "DE" and "EN" and on each tab an editor as property with the alias bodyText_de and bodyText_en.

    Now I can get the values in the template via

    <umbraco:Macro runat="server" Alias="GetContent" macroAlias="GetContent"></umbraco:Macro>

    which calls the xslt above. You can see that I can optional set the property name so I am not only nailed to bodyText.

    If there are questions leave a comment or (if I am not answering) mail me at th |at| thoehler |dot| com

    hth,
    Thomas

  • Richard 38 posts 78 karma points
    Feb 19, 2010 @ 21:01
    Richard
    0

    This code crashes on Umbraco 4.0.3. And wouldn't compile anyway since variables are accessed that don't exist. I fixed it, but hth should publish a working version...

     

  • Boby 20 posts 42 karma points
    May 02, 2010 @ 12:33
    Boby
    0

    @Richard  I'm trying to get a multilinugal 1:1 site to work; wondering how you did the same? And how do i call a macro with a parameter?

    Boby

  • Anarbek 2 posts 22 karma points
    May 18, 2010 @ 13:18
    Anarbek
    0

    Try this:

     

    using System;

    using System.Collections.Generic;

    using System.Text;

    using System.Web;

    using umbraco.cms;

    using umbraco.cms.businesslogic;

    using umbraco.cms.businesslogic.language;

     

    namespace ANAR.umbraco

    {

        public class Translations2

        {

            public static string GetSessionLanguage()

            {

                string lang = "tr";

                if (HttpContext.Current.Request.QueryString["lang"]!=null)

                {

                    if (!string.IsNullOrEmpty(Convert.ToString(HttpContext.Current.Request.QueryString["lang"])))

                    {

                        HttpContext.Current.Session["lang"] = HttpContext.Current.Request.QueryString["lang"];

                    }

                }

                try

                {

                    if (string.IsNullOrEmpty(Convert.ToString(HttpContext.Current.Session["lang"])))

                        foreach (string s in HttpContext.Current.Request.UserLanguages)

                        {

                            if (s.ToLower().StartsWith("tr"))

                            {

                                lang = "tr";

                                HttpContext.Current.Session["lang"] = lang;

                                return lang;

                            }

                            else

                            {

                                if (s.ToLower().StartsWith("en"))

                                {

                                    lang = "en";

                                    HttpContext.Current.Session["lang"] = lang;

                                    return lang;

                                }

                            }

                        }

                    else

                        lang = Convert.ToString(HttpContext.Current.Session["lang"]);

                }

                catch (Exception)

                {

                    //umbraco.BusinessLogic.Log.Add(umbraco.BusinessLogic.LogTypes.Error, -1, ex.Message + "\n\n" + ex.StackTrace);

                }

                return lang;

            }

     

            public static string GetDictionaryItemById(int id)

            {

                Language umbracoLanguage = Language.GetByCultureCode(GetSessionLanguage());

                Dictionary.DictionaryItem dic = new Dictionary.DictionaryItem(id);

                return dic.Value(umbracoLanguage.id);

            }

     

            public static string GetDictionaryItemByKey(string key)

            {

                Language umbracoLanguage = Language.GetByCultureCode(GetSessionLanguage());

                Dictionary.DictionaryItem dic = new Dictionary.DictionaryItem(key);

                return dic.Value(umbracoLanguage.id);

            }

        }

    }

    and xslt code:
    <xsl:stylesheet 
            version="1.0" 
            xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
            xmlns:msxml="urn:schemas-microsoft-com:xslt" 
            xmlns:umbraco.library="urn:umbraco.library" 
            xmlns:anar_trans="urn:anar_trans"
            exclude-result-prefixes="msxml umbraco.library anar_trans">
            
            <xsl:output method="xml" omit-xml-declaration="yes"/>
            <xsl:param name="currentPage"/>
    <xsl:variable name="propertyname" select="/macro/propertyname" />
            <xsl:param name="lang" select="anar_trans:GetSessionLanguage()"></xsl:param>
            
            <xsl:template match="/">
                    <xsl:choose>
                            <xsl:when test="$propertyname = ''">
                                    <xsl:value-of select="$currentPage/data [@alias=concat('icerik_', $lang)]" disable-output-escaping="yes" />
                            </xsl:when>
                            <xsl:otherwise>
                                    <xsl:value-of select="$currentPage/data [@alias=concat($propertyname, $lang)]" disable-output-escaping="yes" />
                            </xsl:otherwise>
                    </xsl:choose>
            </xsl:template>
    </xsl:stylesheet>
    xslt declaration in xsltExtensions.config:
    <?xml version="1.0" encoding="utf-8" ?>
    <XsltExtensions>
      <!--
      <ext assembly="/bin/name-of-dll-without-dll-extension" type="Fully.Qualified.Name.Of.Type.Including.Namespace" alias="Prefix-to-use-in-xslt" />
      -->
      <ext assembly="/bin/AnarUmbracoTranlator" type="ANAR.umbraco.Translations" alias="kv_trans" />
      <ext assembly="/bin/AnarUmbracoTranlator" type="ANAR.umbraco.Translations2" alias="anar_trans" />
    </XsltExtensions>

  • Anarbek 2 posts 22 karma points
    May 18, 2010 @ 13:24
    Anarbek
    0

    Forgot to post this:

    Reference from MasterPage:

    <umbraco:Macro runat="server" Alias="Translator2" propertyname="PageTitle_"  macroAlias="Translator2"></umbraco:Macro>

Please Sign in or register to post replies

Write your reply to:

Draft