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.
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;
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.
There is a MSDN page on Loading Resources Based on Office User Interface Language
. The code sample given there works for me. It's using the LanguageSettings from the Application object to determine the current language of the Office UI. I've tested it so far with Word 2010 and Outlook 2010, and I'm pretty sure it runs with the other Office 2010 products as well. I can't say anything on Office 2007, but I would give it a try, since it's so much easier than querying the registry.
For some detail question on how to employ this approach I've just got an answer here by some helpful SO user.
read a bit into http://technet.microsoft.com/en-us/library/cc179091%28office.12%29.aspx
you could read the "HKCU\Software\Microsoft\Office\12.0\Common\LanguageResources\UILanguage" registry key to determine which language the UI is.