Add Resource String Visual Studio Add-In


The Add Resource String Visual Studio Add-In exists as a recognition of the fact that the average brain has an eight-item stack. On average, you can hold eight new items in your working storage. If you need to remember a ninth item, either you have to commit something to longer-term storage or one item is replaced. It's a sweeping generalization, and the number 8 varies from developer to developer, but the essential idea is solid. When you're writing code, you're writing code. Anything else is a distraction. Mistakes are made when distractions occur (ask anyone with kids). Having to add a string to a resource is something that you'll do "later." And as we all know, "later" sometimes means when it is reported by the test team. Adding a resource string is often postponed when it means having to update more than one resource file because you are trying to maintain multiple languages. The Add Resource String Add-In makes this process easier and helps reduce the number of incomplete or incorrect resource entries. In Visual Studio's Text Editor, type something like this:

 Text = resourceManager.GetString("ProductName"); 


Or if you are using strongly typed resources, type something like this (where GlobalResources is the name of your strongly typed resource class):

 Text = GlobalResources.ProductName; 


For best results, place the cursor at the end of the entry label you want to add (i.e., ProductName, in this example) so that the add-in can guess the resource key. Press Alt+X, Alt+R (R is for resource and, with a leap of imagination, X is for add); the Add Resource String dialog box is displayed (see Figure 10.10).

Figure 10.10. Add Resource String Dialog Box


The add-in attempts to guess the name of the resource (C:\Books\I18N\Tests\VS2003\AddResourceStringTest\Form1Resources.resx, in this example) from the name of the open file, and also guesses the name of the key from either the text selected in the Text Editor or behind the cursor position if no text is selected. Enter a value for the resource string and click OK. The resource string is added to the resource specified in the dialog box. The Languages button brings up the same dialog as used by the Resource Administrator in Figure 10.2 and enables you to specify which languages to maintain. If you specify one or more languages, the resource string is added to those resources. If you check the Automatic Translation check box, those entries are automatically translated. The Translators button brings up the same dialog as used by the Resource Administrator in Figure 10.6, and allows you to enable or disable the translators used to perform automatic translation.

Your settings for Automatic Translation, Invariant Language, and Target Languages are all saved in the application's solution file so that you need to set these values only once for each solution.

Installing the Add-In in Visual Studio 2005

Visual Studio 2005's add-in mechanism differs from Visual Studio 2003's add-in mechanism. To install an add-in in Visual Studio 2005, you need to build the add-in assembly, copy the add-in XML file to Visual Studio 2005's add-in folder, and change the reference in the add-in file to the location of the built assembly. The add-in XML file is in the same folder as the solution file (AddResourceString.sln) and is called AddResourceString.AddIn. Copy it to <Documents>\<User>\Application Data\Microsoft\MSEnvShared\Addins. Open the add-in XML file and change the <assembly> tag to the location of the built assembly:

 <Assembly>C:\Books\I18N\Source\VS2005\ResourceAdministration\ AddResourceString\bin\AddResourceString.dll</Assembly> 


In Visual Studio 2005, select Tools, Add-In Manager...; check the check box next to Add Resource String and click OK. To assign a keystroke combination to the add-in, select Tools, Options (see Figure 10.11); expand the Environment node in the TreeView; select Keyboard; enter AddResourceString in the "Show commands containing:" text box; select "Text Editor" in the "Use new shortcut in" combo box; press Alt+X, Alt +R in the "Press shortcut keys" text box; click on the Assign button; and click OK.

Figure 10.11. Assigning a Keystroke to an Add-In


Installing the Add-In in Visual Studio 2003

Visual Studio 2003's add-in architecture is based on COM and requires COM Registry entries. Fortunately, the Add Resource String Add-In comes with an add-in setup project to perform the necessary steps. Build the AddResourceStringSetup project and, in Solution Explorer, right-click the project, select Install, and follow the steps in the wizard. The add-in automatically creates an Add Resource String menu item and assigns the Alt+X, Alt+R keystroke combination to the add resource string command.




.NET Internationalization(c) The Developer's Guide to Building Global Windows and Web Applications
.NET Internationalization: The Developers Guide to Building Global Windows and Web Applications
ISBN: 0321341384
EAN: 2147483647
Year: 2006
Pages: 213

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net