[PyQt] Issues with PyKDE4 and i18n API

Chusslove Illich caslav.ilic at gmx.net
Fri Apr 18 21:29:25 BST 2008


KDE 4 i18n API, with intended usage patterns, is given here:

http://api.kde.org/4.0-api/kdelibs-apidocs/kdecore/html/classKLocalizedString.html

For the same semantics to be fully supported by the Python bindings, some
special care is needed.

First, looking at the pykde4/sip/kdecore/klocalizedstring.sip, most of the
number-consuming subs() methods to KLocalizedString appear to be ignored,
only the one for qulonglong is enabled. The behavior of KLocalizedString
crucially depends on that numbers are sent to it as appropriate C++ number
types (int or double), not converted to strings, as it has been observed to
happen right now with Python numbers.

Second, C++ API has a bunch of template i18n* calls, as a shorthand
counterparts to more verbose ki18n* calls. E.g. these two are equivalent:

  QString s1 = ki18n("Foo %1 bar %2.").subs(arg1).subs(arg2).toString();
  QString s2 = i18n("Foo %1 bar %2.", arg1, arg2);

I have pretty much no knowledge about how the wrapping is done, and what can
be done with templates, but one could provide same i18n* calls in pure
Python:

  def i18n_helper (base_args, subs_args):
      kstr = ki18n(*base_args)
      for arg in subs_args:
          kstr = kstr.subs(arg)
      return kstr.toString()

  def i18n (*args):
      return i18n_helper(args[:1], args[1:])

  def i18nc (*args):
      return i18n_helper(args[:2], args[2:])

  def i18np (*args):
      return i18n_helper(args[:2], args[2:])

  def i18ncp (*args):
      return i18n_helper(args[:3], args[3:])

which is exactly what the C++ templates do (just in an ugly way).

-- 
Chusslove Illich (Часлав Илић)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part.
Url : http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20080418/fce05dad/attachment.bin


More information about the PyQt mailing list