Pieter van der Westhuizen

How to localize your Office COM add-in

Let’s be honest, the present day market place is an international one. It is no longer good enough to only have your application and/or add-in support just in one language. If you’re planning on taking over the world you need to start thinking “localization”.

The top three most popular languages spoken worldwide today is:

  • Mandarin – 882 million
  • Spanish – 325 million
  • English – 312 to 380 million

In today’s post I’ll show you how to enable your ADX add-in to support localization. We’ll tap into the English and Spanish markets with our sample add-in. Apologies in advance for our Spanish readers if I made a few grammatical errors. :)

Start by creating a new ADX COM Add-in project in Visual Studio.

Creating a new Add-in Express COM Add-in project in Visual Studio

Finish the wizard by selecting Visual C# as the programming language, Microsoft Office 2007 as the minimum supported Office version and Microsoft Outlook as the supported application.

Open the AddinModule designer and set its Localizable property to True and make sure the Language property is set to Default. This is needed if your add-in is installed on a pc where the supported languages are not installed. Your add-in will then use the default language.

Add a Ribbon Tab control to the designer and change its design to resemble the screenshot below.

Adding a Ribbon Tab control to the designer

Next, change the AddinModule’s Language property to Spanish. Change the components’ Caption properties to Spanish.

Changing the components' Caption properties to Spanish

You’ll notice as you change the Language property of the AddinModule, new .resx files are added below the AddinModule.cs file in the Solution Explorer. Each of these files contains string values for the specific language.

Solution Explorer

Build, register and run your project. You should see the Archive ribbon tab in Outlook. To test the Spanish localization in Windows 7, go to Control Panel > Change display language and select espanol in the language dropdown list.

Testing the Spanish localization

You’ll need to log off in order for the new display language to be used, when you open Outlook again, you’ll notice that your add-in is now in Spanish.

Thank you for reading. Until next time, keep coding!

