Language Selector Error
Hi JV,
I am not able to replicate this issue locally. Could you attach several screenshots
1. Language settings screeen
2. Pages configuration Sitefinity >> Administration >> Settings >> Advanced >> Pages and what has been set for FrontendRootNode
3. On which language version you create a page.
All the best,
Ivan Dimitrov
the Telerik team
Hello JV,
I am not able to replicate the issue with these settings. There is a new build that we uploaded today. Could you download it and try to replicate the issue with it. Let me know if the problem persists and I will try to come up with other suggestions to narrow it down.
Sincerely yours,
Ivan Dimitrov
the Telerik team
Hi,
I already made the download of the new release and run the upgrade in project manager.
When i try to add the language selector to one page it works.
When i try to add the language selector to one page template i get the error.
Hi JV,
The control cannot work on backend pages or templates. Its current implementation allows to use it only with FrontendSiteMap. We will add some logic to catch the exception. The problem should not persists for pages created under FrontendSiteMap
Greetings,
Ivan Dimitrov
the Telerik team
OK.
The error disappear after applying the template to one frontendpage.
I need to change the "tag" displayed in the language selector for example i don't whant "English" but i whant that "EN" appear to the user (Português --> PT). How can i achieve this, how can i costumize the language selector ?
thanks,
JV
Hello JV,
We use CultureInfo and NativeName property of the object. You can change the text of the HtmlGenericControl that us used by creating a custom class that inherits from LanguageSelectorControl. You should override InitializeControls method and rebind the Repeater control - LanguagesRepeater
Kind regards,
Ivan Dimitrov
the Telerik team
Sorry i think i don't understand 100%.
Could you send a litle sample in attach?
thanks,
JV
Hello JV,
Here is a sample code
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
using
Telerik.Sitefinity.Localization.Web.UI;
using
System.Globalization;
using
Telerik.Sitefinity.Configuration;
using
Telerik.Sitefinity.Modules.Pages.Configuration;
using
Telerik.Sitefinity.Modules.Pages;
using
Telerik.Sitefinity.Abstractions;
using
Telerik.Sitefinity.Model;
using
System.Threading;
namespace
Telerik.Sitefinity.Samples
public
class
LanguageSelectorControlCustom : LanguageSelectorControl
protected
override
string
LayoutTemplateName
get
return
LanguageSelectorControlCustom.customTemplate;
protected
override
void
InitializeControls(Web.UI.GenericContainer container)
//base.InitializeControls(container);
var settings = ObjectFactory.Resolve<IAppSettings>();
List<CultureInfo> languages =
new
List<CultureInfo>();
if
(
this
.MissingTranslationAction == NoTranslationAction.HideLink)
languages.AddRange(
this
.usedLanguages);
else
languages.AddRange(settings.DefinedFrontendLanguages);
PageManager pm = PageManager.GetManager();
var homePageId = Config.Get<PagesConfig>().HomePageId;
if
(homePageId != Guid.Empty)
this
.homePageNode = pm.GetPageNode(homePageId);
CultureInfo currentLanguage = Thread.CurrentThread.CurrentUICulture;
IEnumerable<CultureInfo> shownLanguages;
if
(
this
.ShowCurrentLanguage ==
false
&&
this
.SelectorType != LanguageSelectorType.DropDown)
shownLanguages = languages.Where(ci => ci.Equals(currentLanguage) ==
false
);
else
shownLanguages = languages;
this
.LanguagesRepeater.DataSource = shownLanguages;
this
.LanguagesRepeater.ItemDataBound +=
new
System.Web.UI.WebControls.RepeaterItemEventHandler(LanguagesRepeater_ItemDataBound);
this
.LanguagesRepeater.DataBind();
void
LanguagesRepeater_ItemDataBound(
object
sender, System.Web.UI.WebControls.RepeaterItemEventArgs e)
CultureInfo ci = (CultureInfo)e.Item.DataItem;
// here format the link you want to see.
// you can get the template through reflector.
private
const
string
customTemplate =
"Telerik.Sitefinity.Samples.Templates.PublicControls.LanguageSelectorControl.ascx"
;
private
List<CultureInfo> usedLanguages;
private
Pages.Model.PageNode homePageNode;
Hello JV,
1. You have not completed the logic inside ItemDataBound event of the repater
2. You should use the template below.
<%@ Control Language="C#" %>
<%@ Register TagPrefix="sfFields" Assembly="Telerik.Sitefinity" Namespace="Telerik.Sitefinity.Web.UI.Fields" %>
<%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Web.UI" Assembly="Telerik.Sitefinity" %>
<
div
runat
=
"server"
id
=
"controlWrapper"
>
<
asp:Panel
ID
=
"errorsPanel"
runat
=
"server"
CssClass
=
"sfErrorSummary"
/>
<
sf:ConditionalTemplateContainer
ID
=
"sfLangSelectorConditionalTemplateContainer"
runat
=
"server"
>
<
Templates
>
<
sf:ConditionalTemplate
Left
=
"SelectorType"
Operator
=
"Equal"
Right
=
"Horizontal"
runat
=
"server"
>
<
asp:Repeater
ID
=
"languagesRepeater"
runat
=
"server"
>
<
HeaderTemplate
>
<
ul
id
=
"langsWrapper"
class
=
"sflanguagesHorizontalList"
>
</
HeaderTemplate
>
<
ItemTemplate
>
<
li
runat
=
"server"
id
=
"langHolder"
class
=
"sflanguageItem"
>
<
a
runat
=
"server"
id
=
"langLink"
href
=
""
><
span
runat
=
"server"
id
=
"langName"
></
span
></
a
>
</
li
>
</
ItemTemplate
>
<
FooterTemplate
>
</
ul
>
</
FooterTemplate
>
</
asp:Repeater
>
</
sf:ConditionalTemplate
>
<
sf:ConditionalTemplate
Left
=
"SelectorType"
Operator
=
"Equal"
Right
=
"Vertical"
runat
=
"server"
>
<
asp:Repeater
ID
=
"languagesRepeater"
runat
=
"server"
>
<
HeaderTemplate
>
<
ul
id
=
"langsWrapper"
class
=
"sflanguagesVerticalList"
>
</
HeaderTemplate
>
<
ItemTemplate
>
<
li
runat
=
"server"
id
=
"langHolder"
class
=
"sflanguageItem"
>
<
a
runat
=
"server"
id
=
"langLink"
href
=
""
><
span
runat
=
"server"
id
=
"langName"
></
span
></
a
>
</
li
>
</
ItemTemplate
>
<
FooterTemplate
>
</
ul
>
</
FooterTemplate
>
</
asp:Repeater
>
</
sf:ConditionalTemplate
>
<
sf:ConditionalTemplate
Left
=
"SelectorType"
Operator
=
"Equal"
Right
=
"DropDown"
runat
=
"server"
>
<
div
class
=
"sflanguagesDropDown"
>
<
asp:DropDownList
runat
=
"server"
ID
=
"langsSelect"
></
asp:DropDownList
>
</
div
>
</
sf:ConditionalTemplate
>
</
Templates
>
</
sf:ConditionalTemplateContainer
>
</
div
>
OK Thanks,
Now in the LanguagesRepeater_ItemDataBound
CultureInfo ci = (CultureInfo)e.Item.DataItem
i get that ci is null.
But in debug mode i see that "shownLanguages" have two itens (English and Portuguese).
What's wrong ?
Another thing is that in debug i get that CultureInfo currentLanguage = Thread.CurrentThread.CurrentUICulture;
is the english but mi page is backend is the PT translation page.
thanks again.
Hi JV,
You could check the e.Item.DataItem before you made the cast. Also this control cannot work on backend pages as I described in my previous posts. Since it inherits from the base class LanguageSelectorControl there could be some issues.
CurrentUICulture shows the culture that is used by resource manager for the user interface.
Best wishes,
Ivan Dimitrov
the Telerik team
Hi,
I have the same problem as you (The first problem).
In fact, I do not understand how you solved it.
Please, will you explain with mors details.
Thanks.
Hi,
The exception only happens in the backend. If you ignore and publish the page and then navigate in the frontend the exception disappear.
Hi,
The exception exists if I put this url http://localhost:58632/nom_projet/ but if I put this url http://localhost:58632/nom_projet/fr/ or http://localhost:58632/nom_projet/en/ the exception does not exist.
Hi Millaneli,
We were able to reproduce this issue locally. This issue is valid only for Sitefinitys’ projects that are stored on the local file system (not through IIS) and launched using the built-in web server.
The issue is logged as a bug with ID 101947
I have this error when I tried to set the path of my custom control and I lunch the page.
Why?
Stefano
Hello Stefano,
Have you checked whether you have two controls with the same ID on the page or two instances inside your control that use the same ID?
Regards,
Ivan Dimitrov
the Telerik team
Can you show me step by step how can I implement this control to create the languageSelector IT- DE -EN ?
Than you!
Stefano
Hi Stefano,
Most of the custom control is implemented here. What is not clear so I can provide further help?
Best wishes,
Ivan Dimitrov
the Telerik team
I don't understand where i can insert the code of the template and where the code of the custom control that it isn't an User Control so I can't do from my folder "Custom" this operation: "Add -> NewItem -> Web User Control".
I explained?
Hello Stefano,
1. Do you have duplicate Ids in the template? The error says that there are two controls with the same ID
2. As I see you use a user control, not a custom control which will not work. You need to create a class that inherits from LanguageSelectorControl
.
Then override LayoutTemplateName and LayoutTemplatePath and register the template through VirtualPathProvider
Greetings,
Ivan Dimitrov
the Telerik team
Yes, I have the error:
Hello Stefano,
When you are registering the control you are setting a namespace which your control does not have. Please set namespace of your class.
All the best,
Ivan Dimitrov
the Telerik team
I have resolve the problem with the namespace but I have a new error.
Stefano
Hi Stefano,
Try using
var settings = AppSettings.CurrentSettings;
Best wishes,
Ivan Dimitrov
the Telerik team
Now I have this error. And I have this WARNING:
Warning 1 Field 'LanguagesSelectorControl.WebControl.LanguageSelectorControlCustom.usedLanguages' is never assigned to, and will always have its default value null C:\Program Files (x86)\Telerik\Sitefinity 4.1\Projects\LanguageSelectorControl\LanguageSelectorControl.cs 77 35 LanguagesSelectorControl.WebControl
Warning 2 'LanguagesSelectorControl.WebControl.LanguageSelectorControlCustom.usedLanguages' hides inherited member 'Telerik.Sitefinity.Localization.Web.UI.LanguageSelectorControl.usedLanguages'. Use the new keyword if hiding was intended. C:\Program Files (x86)\Telerik\Sitefinity 4.1\Projects\LanguageSelectorControl\LanguageSelectorControl.cs 77 35 LanguagesSelectorControl.WebControl
Warning 3 'LanguagesSelectorControl.WebControl.LanguageSelectorControlCustom.homePageNode' hides inherited member 'Telerik.Sitefinity.Localization.Web.UI.LanguageSelectorControl.homePageNode'. Use the new keyword if hiding was intended. C:\Program Files (x86)\Telerik\Sitefinity 4.1\Projects\LanguageSelectorControl\LanguageSelectorControl.cs 78 26 LanguagesSelectorControl.WebControl
I had "The ID 'languagesRepeater' is already used by another control." errror.
I want to show flags with image button instead of hyper link.
My template file :
01.
<%@ Control Language="C#" %>
02.
<%@ Register TagPrefix="sfFields" Assembly="Telerik.Sitefinity" Namespace="Telerik.Sitefinity.Web.UI.Fields" %>
03.
<%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Web.UI" Assembly="Telerik.Sitefinity" %>
04.
05.
<
div
runat
=
"server"
id
=
"controlWrapper"
>
06.
07.
<
asp:Panel
ID
=
"errorsPanel"
runat
=
"server"
CssClass
=
"sfErrorSummary"
/>
08.
09.
<
sf:ConditionalTemplateContainer
ID
=
"sfLangSelectorConditionalTemplateContainer"
runat
=
"server"
>
10.
<
Templates
>
11.
<
sf:ConditionalTemplate
Left
=
"SelectorType"
Operator
=
"Equal"
Right
=
"Horizontal"
runat
=
"server"
>
12.
<
asp:Repeater
ID
=
"LanguagesRepeater"
runat
=
"server"
>
13.
<
ItemTemplate
>
14.
<
li
>
15.
<
asp:ImageButton
ID
=
"imgLnkButton"
runat
=
"server"
/>
16.
</
li
>
17.
</
ItemTemplate
>
18.
</
asp:Repeater
>
19.
</
sf:ConditionalTemplate
>
20.
<
sf:ConditionalTemplate
Left
=
"SelectorType"
Operator
=
"Equal"
Right
=
"Vertical"
runat
=
"server"
>
21.
<
asp:Repeater
ID
=
"LanguagesRepeater"
runat
=
"server"
>
22.
<
HeaderTemplate
>
23.
<
ul
>
24.
</
HeaderTemplate
>
25.
<
ItemTemplate
>
26.
27.
</
ItemTemplate
>
28.
<
FooterTemplate
>
29.
</
ul
>
30.
</
FooterTemplate
>
31.
</
asp:Repeater
>
32.
</
sf:ConditionalTemplate
>
33.
<
sf:ConditionalTemplate
Left
=
"SelectorType"
Operator
=
"Equal"
Right
=
"DropDown"
runat
=
"server"
>
34.
35.
</
sf:ConditionalTemplate
>
36.
</
Templates
>
37.
</
sf:ConditionalTemplateContainer
>
38.
</
div
>
My custom control codes :
001.
using
System;
002.
using
System.Collections.Generic;
003.
using
System.Linq;
004.
using
System.Web;
005.
using
Telerik.Sitefinity.Localization.Web.UI;
006.
using
System.Globalization;
007.
using
Telerik.Sitefinity.Configuration;
008.
using
Telerik.Sitefinity.Modules.Pages.Configuration;
009.
using
Telerik.Sitefinity.Modules.Pages;
010.
using
Telerik.Sitefinity.Abstractions;
011.
using
Telerik.Sitefinity.Model;
012.
using
System.Threading;
013.
using
System.Web.UI.WebControls;
014.
using
Telerik.Sitefinity.Localization.UrlLocalizationStrategies;
015.
using
Telerik.Sitefinity.Pages.Model;
016.
using
Telerik.Sitefinity.Web;
017.
using
Telerik.Sitefinity;
018.
using
Telerik.Sitefinity.Web.UI;
019.
020.
namespace
SitefinityWebApp
021.
022.
public
class
MyLanguageSelector : LanguageSelectorControl
023.
024.
private
const
string
customLayoutTemplateName =
"SitefinityWebApp.customcontrol.MyLanguageSelector.ascx"
;
025.
private
const
string
customlayoutTemplatePath =
"~/customcontrol/MyLanguageSelector.ascx"
;
026.
027.
new
private
Telerik.Sitefinity.Pages.Model.PageNode homePageNode;
028.
029.
030.
031.
protected
override
string
LayoutTemplateName
032.
033.
get
034.
035.
return
MyLanguageSelector.customLayoutTemplateName;
036.
037.
038.
039.
public
override
string
LayoutTemplatePath
040.
041.
get
042.
043.
return
MyLanguageSelector.customlayoutTemplatePath;
044.
045.
046.
047.
protected
override
void
InitializeControls( GenericContainer container)
048.
049.
//base.InitializeControls(container);
050.
var settings = AppSettings.CurrentSettings;
051.
List<CultureInfo> languages =
new
List<CultureInfo>();
052.
//if (this.MissingTranslationAction == NoTranslationAction.HideLink)
053.
//
054.
// languages.AddRange(this.usedLanguages);
055.
//
056.
//else
057.
//
058.
059.
languages.AddRange(settings.DefinedFrontendLanguages);
060.
PageManager pm = PageManager.GetManager();
061.
var homePageId = Config.Get<PagesConfig>().HomePageId;
062.
if
(homePageId != Guid.Empty)
063.
064.
this
.homePageNode = pm.GetPageNode(homePageId);
065.
066.
//
067.
CultureInfo currentLanguage = Thread.CurrentThread.CurrentUICulture;
068.
IEnumerable<CultureInfo> shownLanguages;
069.
if
(
this
.ShowCurrentLanguage ==
false
&&
this
.SelectorType != LanguageSelectorType.DropDown)
070.
071.
shownLanguages = languages.Where(ci => ci.Equals(currentLanguage) ==
false
);
072.
073.
else
074.
075.
shownLanguages = languages;
076.
077.
078.
this
.LanguagesRepeater.DataSource = shownLanguages;
079.
this
.LanguagesRepeater.ItemDataBound +=
new
System.Web.UI.WebControls.RepeaterItemEventHandler(languagesRepeater_ItemDataBound);
080.
this
.LanguagesRepeater.DataBind();
081.
082.
083.
protected
void
languagesRepeater_ItemDataBound(
object
sender, RepeaterItemEventArgs e)
084.
085.
try
086.
087.
if
(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
088.
089.
CultureInfo item = e.Item.DataItem
as
CultureInfo;
090.
ImageButton imgLanguage = e.Item.FindControl(
"imgLnkButton"
)
as
ImageButton;
091.
092.
093.
imgLanguage.ImageUrl =
"../images/"
+ item.TwoLetterISOLanguageName +
".png"
;
094.
imgLanguage.ToolTip = item.DisplayName;
095.
096.
UrlLocalizationService s = ObjectFactory.Resolve<UrlLocalizationService>();
097.
imgLanguage.PostBackUrl = s.ResolvePageUrl(
this
.node, item);
098.
099.
100.
catch
(Exception ex)
101.
102.
throw
ex;
103.
104.
105.
106.
private
void
GetCurrentPage()
107.
108.
try
109.
110.
var actualSitemapNode = SiteMapBase.GetActualCurrentNode();
111.
112.
PageManager pm = PageManager.GetManager();
113.
114.
var homePageId = Config.Get<PagesConfig>().HomePageId;
115.
//IEnumerable<CultureInfo> availableLanguages = null;
116.
117.
Guid nodeId;
118.
if
(actualSitemapNode !=
null
)
119.
120.
nodeId = actualSitemapNode.Id;
121.
122.
else
123.
124.
nodeId = homePageId;
125.
126.
127.
128.
this
.node = pm.GetPageNode(nodeId);
129.
130.
//if (actualSitemapNode != null)
131.
//
132.
// availableLanguages = actualSitemapNode.AvailableLanguages;
133.
//
134.
//else
135.
//
136.
// availableLanguages = this.node.AvailableCultures;
137.
//
138.
139.
140.
catch
(Exception ex)
141.
142.
throw
ex;
143.
144.
145.
146.
147.
Hi Volkan,
We changes the template of the LanguageSelectorControl. There is a LanguageSelectorType here you can switch between the modes.
<%@ Control Language="C#" %>
<%@ Register TagPrefix="sfFields" Assembly="Telerik.Sitefinity" Namespace="Telerik.Sitefinity.Web.UI.Fields" %>
<%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Web.UI" Assembly="Telerik.Sitefinity" %>
<
div
runat
=
"server"
id
=
"controlWrapper"
>
<
asp:Panel
ID
=
"errorsPanel"
runat
=
"server"
CssClass
=
"sfErrorSummary"
/>
<
sf:ConditionalTemplateContainer
ID
=
"sfLangSelectorConditionalTemplateContainer"
runat
=
"server"
>
<
Templates
>
<
sf:ConditionalTemplate
Left
=
"SelectorType"
Operator
=
"Equal"
Right
=
"Horizontal"
runat
=
"server"
>
<
asp:Repeater
ID
=
"languagesRepeater_horizontal"
runat
=
"server"
>
<
HeaderTemplate
>
<
ul
id
=
"langsWrapper"
class
=
"sflanguagesHorizontalList"
>
</
HeaderTemplate
>
<
ItemTemplate
>
<
li
runat
=
"server"
id
=
"langHolder"
class
=
"sflanguageItem"
>
<
a
runat
=
"server"
id
=
"langLink"
href
=
""
class
=
"sflanguageLnk"
><
span
runat
=
"server"
id
=
"langName"
></
span
></
a
>
</
li
>
</
ItemTemplate
>
<
FooterTemplate
>
</
ul
>
</
FooterTemplate
>
</
asp:Repeater
>
</
sf:ConditionalTemplate
>
<
sf:ConditionalTemplate
Left
=
"SelectorType"
Operator
=
"Equal"
Right
=
"Vertical"
runat
=
"server"
>
<
asp:Repeater
ID
=
"languagesRepeater_vertical"
runat
=
"server"
>
<
HeaderTemplate
>
<
ul
id
=
"langsWrapper"
class
=
"sflanguagesVerticalList"
>
</
HeaderTemplate
>
<
ItemTemplate
>
<
li
runat
=
"server"
id
=
"langHolder"
class
=
"sflanguageItem"
>
<
a
runat
=
"server"
id
=
"langLink"
href
=
""
class
=
"sflanguageLnk"
><
span
runat
=
"server"
id
=
"langName"
></
span
></
a
>
</
li
>
</
ItemTemplate
>
<
FooterTemplate
>
</
ul
>
</
FooterTemplate
>
</
asp:Repeater
>
</
sf:ConditionalTemplate
>
<
sf:ConditionalTemplate
Left
=
"SelectorType"
Operator
=
"Equal"
Right
=
"DropDown"
runat
=
"server"
>
<
div
class
=
"sflanguagesDropDownList"
>
<
asp:DropDownList
runat
=
"server"
ID
=
"langsSelect"
CssClass
=
"sflanguagesDropDown"
></
asp:DropDownList
>
</
div
>
</
sf:ConditionalTemplate
>
</
Templates
>
</
sf:ConditionalTemplateContainer
>
</
div
>
Hi Ivan,
I changed the template with yours. It's ok now. Thanks a lot.