Where does the largegalleryButton picks the value from ?
In other words how do i customize it ?
from where does it pick the value denmark from as in the screenshot?
Sitecore Stack Exchange is a question and answer site for developers and end users of the Sitecore CMS and multichannel marketing software. It only takes a minute to sign up.
Sign up to join this communityWhere does the largegalleryButton picks the value from ?
In other words how do i customize it ?
from where does it pick the value denmark from as in the screenshot?
It's the command Sitecore.Shell.Framework.Commands.Ribbon.Languages
which has GetIcon
method.
<command name="ribbon:languages"
type="Sitecore.Shell.Framework.Commands.Ribbon.Languages,Sitecore.Kernel"/>
Code for icon:
public override string GetIcon(CommandContext context, string icon)
{
Assert.ArgumentNotNull((object) context, nameof (context));
Assert.ArgumentNotNullOrEmpty(icon, nameof (icon));
if (context.Items.Length == 1)
{
Item obj = context.Items[0];
string icon1 = LanguageService.GetIcon(obj.Language, obj.Database);
if (!string.IsNullOrEmpty(icon1))
return icon1;
}
return base.GetIcon(context, icon);
}
And header text:
public override string GetHeader(CommandContext context, string header)
{
Assert.ArgumentNotNull((object) context, nameof (context));
Assert.ArgumentNotNull((object) header, nameof (header));
if (context.Items.Length == 1)
{
CultureInfo cultureInfo = context.Items[0].Language.CultureInfo;
if (cultureInfo.IsNeutralCulture)
cultureInfo = Language.CreateSpecificCulture(cultureInfo.Name);
using (new ThreadCultureSwitcher(Context.Language.CultureInfo))
{
string displayName = cultureInfo.DisplayName;
if (!string.IsNullOrEmpty(displayName))
return displayName;
}
}
return base.GetHeader(context, header);
}
If you are looking at the Language Name, then it should be from the
System.Globalization.CultureInfo.GetCultureInfo.DisplayName
I think what you looking for is to display the name of the foreign language in the native language. For that, instead of using DisplayName you have to NativeName in the method.
var culture = Thread.CurrentThread.CurrentCulture.NativeName;
So you need to override the standard implementation with your custom one. One of the way could be to make a copy of Sitecore.Shell.Framework.Commands.Ribbon.Languages
command and update the method GetHeader to display NativeName, update your config file and Sitecore Item to point towards the new method and you should be good.
public override string GetHeader(CommandContext context, string header)
{
Assert.ArgumentNotNull((object) context, nameof (context));
Assert.ArgumentNotNull((object) header, nameof (header));
if (context.Items.Length == 1)
{
CultureInfo cultureInfo = context.Items[0].Language.CultureInfo;
if (cultureInfo.IsNeutralCulture)
cultureInfo = Language.CreateSpecificCulture(cultureInfo.Name);
using (new ThreadCultureSwitcher(Context.Language.CultureInfo))
{
string displayName = cultureInfo.NativeName;//change this line
if (!string.IsNullOrEmpty(displayName))
return displayName;
}
}
return base.GetIcon(context, header);
}
As default, Sitecore uses ASP.NET globalization ISO code and language names . The Sitecore predefined languages are coming from the configuration file located at /App_Config/LanguageDefinitions.config
.