|
|
Fixing Source Code
OverviewBesides scanning your code to detect internationalization issues, Globalyzer provides several tools and features that you can use to fix the problems. Types of IssuesThe kinds of internationalization issues that Globalyzer can detect include: Embedded Strings -- Think of embedded strings as displayable text, or text that end users will see when they use your application, such as error messages, button names, or tool tips. When the scanner detects embedded strings in your source, they are added to the Scan Results table and displayed when you select Embedded Strings from the Results dropdown. Unsafe Methods -- These are methods or functions that could pose an internationalization problem. For example, methods that produce date or currency strings could be an issue if they do not support the current locale's preference. Methods that sort text pose another kind of problem since text may sort differently for different languages. Click here for more information on unsafe methods. Click here for information on using the Quick Summary Report to link to detailed information on your detected unsafe methods. Static File References -- The problem with image and other static file references is similar to that of embedded text, in that the data may need to change for each locale. For example, images may contain translatable text; a style sheet file may have font settings that would need to be adjusted based on locale. In these cases, the static file would need to be duplicated, localized, stored in locale-sensitive directories and then retrieved dynamically based on locale. Globalyzer helps you to identify and locate source code references to these locale-sensitive static files. General Patterns -- Globalyzer lets you define custom string patterns that the scanner will look for. For instance, when scanning HTML code, you might define a general pattern to detect instances of "value=". Fixing IssuesAfter you perform a scan, the issues that were detected appear in the Scan Results table. Typically, you sort and filter the table before fixing source code. Click here for more information on using the Scan Results table. Double-click on a line in the Scan Results table to open the corresponding source file and highlight the Issue. Depending on the type of issue, you have several possible ways to fix it.
Using the Quick SummaryAfter you scan code, a summary containing information about the scan is generated. This summary is displayed in the Quick Summary pane in the lower left of the Globalyzer main window.
The summary displayed in the Quick Summary pane contains the following categories of information:
Tip: The Unsafe Method section contains links that allow you to view detailed information about the method. This information can be useful in assisting you to re-code or replace the methods. Configuring Globalyzer to Fix Source CodeBefore you use Globalyzer to fix source code, you need to configure the Project Properties. To bring up the Project Properties dialog box, do one of the following:
In the Project Properties dialog, click Fixing under your scan's name on the left. On this sub-screen, you can configure the settings in the String Externalization Resource Files sections. For detailed information on how to use all the options in the Project Properties dialog, click here. Editing Source Code DirectlyWhen you double-click an issue in the Scan Results table, the source file containing the issue is automatically opened and the issue is highlighted. You edit text in the Source File Editor just as you'd expect if you've used a typical text editor. The editor provides basic editing functions, such as copy, cut, and paste. To save a source file, use the Save or Save As menu functions or buttons in the toolbar. Externalizing an Embedded StringExternalizing refers to the process of removing embedded strings from source code and placing them into a resource file. Globalyzer's String Externalization feature lets you automatically replace embedded text (such as hardcoded button and menu names) with a method call to retrieve the text from a resource file. This feature automates the tedious process of typing a retrieval method, assigning a key, and editing a resource file for each instance of display text. When you externalize a string, the string is automatically removed from the source file, assigned a unique key, placed in a resource file, and replaced in the source file by a method designed to recall the string from the resource file. Managing the Resource FilesThe resource files are placed, by default, in the same directory you set as your Base Directory when you created your Project. You can change this in the Fixing pane of your Project Properties. In the Fixing pane, you can also specify several settings that affect how resource files are handled. Some of the key ones are: Resource File Type -- You can set the type to the kind of format you need. There are several options, depending on the Scan's associated programming language. Two common resource file types are .properties and .resx. The first tells Globalyzer to create a Java style resource file, and the second, a .NET resource file. Resource File Frequency -- If set to Project, one resource file is created for the entire project. If set to Source File, a new, uniquely named resource file is created for each source file that contains externalized text. Resource File Name -- Lets you set the name of a Project resource file. Some Resource File types can group externalized strings by file name, some Resource File types are able to append externalized strings to an existing resource file. The following table lists the Resource File types that can group and/or append externalized strings:
In the case where both grouping and appending are possible, select Edit -> Preferences to control how you want strings added to the resource file. For more information on Preferences, click here. For more information on Project Properties, click here. Simple ExampleIn Java, the line:
in a file named Catalog.java will look something like this (depending on how Globalyzer is configured) after the string "Cancel" is externalized:
Notice that the text has been replaced by a method call that takes a string keyword. In the Java properties file, the following line is added:
Notice that the name/value pair consists of the automatically generated keyword and the actual display text. Translators will then create locale-specific properties files and translate the English display text. To externalize a string, make sure the string is highlighted, then do one of the following:
Note: After you externalize a string, the source file is automatically saved and the issue's status updated. Externalizing and Editing a StringSometimes you need to do more than simply externalize a single string. Often display text is composed of concatenated strings that contain variables that are plugged in at runtime. In this case, the Externalize and Edit String function is handy. It brings up a dialog box that lets you edit the string before you externalize it. For more information on this dialog, including an example, click here. To externalize and edit a string, make sure the entire block of concatenated strings are highlighted, then do one of the following:
Note: Once externalized, the entry will be removed from the Active Scan Results table. If you have unchecked Automatically Rescan After String Externalization in the Edit=>Preferences dialog, then Globalyzer will set the status to Resolved until your next scan. Click View Status and check the box for Resolved to see strings that were externalized since your last scan. Externalizing Multiple StringsThis feature greatly speeds up the string externalization process. To externalize multiple strings, select multiple rows containing Embedded Strings in the Scan Results table, then do one of the following:
Warning: When you externalize strings in Single or Batch mode, the affected source files are automatically saved. Be sure to check that the string is a valid string that the user will see before you externalize. You can do this by double-clicking on the string in the Scan Results table to open the corresponding source code file. In addition to ensuring that the string is fully-selected in the source file, you can use the context of the code to verify that it is a string that will be displayed to an end user, and therefore requires string externalization. Note: If a string is several lines long, Globalyzer will display an error and will not include the string in the batch externalization process. To externalize these long strings, use Single String Externalization, but be sure to check that the entire string is selected in the source file before clicking the Plunger button. Inserting Externalized String CommentsThe Externalized String Comment is a text string that can be inserted into your source code right after you externalize a single string. The string you externalized is appended to the end of this comment. For example: // To paste an Externalized String Comment into a source file, do one of the following, right after you've used Globalyzer to externalize a string:
The Externalized String Comment will be inserted right above the current code line. Note: The Externalized String Comment function is only enabled immediately after you externalize a string, and is not available for Batch Externalization. You can change the default text associated with the Externalized String Comment
in the Project Properties dialog box.
Click the Project Properties button
|