Internationalization and localization tools


Fixing Source Code

 

Overview

Besides scanning your code to detect internationalization issues, Globalyzer provides several tools and features that you can use to fix the problems.

Types of Issues

The 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 Issues

After 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.

  • Fixing Embedded String Issues -- If the issue is an embedded string, the simplest way to fix it is to externalize it. The techniques for externalizing code are described in the following sections.
  • Fixing Unsafe Methods, Static Files References, and General Patterns -- To fix any of these issues, you must directly edit the source file using Globalyzer's Source Files editor or another editing tool.

Using the Quick Summary

After 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:

  • a summary of the number of lines and files scanned
  • static file references that were detected
  • pattern matches that were detected
  • unsafe methods that were detected
  • embedded strings that were detected

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 Code

Before 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:

Select Edit=>Project Properties from the Menubar.

Click the Project Properties button in the Toolbar.

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 Directly

When 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 String

Externalizing 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 Files

The 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:

.js .po .properties .rc   Can group by source file and append
.msg .resx .xml   Can only append

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 Example

In Java, the line:

JButton myButton = new JButton("Cancel");

in a file named Catalog.java will look something like this (depending on how Globalyzer is configured) after the string "Cancel" is externalized:

JButton myButton = new JButton(myResource.getString("CATA_CANCEL_1");

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:

CATA_CANCEL_1=Cancel

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:

Click the Externalize String button in the Toolbar.

Right-click over the selected string in the Source Files pane and choose Fix Code=>Externalize String from the menu.

Press Ctrl-E.

Select Fix Code=>Externalize String from the Menubar.

Note: After you externalize a string, the source file is automatically saved and the issue's status updated.

Externalizing and Editing a String

Sometimes 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:

Right-click over the selected string in the Source Files pane and choose Fix Code=>Externalize and Edit String from the menu.

Press Ctrl-Shift-E.

Select Fix Code=>Externalize and Edit String from the Menubar.

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 Strings

This 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:

Click the Externalize Selected Strings button in the Toolbar.

Right-click over the Scan Results table and pick Fix Code=>Externalize Selected Strings.

Select Fix Code=>Externalize Selected Strings from the Main menu.


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 Comments

The 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: //GLOBALYZER_EXTERNALIZED_TEXT: Cancel

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:

Select the Paste Comment button on the Toolbar. This brings up the Insert Comment dialog box, where you choose Externalized String Comment. For information on this dialog, click here.

Select Fix Code=> Externalized String Comment from the Menubar.

In the Source Files pane, right-click on the line where the string externalization took place and select Fix Code=>Externalized String Comment from the menu.

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 or select Edit=>Project Properties. In the dialog, click Fixing under your scan's name to find the Externalized String Comment. For more information on modifying Globalyzer's Externalized String comment, click here.

 

 User's Guide Contents

 

Lingoport internationalization and localization services and software