[Python-Dev] Replacement for print in Python 3.0

Bob Ippolito bob at redivi.com
Wed Sep 7 21:07:07 CEST 2005

On Sep 7, 2005, at 7:11 AM, Guido van Rossum wrote:

> On 9/7/05, Barry Warsaw <barry at python.org> wrote:
>> On Wed, 2005-09-07 at 05:23, Stephen J. Turnbull wrote:
>>> But print-ng looks
>>> like becoming the OOWTDI for a lot of applications.  IMO it's  
>>> just too
>>> early to give up on print-ng becoming the one obvious way to do  
>>> it for
>>> a lot of i18n apps, too.
>> +1.  I have a gut feeling that we can make it easy for  
>> monolinguists to
>> use printng without caring or even knowing about i18n, but also  
>> make it
>> relatively painless to integrate i18n into an application or library.
>> However I haven't had time to really explore that idea.
> I certainly didn't mean to rule that out. But I doubt that the only
> text to be i18n'd will occur in printf format strings. (In fact, I
> expect that few apps requiring i18n will be so primitive as to use
> *any* printf calls at all.)

In my experience, implementing i18n with *existing* Python (2.3 at  
the time) features was not a big deal.

We used a translation company to translate all of the strings, and  
they had no problem with normal Python %(format)s strings.  We gave  
it to them in an excel spreadsheet, and converted it to Apple  
".strings" style files (which we parse directly in the Windows  
version).  Granted, we highlighted all of the "%(format)s" in the  
spreadsheet so it was clear what should be preserved.

It worked like this:

def _(stringToBeLocalized):
     return anAppropriateString

and all formatted strings in the code looked like this:
_('default english string %(variable)s') % someDict

from real world production code:

_(u'Installing this software requires %(requiredSpace)s of space.\n 
\nYou have selected to install this software on the iPod "%(podName) 
s" (%(totalFree)s available)')  % {
     u'requiredSpace': self.installer.getRequiredFreeDiskSpace(),
     u'podName': self.podName,
     u'totalFree': space,

I was also able to easily automate the process of extracting strings  
to create that spreadsheet.  I wrote a simple script that parsed the  
Python modules and looked for function calls of "_" whose only  
argument was a constant string.  Worked great, and it was easy to write.


More information about the Python-Dev mailing list