Locate the addition of VSTO according to the language of the office product

I am developing a VSTO add-on and want it to be localized according to the language version of the office product. Theoretically, how to do this:

int lcid = Application.LanguageSettings.get_LanguageID(Office.MsoAppLanguageID.msoLanguageIDUI); System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(lcid); 

For this, I need the Application be initialized, of course. Therefore, the earliest moment I can execute this code is in the Startup event handler. At the moment, however, CreateRibbonExtensibilityObject() has already been called, so at least the title of my custom ribbon tab will display in Windows, which may be different. In the tape class, I have a handler for the IRibbonUI event, where I store an instance of IRibbonUI for later use. I could pass this instance to the addin class and let it call IRibbonUI.Invalidate() on it. But it seems a little strange - creating a tape to make it invalid after a couple of microseconds later. So I ask myself a question - and ask here if there is a more elegant way to localize the vsto add-on ribbon according to the language version of the office product.

(I saw this similar question , but the approach proposed there seems even worse for me.)

+5
source share
1 answer

You can always override the CreateRibbonExtensibilityObject method CreateRibbonExtensibilityObject or possibly override some other AddInBase (BeginInit, Initialize, etc.) to connect to the correct location in the AddIn load life cycle.

I previously overridden CreateRibbonExtensibilityObject to make sure the initialization code is running before the feed is loaded. I noticed that the CreateRibbonExtensibilityObject and Startup events are CreateRibbonExtensibilityObject at arbitrary points in time. Sometimes it happens Startup , sometimes CreateRibbonExtensibilityObject triggered. I had to manually synchronize the two events to ensure that any initialization code runs before the tape is created. If CreateRibbonExtensibilityObject is started first, the application object has not yet been created.

Try this approach in CreateRibbonExtensibility :

  Outlook.Application app = this.GetHostItem<Outlook.Application>(typeof(Outlook.Application), "Application"); int lcid = app.LanguageSettings.get_LanguageID(Office.MsoAppLanguageID.msoLanguageIDUI); Thread.CurrentThread.CurrentUICulture = new CultureInfo(lcid); 

This will return a reference to the Application instance for you - regardless of whether it was still loaded in Initialize .

+8
source

All Articles