Localize menu commands
Applies to: Visual Studio Visual Studio for Mac
Note
This article applies to Visual Studio 2017. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here
You can provide localized text for menu and toolbar commands by creating localized .vsct files and localized .resx files for your VSPackage, and then updating the project files to incorporate the changes.
For information about how to localize the installation experience, see Localize VSIX packages.
Localize command names
In VSPackages, menu commands and toolbar buttons are defined in the .vsct file.
In Solution Explorer, change the name of the .vsct file from filename.vsct to filename.en-US.vsct.
Make a copy of filename.en-US.vsct for each localized language.
Name each copy filename.{Locale}.vsct, where {Locale} is a particular culture name. For a list of culture name values, see Locale IDs assigned by Microsoft.
These filename.Locale.vsct files will contain the localized menu text for your package.
Open each filename.Locale.vsct file to localize the text.
Modify the ButtonText element values as appropriate for the particular language.
If you will provide localized icons, modify the Bitmap values to point to the target files.
The following example shows English and Spanish button text for a command to open a Family Tree Explorer tool window.
[FamilyTree.en-US.vsct]
<Button guid="guidLocalizedPackageCmdSet" id="cmdidFamilyTree" priority="0x0100" type="Button"> <Parent guid="guidSHLMainMenu" id="IDG_VS_WNDO_OTRWNDWS1"/> <Icon guid="guidImages" id="bmpPic2" /> <Strings> <CommandName>cmdidFamilyTree</CommandName> <ButtonText>Family Tree Explorer</ButtonText> </Strings> </Button>
[FamilyTree.es-ES.vsct]
<Button guid="guidLocalizedPackageCmdSet" id="cmdidFamilyTree" priority="0x0100" type="Button"> <Parent guid="guidSHLMainMenu" id="IDG_VS_WNDO_OTRWNDWS1"/> <Icon guid="guidImages" id="bmpPic2" /> <Strings> <CommandName>cmdidFamilyTree</CommandName> <ButtonText>Explorar el arbol genealogico</ButtonText> </Strings> </Button>
Localize other text resources
Text resources other than command names are defined in resource (.resx) files.
Rename VSPackage.resx to VSPackage.en-US.resx.
Make a copy of the VSPackage.en-US.resx file for each localized language.
Name each copy VSPackage.{Locale}.resx, where {Locale} is a particular culture name.
Rename Resources.resx to Resources.en-US.resx.
Make a copy of the Resources.en-US.resx file for each localized language.
Name each copy Resources.{Locale}.resx, where {Locale} is a particular culture name.
Open each .resx file to modify the string values as appropriate for the particular language and culture. The following example shows the localized resource definition for the title bar of a tool window.
[Resources.en-US.resx]
<data name="ToolWindowTitle" xml:space="preserve"> <value>Family Tree Explorer</value> </data>
[Resources.es-ES.resx]
<data name="ToolWindowTitle" xml:space="preserve"> <value>Explorador del arbol genealogico</value> </data>
Incorporate localized resources into the project
You must modify the assemblyinfo.cs file and the project file to incorporate the localized resources.
From the Properties node in Solution Explorer, open assemblyinfo.cs or assemblyinfo.vb in the editor.
Add the following entry.
[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
This sets US English as the default language.
Unload the project.
Open the project file in the editor.
In the root
Project
element, add aPropertyGroup
element with aUICulture
element that matches your default language.<PropertyGroup> <UICulture>en-US</UICulture> </PropertyGroup>
This sets US English as the default UI culture for Windows Presentation Foundation (WPF) controls.
Locate the
ItemGroup
element that containsEmbeddedResource
elements.In the
EmbeddedResource
element that calls VSPackage.en-US.resx, replace theManifestResourceName
element with aLogicalName
element that's set toVSPackage.en-US.Resources
, as follows:<EmbeddedResource Include="VSPackage.en-US.resx"> <MergeWithCTO>true</MergeWithCTO> <LogicalName>VSPackage.en-US.Resources</LogicalName> </EmbeddedResource>
For each localized language, copy the
EmbeddedResource
element forVsPackage.en-US
, and set the Include attribute and LogicalName element of the copy to the target locale.To each localized
VSCTCompile
element, add aResourceName
element that points toMenus.ctmenu
, as shown in the following example:<ItemGroup> <VSCTCompile Include="LocalizedPackage.es-ES.vsct"> <ResourceName>Menus.ctmenu</ResourceName> </VSCTCompile> </ItemGroup>
Save the project file and reload the project.
Build the project.
This creates a main assembly, and resource assemblies for each language. For information on localizing the deployment process, see Localize VSIX packages