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.
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.
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.
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...
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
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
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
I will come back to you at monday.
Cheer, Thomas
Ok, here is our approach.
First I created a class which is managing all the session stuff
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:
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
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
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...
@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
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);
}
}
}
Forgot to post this:
Reference from MasterPage:
<umbraco:Macro runat="server" Alias="Translator2" propertyname="PageTitle_" macroAlias="Translator2"></umbraco:Macro>
is working on a reply...