Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Hi,
is there a way to get a list of languages (from the Settings tab)?
I'm trying to create a languages selector marco, and aiming at a output like:
(Based on a site with English, Danish and German installed)
<ul> <li>en</li> <li>da</li> <li>de</li> </ul>
There is no build in feature for xslt, but you can either create your own xslt extension or use a .net usercontrol, both pupolating the languages from the umbraco.cms.businesslogic.language.Language.getAll function:
public static Language[] getAll{ get { List<Language> list = new List<Language>(); using (IRecordsReader reader = SqlHelper.ExecuteReader("select id from umbracoLanguage", new IParameter[0])) { while (reader.Read()) list.Add(new Language(reader.GetShort("id"))); } return list.ToArray(); }}
hth, Thomas
Hi Floffy,
There is currently no umbraco.library function that will give you a list of languages used.
You would need to write an XSLT extension to do this. Luckily, "here's something I prepared earlier" ...
public static XPathNodeIterator GetLanguages() { XmlDocument xd = new XmlDocument(); xd.LoadXml("<languages/>"); try { Language[] languages = Language.getAll; foreach (Language language in languages) { XmlNode node = xmlHelper.addTextNode(xd, "language", String.Empty); node.Attributes.Append(xmlHelper.addAttribute(xd, "id", language.id.ToString())); node.Attributes.Append(xmlHelper.addAttribute(xd, "culture", language.CultureAlias)); node.Attributes.Append(xmlHelper.addAttribute(xd, "name", language.FriendlyName)); xd.DocumentElement.AppendChild(node); } } catch (Exception ex) { xd.DocumentElement.AppendChild(xmlHelper.addTextNode(xd, "error", ex.Message)); } return xd.CreateNavigator().Select("/"); }
You can either compile this into your own DLL, or use a custom script block within the XSLT, more info about that here.
Good luck, Lee.
Hi Lee,
I used your code and compiled it into a dll, and registred it (as descriped here: http://en.wikibooks.org/wiki/Umbraco/Create_xslt_exstension_like_umbraco.Library_in_C)
It might be that is getting late but i can't figure out how to use it in my xslt? (all I'm getting is nothing)
I tryed something like this: (LanguageMetods:GetLanguages() calls your method)
<ul> <xsl:for-each select="LanguageMetods:GetLanguages()"> <li> <xsl:value-of select="@culture"/> </li> </xsl:for-each> </ul>
just use a copy of to see the complete results what you get:
<xsl:copy-of select="LanguageMetods:GetLanguages()"/>
But in the code from aboe you get a structure like this:
<languages> <language id="" name="" culture=""/> <language id="" name="" culture=""/></languages>
So your code should be like this:
<ul><xsl:for-each select="LanguageMetods:GetLanguages()/languages/language"> <li> <xsl:value-of select="@culture"/> </li></xsl:for-each></ul>
Thanks Thomas, much appreciated. :-D
Awesome guys, got it up and running
Hi guys.
Any improvements since 2010?
The explanations above look kind of advanced. Isn't there built-in language collection in Umbraco?
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Getting a list of languages
Hi,
is there a way to get a list of languages (from the Settings tab)?
I'm trying to create a languages selector marco, and aiming at a output like:
(Based on a site with English, Danish and German installed)
There is no build in feature for xslt, but you can either create your own xslt extension or use a .net usercontrol, both pupolating the languages from the umbraco.cms.businesslogic.language.Language.getAll function:
hth, Thomas
Hi Floffy,
There is currently no umbraco.library function that will give you a list of languages used.
You would need to write an XSLT extension to do this. Luckily, "here's something I prepared earlier" ...
You can either compile this into your own DLL, or use a custom script block within the XSLT, more info about that here.
Good luck, Lee.
Hi Lee,
I used your code and compiled it into a dll, and registred it (as descriped here: http://en.wikibooks.org/wiki/Umbraco/Create_xslt_exstension_like_umbraco.Library_in_C)
It might be that is getting late but i can't figure out how to use it in my xslt? (all I'm getting is nothing)
I tryed something like this: (LanguageMetods:GetLanguages() calls your method)
just use a copy of to see the complete results what you get:
But in the code from aboe you get a structure like this:
So your code should be like this:
hth, Thomas
Thanks Thomas, much appreciated. :-D
Awesome guys, got it up and running
Hi guys.
Any improvements since 2010?
The explanations above look kind of advanced. Isn't there built-in language collection in Umbraco?
is working on a reply...