Visual Studio Addin Menus - Internationalization RRS feed

  • Question

  • I am having a large problem with adding menus in Visual Studio.  When I run my addins on a standard en_US locale there are no issues.  The problem popped up when I internationalized my addins.  For Visual Studio 2005 I found that I needed to use the translated version of "Tools" in order to add my menus.  The problem was that I needed to provide this translation myself.  I would like to move away from this dependance.  Is there any way to access the menu in a more basic way than this?  As in a way to reference the ResourceManager that Visual Studio uses to translate "Tools" in the first place?

    The real problem is that when I run the Visual Studio 2003 version of the addin the "tools" menu is not found - even though the string that I am using to try and access the menu is the same as the translated string found in my VS2005 addin (which does work in japanese).

    Thanks for your time


    Friday, June 23, 2006 11:34 PM


  • Hi Russ,

    There are two things here:

    1) Getting a commandbar from the DTE.CommandBars collection by name. A CommandBar has the properties Name and NameLocal and AFAIK, using DTE.CommandBars.Item(englishName) always work, even if the IDE is localized. I have been doing this for ages (VB5, VB6, VS.NET 2002, 2003 and 2005) without problem and I am Spanish and therefore aware of localization issues (although I use English versions most of the time). So, DTE.CommandBars.Item("Tools") should work always. In the add-in code generated by the VS 2005 add-in wizard for VB, notice that the wizard generates this code without localization issues:

    Dim menuBarCommandBar As CommandBar = commandBars.Item("MenuBar")

    In Spanish "MenuBar" is "Barra de menús" but there is no need to localize that, the code is correct.

    And my MZ-Tools add-in uses English names to locate many command bars and nobody has reported a problem regarding this from non-English countries.

    2) Getting a CommandBarControl from the CommandBar.Controls collection by caption. A CommandBarControl does not have a Name or NameLocal property, only a Caption property which of course is localized. So, if you want to find a CommandBarControl to get it or its associated CommandBarPopup (more on this later) you need to take into account the localization issue. In the add-in code generated by the VS 2005 add-in wizard for VB, notice that the wizard generates this code with localization issues:

    Dim toolsControl As CommandBarControl = menuBarCommandBar.Controls.Item(toolsMenuName)
    Dim toolsPopup As CommandBarPopup = CType(toolsControl, CommandBarPopup)

    where toolsMenuName was localized through the resource manager

    Notice that the "Tools" commandbar belongs to the DTE.CommandBars collection, so I think that there was no need to get the "MenuBar" commandbar, its "Tools" commandbarcontrol and then its associated commandbarpopup, you could get it directly with DTE.CommandBars.Item("Tools"), without localization issues. I don´t know why Microsoft did it that way in the VS 2005 add-in wizard. There are commandbarpopups that don´t belong to the DTE.CommandBars collection (the "View" commandbar comes to mind, because there are two of them and the one of the MenuBar does not belong to that collection)  and therefore in that case the extra step to locate the CommandBarControl is required, but even in this case you can avoid the localization issue rather than using CommandBar.Controls.Item(localizedCaption) using instead this approach: you iterate the CommandBar.Controls collection and for each CommandBarControl try to get its CommandBarPopup (if any). If you get one, the check its Name property against the English name of the command bar that you are looking for. See my article:

    HOWTO: Getting the "View" command bar of Visual Studio .NET from an add-in

    If you or someone from MS think this is wrong and I am missing something, let me know.


    Saturday, June 24, 2006 9:20 AM