Hard Coded Strings

When preparing your application for localization you’ll need to deal with hard coded strings in source files.
These hard coded strings are usually either converted to a resourcestring, a constant or marked as unlocalized.

ModelMaker Code Explorer comes with an extensive set of tools to help manage locating and converting hard coded strings in Delphi Pascal source files:

  • Convert string at editor cursor to resource string or constant: simply press Ctrl+Alt+R to convert a string to a resourcestring. Similar, press Ctrl+Alt+N to convert a string to a constant.
  • Live Metrics™ hints are displayed if a unit contains hard coded strings.
  • Module String Conversion Wizard: scan entire file for hard code string and allows mass extraction and conversion.
  • Multi File String Wizard: used to manage and scan lists of source files for hard coded strings
  • Extensive Options to control string scanning and conversion.
  • Command Line string scanner to include in automated build processes.

Code Explorer helps you to make your software localizable by converting hard coded strings to resourcestrings.
The next step is to use a software localization tool.


Module string conversion wizard

This wizard scans an entire source file for hard coded strings and let you do a mass conversion to resourcestrings and/or constants.
The scanner uses regular expression and string length based filters. Clicking a string in the list scrolls the IDE editor to the line containing the
(first occurrence of the) string.

After clicking Convert, strings are replaced with the identifiers and a resourcestring and / or const section is inserted defining the identifiers and strings.
In addition to converting a string to resourcestring or const, the wizard can mark a string as unlocalized. It does this by appending a user definable //-style comment to the line containing the string – defaults to // do not localize

The wizard is case-sensitive and treats ‘Hello’ and ‘hello’ as two different strings.


String conversion and scanner options

The options below allow adjusting the string scanner as used by the module string wizard and multi file string wizards.
These include filters to that skip strings less than a minimum length.
A line filter lets you skip lines containing certain phrases such as “Assert” or “// do not localize”.
Similar a string filter can be defined to filter on the actual string rather than the entire source line.
Both filters use regular expressions.


Multi File String Wizard

The Multi File String Wizard helps in scanning, analyzing, extracting and converting hard coded strings in a list of files.
For the Delphi IDE only: the file list window is dockable. Operations on multiple selected files include:

  • Scan and Filter: scans the files for hard coded strings and removes files from the list that do not contain hard coded strings.
    The number of (unique) strings is displayed per file.
  • Run Module Resource String Wizard to view and convert hard coded strings.
  • Load File List from a text file, for example generated with a dir *.pas /b/s > filelist.txt
  • Load Files in Active IDE Project.
  • Load Files using an open dialog.
  • Save File List to a text file.


Command Line hard coded string scanner utility

A command line utility MMXStrScan.exe is available for integration with automated build processes.
It can for example be used to verify a file does not contain hard coded strings before building or file check in.
The ModelMaker Code Explorer string filter settings are used to scan one or more files for hard coded strings.
Output is an exitcode and / or a output text file.