|
Heinz-Josef Bomanns
Posts: 206
Joined: 2008-02-28
|
Hi,
i've created a multi language add in (Localizable = True, Language= English, French, German, Spain etc.), toolbars and ribbons are dispalyed in the language chosen in the property window. Now i want the user to be able to choose the language to use 'on the fly' for e.g. via an Options dialog - what'sy the best way to do this and how to switch the language of the add in? Thanks for any hints...__________________
Greetings, HJB
|
|
Posted 16 Jan, 2012 04:59:57
|
|
Top
|
|
Eugene Astafiev
Guest
|
Hi Heinz-Josef,
When your add-in is loaded by the host application the UI language is detected depending on the Office localization and appropriate language should be chosen/applied to the add-in UI automatically. However, if you want to set the UI language manually the best place to do this is the AddinInitialize component (when the add-in starts). Also the Ribbon UI provides you wit the PropertyChanging event which allows you set the Caption property at runtime. For example:
private void adxRibbonButton1_PropertyChanging(object sender, ADXRibbonPropertyChangingEventArgs e)
{
if (e.PropertyType == ADXRibbonControlPropertyType.Caption)
{
e.Value = "your localized string";
}
}
Please remember that localized strings are stored in the resources. So, you need to read them first (steps are common for all .net framework applications) and then set the Caption property of your UI controls. |
|
Posted 16 Jan, 2012 05:53:22
|
|
Top
|
|
Heinz-Josef Bomanns
Posts: 206
Joined: 2008-02-28
|
Hi Eugene,
thanks so far. The original language was German. For the AddinModule 'Localizable' is set to 'True'. Then i set language to 'Engish' and translated buttons and tooltips for the ADXOlExplorerCommandBar and the ADXRibbonTab to english. When i switch language in the properties window of the AddinModule the designer shows correctly german or english captions and tooltips for toolbar and ribbon. I've added
Application.CurrentCulture = New CultureInfo("en-US")
to AddinIntialize and expected to see an english toolbar/ribbon, but they are still showing german captions and tooltips. How do i get the toolbar/ribbon to display in the correct language? Do i have to use something like ComponentRessourceManager and 'ApplyRessources' like in forms? Thanks for any hint...__________________
Greetings, HJB
|
|
Posted 17 Jan, 2012 04:08:56
|
|
Top
|
|
Eugene Astafiev
Guest
|
Hi Heinz-Josef,
Please use the GetString method of the System.ComponentModel.ComponentResourceManager class for retrieving localized text from resources on the fly:
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(AddinModule));
adxRibbonButton1.Caption = resources.GetString("adxRibbonButton1.Caption", new System.Globalization.CultureInfo("ru-RU")); |
|
Posted 17 Jan, 2012 08:23:26
|
|
Top
|
|
Heinz-Josef Bomanns
Posts: 206
Joined: 2008-02-28
|
Hi Eugene,
the add in has about a dozend toolbars and each toolbar has several dozend controls, so coding a line 'resources.GetString...' for each control isn't practicable, would take me hours. I tried to use a recursive 'for each' loop to do this job like this:
Dim crm As ComponentResourceManager
Dim ci As CultureInfo
Private Sub ChangeLanguage(ByVal root As Object)
Dim ctl As Object 'Control
Try
crm.ApplyResources(root, root.Name, ci)
For Each ctl In root.Controls
ChangeLanguage(ctl)
Next 'ctl
Catch ex As Exception
Debug.Print(ex.Message)
End Try
End Sub 'ChangeLanguage()
Public Sub SetLanguage(ByVal cb As Object, ByVal lng As String)
Dim ctl As Object 'Control
On Error Resume Next
crm = New ComponentResourceManager(cb.GetType)
ci = New CultureInfo(lng)
For Each ctl In cb.Controls
ChangeLanguage(ctl)
Next 'ctl
End Sub 'SetLanguage
'cb' is an ADXOlExplorerCommandBar, 'lng' the language code like 'en-US'. A similar mechanismn for forms works well, but here i get an exception from 'ApplyResources': 'System.MissingMemberException, Public member 'Name' on type 'ADXCommandBarButton' not found.' - why isn't the 'Name' property accessible and how can i make it accessible? For nearly all other .NET controls 'Name' is accessibel, why not for this ADX controls?__________________
Greetings, HJB
|
|
Posted 17 Jan, 2012 11:54:02
|
|
Top
|
|
Eugene Astafiev
Guest
|
Hi Heinz-Josef,
Thank you for sharing your code for other forum readers.
Note that the Name property doesn't exist in the CommandBarButton class (which comes from the Office Object Model). That is why the AddinExpress.MSO.ADXCommandBarButton class doesn't have it too.
FYI To get assistance with host applications?Â?Ð?é objects, their properties, and methods as well as help info, use the Object Browser. Go to the VBA environment (in the host application, choose menu Tools | Macro | Visual Basic Editor or just press {Alt+F11}), press {F2}, select the host application in the topmost combo and/or specify a search string in the search combo. Select a class/property/method and press {F1} to get the help topic that relates to the object. |
|
Posted 18 Jan, 2012 05:35:18
|
|
Top
|
|
Heinz-Josef Bomanns
Posts: 206
Joined: 2008-02-28
|
Hi Eugene,
>the Name property doesn't exist in the CommandBarButton class
Thanks, i now use 'Tag' or 'ID' property to pass the name to my routines, works fine so far. Currently under pressure with my deadline, will post the solution next week...__________________
Greetings, HJB
|
|
Posted 20 Jan, 2012 00:02:03
|
|
Top
|
|
Eugene Astafiev
Guest
|
Hi Heinz-Josef,
Good luck with your add-in project! :-) |
|
Posted 20 Jan, 2012 00:22:33
|
|
Top
|
|