I have a multilingual site which is somewhat of a hack, as it's a migration of an existing site to Umbraco. E.g. I don't use hostnames to define language context.
I've created the correct Languages in the Settings section (english and russian), and then created a Dictionary Item called Sector (there will be lots more later). This has the correct English and Russian versions in it.
I have a Macro which outputs an XML feed containing data in both English and Russian and I want to use the Dictionary to translate the word Sector for the English and Russian parts of the feed.
The problem is that umbraco.library:GetDictionaryItem("Sector") returns the translated value for the current language context. What I want to do is get to the dictionary and retrieve all current language values for an item -or- is there a method where I can pass the language context as a parameter, something like GetDictionaryItem("Sector", "EN") and GetDictionaryItem("Sector", "RS") rather than rely on the current context.
Any ideas if this is possible or pointers to how I might go about writing this myself.
Please no-one laugh at me for being thick. I'm just a project manager pretending to be a developer!
But I'm trying to add a bit of embedded c# at the bottom of one of my XSL files to make a call to Dictionary.DictionaryItem etc.
I've done this before by plaigerising some of Doug's XSLSearch to put C# function's into my XSL so I thought I'd be able to do it for the Dictionary call, but it keeps erroring. Here's my code
<msxsl:script language="C#" implements-prefix="orcare"> <![CDATA[ public string GetDictionaryItemByContext(string key, int languageId) { return new umbraco.cms.businesslogic.Dictionary.DictionaryItem(key).Value(languageId); } ]]> </msxsl:script>
But I get the following error:
Error in XSLT at line 233, char 20 231: public string GetDictionaryItemByContext(string key, int languageId) 232: { 233: >>> return new umbraco.cms.businesslogic.Dictionary.DictionaryItem(key).Value(languageId); <<< 234: }
In the end I went with creating my own library based on this which Tim pointed to in an old post. It's meant that I can now call a couple of functions one called GetDictionaryItemByLanguageId and one called GetDictionaryItemByCultureCode.
Accessing Dictionary Items
I have a multilingual site which is somewhat of a hack, as it's a migration of an existing site to Umbraco. E.g. I don't use hostnames to define language context.
I've created the correct Languages in the Settings section (english and russian), and then created a Dictionary Item called Sector (there will be lots more later). This has the correct English and Russian versions in it.
I have a Macro which outputs an XML feed containing data in both English and Russian and I want to use the Dictionary to translate the word Sector for the English and Russian parts of the feed.
The problem is that umbraco.library:GetDictionaryItem("Sector") returns the translated value for the current language context. What I want to do is get to the dictionary and retrieve all current language values for an item -or- is there a method where I can pass the language context as a parameter, something like GetDictionaryItem("Sector", "EN") and GetDictionaryItem("Sector", "RS") rather than rely on the current context.
Any ideas if this is possible or pointers to how I might go about writing this myself.
You could take a look at this: http://forum.umbraco.org/yaf_postst2208_Actionhandlers-and-dictionary-items--How-to-get-the-node-language-.aspx
I seems like there is a Dictionary.DictionaryItem(Key).Value(domains[0].Language.id);
Please no-one laugh at me for being thick. I'm just a project manager pretending to be a developer!
But I'm trying to add a bit of embedded c# at the bottom of one of my XSL files to make a call to Dictionary.DictionaryItem etc.
I've done this before by plaigerising some of Doug's XSLSearch to put C# function's into my XSL so I thought I'd be able to do it for the Dictionary call, but it keeps erroring. Here's my code
But I get the following error:
Error in XSLT at line 233, char 20
231: public string GetDictionaryItemByContext(string key, int languageId)
232: {
233: >>> return new umbraco.cms.businesslogic.Dictionary.DictionaryItem(key).Value(languageId); <<<
234: }
Anyone know what's going wrong?
try removing the "new" as it will try to create an instance of the string that is return by that function.
If that won't work please share the entire xslt so I can test it myself
Ron
In the end I went with creating my own library based on this which Tim pointed to in an old post. It's meant that I can now call a couple of functions one called GetDictionaryItemByLanguageId and one called GetDictionaryItemByCultureCode.
You can use something like this pair of overloaded functions:
public static string GetDictionaryItemByCulture(string key, string cultureName)
{
return GetDictionaryItemByCulture(key, CultureInfo.GetCultureInfo(cultureName));
}
public static string GetDictionaryItemByCulture(string key, CultureInfo culture)
{
Language byCultureCode = Language.GetByCultureCode(culture.Name);
return new Dictionary.DictionaryItem(key).Value(byCultureCode.id);
}
where cultureName is one of the list:
http://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo%28v=vs.71%29.aspx
is working on a reply...