"""gui package XXX"""

__revision__ = "$Id: __init__.py,v 1.15 2001/12/07 16:01:33 syt Exp $"

import sys
ENCODING = 'iso-8859-1'

if sys.platform=='win32':
    def unicode_to_gtk(ustring):
        return ustring.encode('utf-8')
else:
    # on non windows platforms, gtk does not expect utf8 strings
    # please correct me if I'm wrong
    def unicode_to_gtk(ustring): 
        if ustring:
            try:
                return ustring.encode(ENCODING)
            except:
                print 'error converting string', ustring
                return ustring
        else:
            return ''
    

def init_gettext():
        # gettext implementation
    try:
        from narval import config
        import os, sys, gettext, locale
        if sys.platform == 'win32':
            os.environ['LC_ALL'] = locale.getdefaultlocale()[0]
        locale_dir = os.path.split(config.__file__)[0]
        t = gettext.translation('Horn',locale_dir)
        global ENCODING
        try:
            from narval.NarvalRC import NarvalRC
            ENCODING = NarvalRC()['encoding']
        except Exception, e:
            import traceback
            traceback.print_exc()
            print e
        t._charset = ENCODING
        t.install(unicode=1)

    except (ImportError,AttributeError,IOError):
        import traceback,__builtin__
        print '***** Horn localisation support error :'
        traceback.print_exc()
        print '***** program will continue running and use english as a default...'
        def gettext(msg):
            # default message should be ascii, which also happens to be UTF-8
            return msg 
        __builtin__.__dict__['_'] = gettext
