Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Localize Office add-in based on Office language pack in use rather than Windows' current language

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.

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.

like image 995
Reza S Avatar asked Nov 04 '11 17:11

Reza S


2 Answers

I found that the value of Thread.CurrentThread.CurrentCulture corresponded to my system culture, and the value of Thread.CurrentThread.CurrentUICulture corresponded to the Office UI.

So I simply assigned one to the other on add-in startup. Seems to work.

Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture;
like image 158
Andy McCluggage Avatar answered Sep 29 '22 00:09

Andy McCluggage


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

Resource1 is my resource dictionary, and the culture parameter forces all strings to be overridden with that culture when used.

like image 40
Reza S Avatar answered Sep 29 '22 01:09

Reza S