Change text of language selector
Hello Everyone,
I have language slector wideget in master page of my website. When i
drag the widget it shows only name of language i.e English. I want to
change that text Site in English. What should i do to change the text
English & replace it with Site in English ?
Kind Regards,
Nrv.
Hello Srk,
Based on passed experience with having to modify the language control, I am going to say that you are going to to need to create a custom language control. You are going to need to override the BindLanguageContainers method of that control. I don't know know what type of Language Selector you are using (Dropdown, Horizontal, or Vertical) but my example below is using a drop down. Here is some sample code to get you started. It builds but I can't guarantee it will do everything that you want from the get go. You will need to override the Control CLR Type or Virtual Path property in the Administration Settings to override the original Language control with the new one.
[ControlDesigner(typeof(LanguageSelectorDesigner))]
public class CustomLanguageSelector : LanguageSelectorControl
#region Construction
/// <
summary
>
/// Initializes a new instance of the <
see
cref
=
"CustomLanguageSelector"
/> class.
/// </
summary
>
public CustomLanguageSelector()
: base()
#endregion
#region Overwritten methods
/// <
summary
>
/// Binds the language containers (repeater or drop down) with the specified languages
/// </
summary
>
/// <
param
name
=
"shownLanguages"
>The languages.</
param
>
protected override void BindLanguageContainers(IEnumerable<
CultureInfo
> languages)
if (this.SelectorType == LanguageSelectorType.DropDown)
var dropDown = this.LanguagesDropDown;
if (!this.IsDesignMode())
dropDown.Attributes["onChange"] = "document.location.href = this.value;";
foreach (var lang in languages)
var langName = GetDisplayedLanguageName(lang);
var url = GetUrlForLanguage(lang);
url = RouteHelper.ResolveUrl(url, UrlResolveOptions.Absolute);
if (lang.DisplayName == "English")
ListItem item = new ListItem("Site", url);
item.Attributes.Add("lang", lang.TwoLetterISOLanguageName);
dropDown.Items.Add(item);
else
ListItem item = new ListItem(langName, url);
item.Attributes.Add("lang", lang.TwoLetterISOLanguageName);
dropDown.Items.Add(item);
else
base.BindLanguageContainers(languages);
/// <
summary
>
/// Gets the languages to display.
/// </
summary
>
/// <
returns
></
returns
>
protected override IEnumerable<
CultureInfo
> GetLanguagesToDisplay()
var shownLanguages = base.GetLanguagesToDisplay();
if (this.SelectorType == LanguageSelectorType.DropDown && !this.ShowCurrentLanguage)
CultureInfo currentLanguage = Thread.CurrentThread.CurrentUICulture;
shownLanguages = shownLanguages.Where(ci => !ci.Equals(currentLanguage));
return shownLanguages;
#endregion
#region Constants
/// <
summary
>
/// This constant represents the value that will be seen when the
/// language selector is set to drop-down without showing the current language.
/// </
summary
>
private const string DefaultLanguageName = "Select language";
#endregion