5

我正在尝试本地化我的办公室插件,我已经阅读了许多关于如何做到这一点的文档和教程,但他们都教如何根据当前的 Windows 语言进行本地化,而不一定是办公室语言界面包正在使用中。

所以我最终遇到了我的 Windows 语言是法语的情况,我没有任何 Office 语言界面包,因此我在 Office 中的所有菜单都是英语的,除了我的加载项是法语的。它看起来有点奇怪,所以我想知道是否有一种方法可以根据当前使用的办公语言界面包进行本地化。

4

4 回答 4

4

我发现 的值Thread.CurrentThread.CurrentCulture与我的系统文化相对应,而 的值则Thread.CurrentThread.CurrentUICulture与 Office UI 相对应。

所以我只是在加载项启动时将一个分配给另一个。似乎工作。

Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture;
于 2012-08-01T16:51:24.773 回答
2

这是我解决此问题的方法。我基本上阅读了 Ron 建议的注册表项,并将文化强制转换为已安装的语言文化。我只支持 Office 2007 和 Office 2010。很糟糕,我们必须查看每个 office 版本的 CU 和 LM 注册表项,并且没有单个内部变量将我们指向正确的注册表路径。解决方法如下:

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);

Resource1 是我的资源字典,culture 参数在使用时强制使用该文化覆盖所有字符串。

于 2011-11-08T22:29:28.363 回答
2

有一个 MSDN page on Loading Resources Based on Office User Interface Language 。那里给出的代码示例对我有用。它使用 Application 对象中的 LanguageSettings 来确定 Office UI 的当前语言。到目前为止,我已经使用 Word 2010 和 Outlook 2010 对其进行了测试,并且我很确定它也可以与其他 Office 2010 产品一起运行。我不能在 Office 2007 上说什么,但我会试一试,因为它比查询注册表要容易得多。

对于如何使用这种方法的一些详细问题,我刚刚得到了一些有用的 SO 用户的回答。

于 2011-12-16T09:38:09.617 回答
1

读一点http://technet.microsoft.com/en-us/library/cc179091%28office.12%29.aspx

您可以阅读“HKCU\Software\Microsoft\Office\12.0\Common\LanguageResources\UILanguage”注册表项来确定 UI 是哪种语言。

于 2011-11-04T18:07:53.373 回答