Modifying the Python code

First, ensure that the text to be translated is in a reasonable form for translation.

  • Do not build up text by combining fragments of text in code. This makes it impossible to rearrange the text according to the grammar of the target languages and makes it difficult for translators to understand the context of the strings.
  • Avoid using multiple parameters in a string. Translators may need to change the parameter order.
  • Avoid the use of abbreviations and colloquialisms that are difficult to translate.

Enclose each translatable string in a call to the underscore function "_". For example:

_("File not found: %s") % filespec

The _ function will fetch the translation, if available, when the statement containing the string is executed. The following limitations apply:

  • Never pass an empty string as the argument to _, i.e., _(""). This will damage the translation mechanism.
  • Do not use the underscore function in static text such as class variables. The _ function is defined dynamically.
  • The _ function, as defined in the extension module, always returns Unicode text even if IBM® SPSS® Statistics is running in code page mode. If there are text parameters in the string as in the example above, the parameter should be in Unicode. The automatic conversion used in the parameter substitution logic will fail if the parameter text contains any extended characters. One way to resolve this is as follows, assuming that the locale module has been imported.
if not isinstance(filespec, unicode):
   filespec = unicode(filespec, locale.getlocale()[1])
   _("File not found: %s") % filespec

Note: There is a conflict between the definition of the _ function as used by the Python modules (pygettext and gettext) that handle translations, and the automatic assignment of interactively generated expression values to the variable _. In order to resolve this, the translation initialization code in the extension module disables this assignment.

Calls to the spss.StartProcedure function (or the spss.Procedure class) should use the form spss.StartProcedure(procedureName,omsIdentifier) where procedureName is the translatable name associated with output from the procedure and omsIdentifier is the language invariant OMS command identifier associated with the procedure. For example:

spss.StartProcedure(_("Demo"),"demoId")