Wrong CurrentUICulture with Teamviewer installed

Add-in Express™ Support Service
That's what is more important than anything else

Wrong CurrentUICulture with Teamviewer installed
 
Christopher Thiede




Posts: 38
Joined: 2016-07-05
Hi,

I read this topic with the same title but it doesn't helped me. I can't answer this old topic. Therefore I start it againn.

Currently I have the same problem. A customer (and now me too) has TeamViewer installed with Outlook Add-In.

I get in trouble because out Add-In Ribbon Menu Button is shown in english instead of german. The dynamic insert Menu is in german because I set the CurrentUiCulture in my OnAddinInitialize method.


private void OnAddinInitialize(object sender, EventArgs eventArgs)
{
    Thread.CurrentThread.CurrentCulture = new CultureInfo(OutlookApp.LanguageSettings.get_LanguageID(MsoAppLanguageID.msoLanguageIDUI));
}

But I can't set the CurrentUiCulture in the Constructor of my AddIn or in InitializeComponent method. If I try I get the error: Can not register the Assembly MyAddIn.dll.

Where should I set the CurrentUiCulture to change the language for my RibbonMenuButton?

Thx
Christopher
Posted 19 Dec, 2016 16:37:48 Top
Andrei Smolin


Add-in Express team


Posts: 14140
Joined: 2006-05-11
Hello Christopher,

Please have a look at https://www.add-in-express.com/forum/read.php?FID=5&TID=14243&MID=72957#message72957 (the last post having a code sample on that page). On that page we describe an approach to creating an add-in which retrieves the localization of the host Office application and sets CurrentUICulture accordingly.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 20 Dec, 2016 06:13:10 Top
Christopher Thiede




Posts: 38
Joined: 2016-07-05
Hello Andrei,

thx for your fast response. I tried to override the method OnHostApplicationInitialized but there is no suitable method in my AddinExpress.MSO.ADXAddinModule. I tried your C# sample AddinModule. Same error: no suitable method. What's wrong with my configuration? I use Add-in Express for Microsoft Office and .NET, Standard for Visual Studio 2015 Version 8.2.4371.0.
Posted 20 Dec, 2016 06:32:21 Top
Andrei Smolin


Add-in Express team


Posts: 14140
Joined: 2006-05-11
Christopher,

OnHostApplicationInitialized was introduced in Add-in Express for Office and .NET version 8.3. Please install the latest Add-in Express build.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 20 Dec, 2016 06:59:31 Top
Christopher Thiede




Posts: 38
Joined: 2016-07-05
Hi Andrei,

Setting the CurrentCulture and CurrentUICulture in OnHostApplicationInitialized() works fine.

But I think it is not best practise to set CurrentCulture and CurrentUICulture because any other Add-In can do this.
Therefore I tried to use overload of ApplyResources in InitialzeComponent() to set the Culture for each localizable string. But this didn't work. The Assembly can't be registered on build.


private CultureInfo CurrentAppCulture => new CultureInfo(GetLanguageID());

private int GetLanguageID()
{
  LanguageSettings languageSettings = OutlookApp.LanguageSettings;
  if (languageSettings != null)
    try
    {
      return languageSettings.LanguageID[MsoAppLanguageID.msoLanguageIDUI];
    }
    finally { Marshal.ReleaseComObject(languageSettings); }
    
  return 0;
}

private void InitializeComponent()
{
  ...
  resources.ApplyResources(this.adxRibbonTabStart, "adxRibbonTabStart", CurrentAppCulture);

  ...
}
Posted 27 Dec, 2016 08:52:19 Top
Andrei Smolin


Add-in Express team


Posts: 14140
Joined: 2006-05-11
Hello Christopher,

Check https://www.add-in-express.com/creating-addins-blog/2016/12/20/localize-office-addins-forms-based-resources/.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 27 Dec, 2016 08:59:27 Top
Christopher Thiede




Posts: 38
Joined: 2016-07-05
Hi,

I thinks this approach can fail if another Add-In tries to set CurrentCulture and/or CurrentUICulture directly after my AddIn set it to my favorite language. Isn't it possible?
Posted 27 Dec, 2016 09:09:06 Top
Andrei Smolin


Add-in Express team


Posts: 14140
Joined: 2006-05-11
Christopher,

If your add-in has called ApplyResources then any other add-in modifying the culture *after* this moment, can't influence the UI of your add-in. It may influence other parts of your add-in however but this depends on how the actual code that you use depends on the culture.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 27 Dec, 2016 09:39:10 Top
Christopher Thiede




Posts: 38
Joined: 2016-07-05
Good morning,

I ment your approach using switching the Language in OnHostApplicationInitialized and then use InitializeComponents.
Therefore I tried using overload of ApplyResources in InitializeComponents. But this didn't work because the Assembly can't be registered on build process.
Posted 28 Dec, 2016 01:54:25 Top
Andrei Smolin


Add-in Express team


Posts: 14140
Joined: 2006-05-11
Hello Christopher,

Does the project described in that blog works for you?

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 28 Dec, 2016 04:51:09 Top