Marking translatable strings

Darrell news at dorb.com
Wed Sep 22 13:40:03 EDT 1999


Looked on dejanews and could find your old post. I was interested how you
used this.
All the UserDict approaches have to assume ')s' as the format type.

By changing PyString_Format it was possible to avoid that assumption.
And use things like %(BB).3s

d1={'AA':11}
d2={'BB':'bbbb'}
d3={'CC':33}

s= fmt("%(AA)d %(BB).3s %(CC)d",d1)
print s
s= fmt(s,d2)
print s
s= fmt(s,d3)
print s
######################
11 %(BB).3s %(CC)d
11 bbb %(CC)d
11 bbb 33

Thanks for the comments.
--
--Darrell


Barry A. Warsaw <bwarsaw at cnri.reston.va.us> wrote in message
news:14312.60639.695242.62330 at anthem.cnri.reston.va.us...
> A while back I posted what we use in Mailman:
>
> -------------------- snip snip --------------------
> from UserDict import UserDict
> from types import StringType
>
> class SafeDict(UserDict):
>     """Dictionary which returns a default value for unknown keys.
>     """
>     def __init__(self, d):
>         # optional initial dictionary is a Python 1.5.2-ism.  Do it this
way
>         # for portability
>         UserDict.__init__(self)
>         self.update(d)
>
>     def __getitem__(self, key):
>         try:
>             return self.data[key]
>         except KeyError:
>             if type(key) == StringType:
>                 return '%('+key+')s'
>             else:
>                 return '<Missing key: %s>' % `key`
> -------------------- snip snip --------------------
>
> >>> 'Well %(hello)s there %(name)s' % sd
> 'Well howdy there %(name)s'
>
> Hope that helps,
> -Barry






More information about the Python-list mailing list