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. Locale-Sensitive 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 locale-sensitive methods. Click here for information on using the Quick Summary Report to link to detailed information on your detected locale-sensitive 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.
Ignoring Issues and LinesSometimes there are active issues reported that you know aren't really issues, and it may be impossible to modify the rule set to filter them. As described earlier, you can select these issues from Scan Results and change their status. Changing the status in this way is only temporary, however. If the rule set or source file is modified, those status settings may be lost. But if you update these issues to Dashboard as False Positive, you could reload Dashboard False Positives to any Globalyzer Workbench later. Another permanent way to ignore these issues is to insert comments telling Globalyzer to ignore these issues. As described earlier, this can be done one line at a time from the source file by right clicking and selecting an ignore comment to insert via Fix Code. A more robust way to insert ignore comments is via Scan Results. You can select one or multiple issues in Scan Results, right click, and select Fix Code=>Ignore This Issue or Fix Code=>Ignore This Line. Globalyzer will then add a special comment at the end of each code line, telling it to ignore this issue or to ignore all the issues found on this line. In the screen capture below, the user wants to ignore the embedded string "US" in the file ExampleMain.java:
Ignore This Line is available for all Scan Types: Embedded Strings, Locale-Sensitive Methods, Static File References, and General Patterns. Ignore This Issue is only available for Embedded Strings. If a source line contains two embedded string issues and one locale-sensitive method issue, choosing to ignore one string issue will leave the other string, as well as the locale-sensitive method, active. If instead the line is ignored, then both strings will be removed from the Embedded Strings Scan Results and the method will be removed from the Locale-Sensitive Method Scan Results. Updating Issues to Dashboard as False PositivesUpdate Issues to Dashboard as False Positives make it possible for Globalyzer to synchronize false positives across the suite. It is available for all Scan Types: Embedded Strings, Locale-Sensitive Methods, Static File References, and General Patterns. Right click on selected issues and select Update to Dashboard as False Positive from dropdown menu, those issues status will be changed to dfp if update successful. And you could reload Dashboard False Positives to any Globalyzer Workbench later. Right-click on the scan results or click Project menu and select Reload Dashboard False Positives from the dropdown menu to reload the dfp status for the currently selected project. See the confirm information in Console. Using the All Predicted Scan SummaryAfter you scan code, a summary containing information about the scan is generated. This summary is displayed in the Predicted Active Scan Summary view in the lower left of the Globalyzer main window.
The summary displayed in the All Predicted Scan Summary view contains the following categories of information:
Tip: The Locale-Sensitive 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 scans.
Select the scan you want to configure and click Modify.... Click Next until you reach Globalyzer Scan I18n Settings. This is where you can configure the settings in the String Externalization Resource Files sections. 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 Editor view. The editor provides powerful editing functions. You may want to add plugins depending on your software language and your application. 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 Globalyzer Scan I18n Settings page of your Manage Scans wizard. In the Globalyzer Scan I18n Settings 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 Windows=>Preferences=>Globalyzer to control how you want strings added to the resource file. For more information on Preferences, 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 Concatenated StringsGlobalyzer now detects when strings are part of a string concatenation. Concatenated strings need to be refactored before being externalized. As Globalyzer scans your source code, it sets a detected string's Scan Results priority to the new string concatenation priority 'C' when at least one of the following conditions are true:
For example, given the following code:
Most programming languages support some kind of parameter substitution. For example,
in Java the above code could be refactored using After refactoring, rescan the file. The new string, "{0} is {1} years old." is detected and can now be externalized. The translator will know the proper translation given the full context of the string. Note: Once externalized, the entry will be removed from the Active Scan Results table. 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:
Batch externalization can also be done from the Project Explorer view. Select files and/or directories from the Project Explorer, right click, and select Externalize Strings from ... . All active embedded strings from the selected files/directories that are displayed on the current page of Scan Results will be externalized. 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 Externalize button. Inserting Externalized String CommentsThe Externalized String Comment is a text string that can be inserted into your source code when you externalize a string. The string you externalized is appended to the end of this comment.
For example: //
To configure Globalyzer to insert an Externalized String Comment into a source file when a string is externalized, check Automatically Insert Externalized String Comment in the Windows > Preferences > Globalyzer dialog. The Externalized String Comment will be inserted right above the current code line. You can change the default text associated with the Externalized String Comment. Click the Scan > Manage Scans ... menu item. In the wizard, go to the Globalyzer Scan I18n Settings page to find the Externalized String Comment.
|