Modifying the R code

To enable the translation mechanism, you must modify the R code that generates your output--for example, the R source code that implements an extension command. First, however, 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.

To enable the translation mechanism, you must include a call to the R bindtextdomain function to associate a name--called the domain name--with a set of translation files. The function takes two arguments: the domain name, and the location where the associated translation files reside. If you are creating translations for an extension command implemented in R, then it is recommended to use the name of the extension command as the domain name. For multi-word extension command names, replace the spaces with underscores. For example:

bindtextdomain(domain="MYORG_MYSTAT",dirname=paste(spsspkg.GetStatisticsPath(),
               "extensions/MYORG_MYSTAT/lang",sep=""))
  • The domain name in this example is "MYORG_MYSTAT", and it will represent translations for an extension command named MYORG MYSTAT.
  • The dirname argument specifies the path to the directory containing the translation files. In this example, translation files are located in the extensions/MYORG_MYSTAT/lang directory under the location where IBM® SPSS® Statistics is installed. See the topic Installing the mo files for more information.

In addition to the bindtextdomain function, you must enclose each translatable string in a call to the R gettext, ngettext, or gettextf function. For example:

gettext("ERROR:",domain="MYORG_MYSTAT")
  • The arguments to gettext are the untranslated string--in this case, "ERROR:"--and the domain name specified in the bindtextdomain function. The function will fetch the translation, if available, when the statement containing the string is executed.

Calls to the spsspkg.StartProcedure function should use the form spsspkg.StartProcedure(pName,omsId) where pName is the translatable name associated with output from the procedure and omsId is the language invariant OMS command identifier associated with the procedure. For example:

spsspkg.StartProcedure(gettext("Demo",domain="MYORG_MYSTAT"),"demoId")