【问题标题】:Localize Office add-in based on Office language pack in use rather than Windows' current language根据正在使用的 Office 语言包而不是 Windows 的当前语言本地化 Office 加载项
【发布时间】:2011-11-04 17:48:04
【问题描述】:

我正在尝试本地化我的 office 插件,我已经阅读了许多有关如何执行此操作的文档和教程,但它们都教如何根据当前的 Windows 语言进行本地化,而不一定是什么办公语言界面包正在使用中。

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

【问题讨论】:

    标签: c# localization outlook ms-office office-addins


    【解决方案1】:

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

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

    Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture;
    

    【讨论】:

      【解决方案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 参数强制所有字符串在使用时都被该文化覆盖。

      【讨论】:

        【解决方案3】:

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

        关于如何使用这种方法I've just got an answer here 的一些有用的 SO 用户的一些详细问题。

        【讨论】:

          【解决方案4】:

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

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

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 2021-08-28
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2013-01-31
            • 1970-01-01
            相关资源
            最近更新 更多