SPSS Statistics

 View Only



LinkedIn Share on LinkedIn

Translating IBM SPSS Statistics Python Extension Commands

By Archive User posted Tue January 26, 2010 06:31 PM

  


The Python language includes a general mechanism facilitating translation of text in Python code.  The newest version of extension.py, the module that facilitates creating extension commands, exploits this to make output translation really simple.




You can read all the details in the recently revised article on SPSS Developer Central on creating extension commands, but here is the short version.  The new version of extension.py, 1.4.0, will be in IBM SPSS Statistics version 19, but you can use it now with version 17 or 18.



 



Even without doing any translation, you will see a difference in the output from an extension command.  With previous versions of extension.py, exceptions raised in the implementation code for an extension command result simply in a printed message.  With the new version, these are automatically converted to a Warnings pivot table.



To set up for a translation, you need to do only a few things.




  • Wrap each translatable string in the "_" function.  E.g.,

    _("This is a translatable message")


  • Use the standard Python gettext tool to extract these strings and create a POT file of translatable strings


  • Translate, creating a .po file for each supported language


  • Install the compiled .po files (.mo files produced by msgfmt) in a certain directory structure



If you want to support older versions of extension.py, you need also to add a few lines of code in your Run function to ensure that the _ function is defined for older versions.



The translations will be used automatically according to the Statistics output language.  You can also translate custom dialog boxes, and they will synchronize with the Statistics user interface language.



There are a few technical details that you should consider that are explained in the article I mentioned.  But basically, that's it.



R code uses a similar translation mechanism, but translation is harder, because often the output text comes from R code outside your control, and the R equivalent of extension.py does not have the extra translation support at this time.  Dialog translation, though, is done in the same way.



While ideally, the translations would cover all of the standard Statistics languages, if there is no translation for a particular language, the output and dialog fall back to the untranslated text.








#extensions
#Programmability
#python
#SPSSStatistics
0 comments
5 views

Permalink