根据办公产品的语言本地化VSTO插件 [英] localize VSTO addin according to the language of the office product

查看:181
本文介绍了根据办公产品的语言本地化VSTO插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个VSTO插件,并希望它按照办公产品的语言版本进行本地化。从理论上讲,这是如何做到这一点:

I'm developing a VSTO addin and want it to be localized according to the language version of the office product. In theory, that's how to do it:

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

对于这个工作,我需要应用程序来进行初始化的,当然。所以,在这里我能执行此code最早的一点是,在启动事件处理程序。在这一点上,然而, CreateRibbonExtensibilityObject()已被调用,所以至少我的自定义功能区选项卡的标题将被显示在Windows的语言,这可能是不同。 在功能区类我有一个处理程序onLoad事件,我在那里存放的 IRibbonUI 的实例,以供日后使用。我可以交出该实例的插件类,让它调用 IRibbonUI.Invalidate()就可以了。但是,这似乎有点奇怪 - 创建一个带状只是后来使它无效几微秒。所以我想 - 问这里 - 是否有更优雅的方式按照办公产品的语言版本本地化VSTO插件的带状

For this to work I need Application to be initialized, of course. So the earliest point where I can execute this code is in the Startup event handler. At this point, however, CreateRibbonExtensibilityObject() already has been called, so at least the title of my custom ribbon tab is going to be displayed in the Windows language, which might be different. In the ribbon class I have a handler for the onLoad event, where I store an instance of IRibbonUI for later use. I could hand over this instance to the addin class and let it call IRibbonUI.Invalidate() on it. But this seems to be a bit strange - creating a ribbon just to invalidate it a couple of microseconds later. So I wonder - and ask here - whether there is a more elegant way to localize the ribbon of a vsto addin according to the language version of the office product.

(我见过的<一个href="http://stackoverflow.com/questions/8013658/localize-office-add-in-based-on-office-language-pack-in-use-rather-than-windows">this类似的问题,但该方法通过这个答案提供有看起来更糟我。)

(I've seen this similar question, but the approach offered there by this answer looks even worse to me.)

推荐答案

您可以随时重写<一href="http://msdn.microsoft.com/en-us/library/microsoft.office.tools.addinbase.createribbonextensibilityobject.aspx"><$c$c>CreateRibbonExtensibilityObject方法或可能忽略一些其他的 AddInBase 方法( BeginInit在,初始化等。的)挂接到在外接程序负载生命周期中的正确位置。

You can always override the CreateRibbonExtensibilityObject method or possibly override some of the other AddInBase methods (BeginInit, Initialize, etc.) to hook into the proper location in the AddIn load lifecycle.

我已经覆盖了 CreateRibbonExtensibilityObject 前确保初始化code是功能区加载之前运行。我注意到, CreateRibbonExtensibilityObject 启动事件是在随机时间触发。有时启动首先发生 - 有时 CreateRibbonExtensibilityObject 触发第一。我不得不手动同步两个事件,以确保任何初始化code先于功能区建立执行。如果 CreateRibbonExtensibilityObject 第一发射 - 应用程序对象尚未建立。

I have overridden the CreateRibbonExtensibilityObject before to ensure that initialization code is run before the Ribbon is loaded. I have noticed that CreateRibbonExtensibilityObject and Startup events are triggered at random times. Sometimes Startup happens first - sometimes CreateRibbonExtensibilityObject fires first. I had to manually synchronize the two events to ensure any initialization code is executed prior to Ribbon creation. If CreateRibbonExtensibilityObject fires first - the Application object has not yet been created.

 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 retrieve a reference to the Application instance for you - regardless if it has been loaded in the Initialize yet.

这篇关于根据办公产品的语言本地化VSTO插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