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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With