18 Comments

  • Andrew says:

    Hello there,

    This works fine if both the operating system and office are in the same language.
    However, there is a problem if the operating system is in different language that the office language.

    For example if windows is GB English version and outlook version is Spanish the .NET Thread.CurrentThread.CultureUiThread returns en-gb.

    According to Microsoft https://msdn.microsoft.com/en-us/library/ms178762%28v=VS.100%29.aspx#sectionToggle3
    You need to set in your add-in:

    System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(
    Application.LanguageSettings.get_LanguageID(Office.MsoAppLanguageID.msoLanguageIDUI));

    As a result we need to set the thread culture before the add-in express control are initialized.

    But in the add-in express constructor the property HostApplication is null.

    public AddinModule()
    {
    var outlookApplication = HostApplication as Outlook.Application;
    Thread.CurrentThread.CurrentUICulture = new CultureInfo(
    outlookApplication.LanguageSettings.get_LanguageID(Office.MsoAppLanguageID.msoLanguageIDUI));

    InitializeComponent();

    }

    Is there another way to do this?

  • Pieter van der Westhuizen says:

    Hi Andrew,

    A very interesting scenario. You’re code will work if you put it in the AddinStartupComplete event, e.g:

    private void AddinModule_AddinStartupComplete(object sender, EventArgs e)
    {
    Thread.CurrentThread.CurrentUICulture = new CultureInfo(this.OutlookApp.LanguageSettings.get_LanguageID(Microsoft.Office.Core.MsoAppLanguageID.msoLanguageIDUI));
    }

    You can also use the use the OutlookApp property of the AddinModule class instead of using HostApplication directly.

    Hope this helps!

    -Pieter

  • Bianca Saftoiu says:

    This was not working for me. Do you have any idea ?

  • Pieter van der Westhuizen says:

    Hi Bianca,

    Can you give some more info on what exactly is not working?

  • Bianca Saftoiu says:

    I used this code:

    private void AddinModule_AddinStartupComplete(object sender, EventArgs e)
    {
    Thread.CurrentThread.CurrentUICulture = new CultureInfo(this.OutlookApp.LanguageSettings.get_LanguageID(Microsoft.Office.Core.MsoAppLanguageID.msoLanguageIDUI));
    }

    But is not working, is “too late” to change the thread language, the components there are already initialized.

  • Pieter van der Westhuizen says:

    Hi Bianca,

    Try adding this code to the AddinInitialize event and see if you get a better result:
    Thread.CurrentThread.CurrentUICulture = new CultureInfo(ExcelApp.LanguageSettings.LanguageID[Microsoft.Office.Core.MsoAppLanguageID.msoLanguageIDUI]);

    Hope this helps!

  • Bianca Saftoiu says:

    Same result, does not work.

  • Pieter van der Westhuizen says:

    Hi Bianca,

    Would you mind sending your sample project to our support e-mail. You can find the email in the readme.txt file.

    Please mark the email for my attention.

    Thank you!

  • Bianca Saftoiu says:

    I can’t do this. But to reproduce my problem it is very simple. So, you should do the following steps:

    1. To add any ribbon(or other element) for test.
    2. Translate the caption in two languages ( my example: English & German)
    3. Test like German Windows and English Office – if our Ribbon is translated in English like the Office
    OR

    English Windows with German Office – if our Ribbon is translated in German like the Office

    OR

    Any different pair of (Windows, Office)

    The UI language should be the Office language, not the OS language and I cannot do this.

  • Dmitry Kostochko (Add-in Express Team) says:

    Hi Bianca,

    Thank you for the detailed description, it was helpful.

    You need to use the OnRibbonBeforeCreate event. Please try to move your code that sets CurrentUICulture to this event handler.

  • Ankush Jain says:

    Hi,

    Need to know where do we create the OnRibbonBeforeCreate event, in AddIn or in the Ribbon class.
    I am seeing a issue that the language of the labels in my Ribbon are not changing as per the office language, whereas the other dialog boxes the language is changing. I have English Windows and based on the office language I am trying to localize my Outlook Plugin.
    I have used the command to set office language as Thread language in private void ThisAddIn_Startup(object sender, System.EventArgs e) currently.

  • Pieter van der Westhuizen says:

    Hi Ankush,

    If you’re using Add-in Express you can select the AddinModule class, switch to the Events list in the Properties window and double-click next to the OnRibbonBeforeCreate event name.
    This will then automatically generate an event stub for you inside the AddinModule.cs class file e.g:

    private void AddinModule_OnRibbonBeforeCreate(object sender, string ribbonId)
    {

    }

    Hope this helps. Good luck!

  • Ankush Jain says:

    Hi,

    I am not using the AddIn Express but I tried creating the function in the as you said in my ThisAddIn.cs file.
    The language change for the dialog boxes also went off.

  • Pieter van der Westhuizen says:

    Hi Ankush,

    So after adding the code to the RibbonBeforeCreate event, the language now does not change in the message boxes?

  • Jörg Werner says:

    Hi,

    after adding the code to the RibbonBeforeCreate event the language will not change either. If I move

    Thread.CurrentThread.CurrentUICulture = new CultureInfo(ExcelApp.LanguageSettings.LanguageID[Microsoft.Office.Core.MsoAppLanguageID.msoLanguageIDUI]);

    to the beginning of my Addin creator, I can not build my solution.

    Reason I think is:
    https://www.add-in-express.com/forum/read.php?FID=5&TID=11283

    How can I use the Outlook display language to choose the language for my ribbons?

    Thank you!

  • Andrei Smolin (Add-in Express Team) says:

    Hello Jörg,

    Since you create a CultureInfo basing on the information provided by the Excel object model, you have to use the ExcelApp property only when it is initialized; it isn’t initialized when the constructor of the add-in module is created.

    An Office add-in can be started in a number of ways that differ in the event which is called first: AddinInitialize or OnRibbonBeforeCreate. Whatever event occurs first, you can set Thread.CurrentThread.CurrentUICulture first and invoke the InitializeComponent method then; this assumes that you remove the InitializeComponent() call from the constructor and thus you cannot use design-time features of Add-in Express.

  • Velja Radenkovic says:

    The conclusion is that with add in express, if you want to be able to use add in express VS designer you can not localize your add in? Am I correct?

    Thank,
    Velja

  • Andrei Smolin (Add-in Express Team) says:

    Hello Velja,

    Please find my response at https://www.add-in-express.com/forum/read.php?FID=5&TID=14243&MID=72928.

Post a comment

Have any questions? Ask us right now!