问题描述
我想我的本地化办公室插件,我已经经历了许多文档并就如何做到这一点的教程阅读,但他们都教了如何基于什么当前Windows语言,不一定是本地化它办公语言界面包正在使用中。
I'm trying to localize my office add-in, I've read through many docs and tutorials on how to do this, but they all teach on how to localize it based on what the current Windows language, not necessarily what office language interface pack is in use.
于是我在的情况下我的Windows语言是法语结束了,我没有任何的办公语言界面包,所以我所有的在Office的菜单都是英文,除了我的加载项是法语。它看起来有点古怪,所以我想知道是否有根据当前使用的Office语言界面包本地化的方式。
So I end up in a situation where my Windows language is French, I don't have any office language interface packs, therefore all my menus in the Office are in English, except my add-in which is in French. It looks kind of odd, so I was wondering if there's a way to localize based on current office language interface pack in use.
推荐答案
这是我对解决这个问题的办法。我基本上都看过罗恩建议,并迫使文化融入到安装的语言文化中的注册表项。我只支持Office 2007和Office 2010中它吮吸,我们要看看每个Office的各个版本的CU和LM的注册表项,并有指向我们正确的注册表路径没有单一的内部变量。解决的方法是如下:
This was my approach on fixing this issue. I basically read the registry keys that Ron suggested and forced the culture into the installed language culture. I only support Office 2007 and Office 2010. It sucks that we have to look at CU and LM registry entries for each of the versions of the office, and there is no single internal variable pointing us to the correct registry path. The solution is as follow:
int languageCode = 1033; //Default to english
const string keyEntry = "UILanguage";
if (IsOutlook2010)
{
const string reg = @"Software\Microsoft\Office\14.0\Common\LanguageResources";
try
{
RegistryKey k = Registry.CurrentUser.OpenSubKey(reg);
if (k != null && k.GetValue(keyEntry) != null) languageCode = (int)k.GetValue(keyEntry);
} catch { }
try
{
RegistryKey k = Registry.LocalMachine.OpenSubKey(reg);
if (k != null && k.GetValue(keyEntry) != null) languageCode = (int)k.GetValue(keyEntry);
} catch { }
}
else
{
const string reg = @"Software\Microsoft\Office\12.0\Common\LanguageResources";
try
{
RegistryKey k = Registry.CurrentUser.OpenSubKey(reg);
if (k != null && k.GetValue(keyEntry) != null) languageCode = (int)k.GetValue(keyEntry);
} catch { }
try
{
RegistryKey k = Registry.LocalMachine.OpenSubKey(reg);
if (k != null && k.GetValue(keyEntry) != null) languageCode = (int)k.GetValue(keyEntry);
} catch { }
}
Resource1.Culture = new CultureInfo(languageCode);
资源1是我的资源字典,以及文化参数强制所有字符串与文化使用时,可以覆盖
Resource1 is my resource dictionary, and the culture parameter forces all strings to be overridden with that culture when used.
这篇关于本地化Office加载项的基础上使用Office语言包,而不是Windows的当前语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!