Category / Section
How to localize the navigation pane button text in WinForms GroupBar?
2 mins read
Localize the navigation pane button text
In GroupBar control, NavigationPane button text can be localized to any Language. Below steps helps to provide the localization for NavigationPane button text.
Step 1: Need to initialize the LocalizationProvider class, inherited from the ILocalizationProvider interface.
Step 2: Need to add the GetLocalizedString function in the LocalizationProvider class. It is used to provide the localized content for the options in NavigationPane of GroupBar.
Here, NavigationPane button text is localized in Arabic Language. The following code demonstrates the same.
C#
//Codes in Form1.cs LocalizationProvider.Provider = new localizer(); //For Arabic Language CultureInfo Arabic = new CultureInfo("ar"); LocalizationProvider.Provider = new Localizer(Arabic); class Localizer : ILocalizationProvider { CultureInfo CustomCulture; #region ILocalizationProvider Members public Localizer() { } public Localizer( CultureInfo choosenCulture ) { CustomCulture = choosenCulture; } public string GetLocalizedString(System.Globalization.CultureInfo culture, string name,object obj) { //Arabic language if (this.CustomCulture != null && this.CustomCulture.Name == "ar") { switch (name) { #region Menu Package case ToolsResourceIdentifiers.MoreButtonsItemsText: return "عرض المزيد من الأزرار"; case ToolsResourceIdentifiers.FewerButtonsItemsText: return "إظهار أزرار أقل"; case ResourceIdentifiers.GroupBarAddRemoveButton: return "إضافة أو إزالة الأزرار"; #endregion default: return string.Empty; } } return string.Empty; } #endregion }
Code Example: [VB]
'Codes in Form1.vb LocalizationProvider.Provider = New Localizer() 'For Arabic Language Dim Arabic As New CultureInfo("ar") LocalizationProvider.Provider = New Localizer(Arabic) Friend Class Localizer Implements ILocalizationProvider Private CustomCulture As CultureInfo #Region "ILocalizationProvider Members" Public Sub New() End Sub Public Sub New(ByVal choosenCulture As CultureInfo) CustomCulture = choosenCulture End Sub Private Function ILocalizationProvider_GetLocalizedString(culture As CultureInfo, name As String, ctrl As Object) As String Implements ILocalizationProvider.GetLocalizedString 'Arabic language If Me.CustomCulture IsNot Nothing AndAlso Me.CustomCulture.Name = "ar" Then Select Case name '#Region "Menu Package" Case ToolsResourceIdentifiers.MoreButtonsItemsText Return "عرض المزيد من الأزرار" Case ToolsResourceIdentifiers.FewerButtonsItemsText Return "إظهار أزرار أقل" Case ResourceIdentifiers.GroupBarAddRemoveButton Return "إضافة أو إزالة الأزرار" '#End Region Case Else Return String.Empty End Select End If Return String.Empty End Function #End Region End Class
Screenshot
Figure: Before localization.
Figure: After localization
Samples:
C#: GroupBarExample
VB: GroupBarExample