[I18n-sig] JapaneseCodecs 1.4.8 released

Walter Drwald walter@livinglogic.de
Fri, 06 Sep 2002 12:24:53 +0200

Martin v. Loewis wrote:

> Tamito KAJIYAMA <kajiyama@grad.sccs.chukyo-u.ac.jp> writes:
 > [...]
>>Sorry, I not sure I've got the picture of what transliteration
>>support would do.  Transliteration support is meant to solve
>>interoperability problems due to differences among vendor-
>>specific mappings, right?
> No. In general, transliteration adds one-way mappings, to allow
> mapping a larger subset of Unicode to the target mapping. For example,
> "" is not supported in ASCII, but a common transliteration (for
> German) is to write "oe". So, u"\u00f6".encode("ascii") raises a
> UnicodeError, where u"\u00f6".encode("ascii//translit-german") might
> return "oe" (this is not implemented in Python).

But it's simple to implement as an PEP 293 error handling callback:

# -*- coding: iso-8859-1 -*-
import codecs

translit_german_map = {
    ord(u""): u"oe",
    ord(u""): u"ae",
    ord(u""): u"ue",
    ord(u""): u"ss"

def translit_german(exc):
    if isinstance(exc, UnicodeEncodeError):
       return (exc.object[exc.start:exc.end]. \
          translate(translit_german_map), exc.end)
       raise TypeError("Don't know how to handle %r" % exc)

codecs.register_error("translit-german", translit_german)

u"-----".encode("ascii", "translit-german")

Could transliteration for the JapaneseCodecs be handled
in a similar way?

    Walter Drwald