示例#1
0
def set_translators():
    global _lang_trans, lcdata
    # To test different translations invoke as
    # CALIBRE_OVERRIDE_LANG=de_DE.utf8 program
    lang = get_lang()
    t = None

    if lang:
        buf = iso639 = None
        mpath = get_lc_messages_path(lang)
        if mpath and os.access(mpath + '.po', os.R_OK):
            from calibre.translations.msgfmt import make
            buf = cStringIO.StringIO()
            try:
                make(mpath + '.po', buf)
            except:
                print(('Failed to compile translations file: %s,'
                       ' ignoring') % (mpath + '.po'))
                buf = None
            else:
                buf = cStringIO.StringIO(buf.getvalue())

        if mpath is not None:
            from zipfile import ZipFile
            with ZipFile(
                    P('localization/locales.zip', allow_user_override=False),
                    'r') as zf:
                if buf is None:
                    buf = cStringIO.StringIO(zf.read(mpath + '/messages.mo'))
                if mpath == 'nds':
                    mpath = 'de'
                isof = mpath + '/iso639.mo'
                try:
                    iso639 = cStringIO.StringIO(zf.read(isof))
                except:
                    pass  # No iso639 translations for this lang
                if buf is not None:
                    try:
                        lcdata = cPickle.loads(
                            zf.read(mpath + '/lcdata.pickle'))
                    except:
                        pass  # No lcdata

        if buf is not None:
            t = GNUTranslations(buf)
            if iso639 is not None:
                iso639 = _lang_trans = GNUTranslations(iso639)
                t.add_fallback(iso639)

    if t is None:
        t = NullTranslations()

    t.install(unicode=True, names=('ngettext', ))
    # Now that we have installed a translator, we have to retranslate the help
    # for the global prefs object as it was instantiated in get_lang(), before
    # the translator was installed.
    from calibre.utils.config_base import prefs
    prefs.retranslate_help()
示例#2
0
def set_translators():
    global _lang_trans, lcdata
    # To test different translations invoke as
    # CALIBRE_OVERRIDE_LANG=de_DE.utf8 program
    lang = get_lang()
    t = None

    if lang:
        buf = iso639 = None
        mpath = get_lc_messages_path(lang)
        if mpath and os.access(mpath + '.po', os.R_OK):
            from calibre.translations.msgfmt import make
            buf = cStringIO.StringIO()
            try:
                make(mpath + '.po', buf)
            except:
                print(('Failed to compile translations file: %s,'
                       ' ignoring') % (mpath + '.po'))
                buf = None
            else:
                buf = cStringIO.StringIO(buf.getvalue())

        if mpath is not None:
            from zipfile import ZipFile
            with ZipFile(
                    P('localization/locales.zip', allow_user_override=False),
                    'r') as zf:
                if buf is None:
                    buf = cStringIO.StringIO(zf.read(mpath + '/messages.mo'))
                if mpath == 'nds':
                    mpath = 'de'
                isof = mpath + '/iso639.mo'
                try:
                    iso639 = cStringIO.StringIO(zf.read(isof))
                except:
                    pass  # No iso639 translations for this lang
                if buf is not None:
                    try:
                        lcdata = cPickle.loads(
                            zf.read(mpath + '/lcdata.pickle'))
                    except:
                        pass  # No lcdata

        if buf is not None:
            t = GNUTranslations(buf)
            if iso639 is not None:
                iso639 = _lang_trans = GNUTranslations(iso639)
                t.add_fallback(iso639)

    if t is None:
        t = NullTranslations()

    t.install(unicode=True, names=('ngettext', ))
    # Now that we have installed a translator, we have to retranslate the help
    # for the global prefs object as it was instantiated in get_lang(), before
    # the translator was installed.
    from calibre.utils.config_base import prefs
    prefs.retranslate_help()
示例#3
0
def load_po(path):
    from calibre.translations.msgfmt import make
    buf = io.StringIO()
    try:
        make(path, buf)
    except Exception:
        print((('Failed to compile translations file: %s, ignoring') % path))
        buf = None
    else:
        buf = io.StringIO(buf.getvalue())
    return buf
示例#4
0
def load_po(path):
    from calibre.translations.msgfmt import make
    buf = cStringIO.StringIO()
    try:
        make(path, buf)
    except Exception:
        print (('Failed to compile translations file: %s, ignoring') % path)
        buf = None
    else:
        buf = cStringIO.StringIO(buf.getvalue())
    return buf
示例#5
0
def set_translators():
    global _lang_trans
    # To test different translations invoke as
    # CALIBRE_OVERRIDE_LANG=de_DE.utf8 program
    lang = get_lang()
    t = None

    if lang:
        buf = iso639 = None
        mpath = get_lc_messages_path(lang)
        if mpath and os.access(mpath+'.po', os.R_OK):
            from calibre.translations.msgfmt import make
            buf = cStringIO.StringIO()
            try:
                make(mpath+'.po', buf)
            except:
                print (('Failed to compile translations file: %s,'
                        ' ignoring')%(mpath+'.po'))
                buf = None
            else:
                buf = cStringIO.StringIO(buf.getvalue())

        if mpath is not None:
            from zipfile import ZipFile
            with ZipFile(P('localization/locales.zip',
                allow_user_override=False), 'r') as zf:
                if buf is None:
                    buf = cStringIO.StringIO(zf.read(mpath + '/messages.mo'))
                if mpath == 'nds':
                    mpath = 'de'
                isof = mpath + '/iso639.mo'
                try:
                    iso639 = cStringIO.StringIO(zf.read(isof))
                except:
                    pass  # No iso639 translations for this lang

        if buf is not None:
            t = GNUTranslations(buf)
            if iso639 is not None:
                iso639 = _lang_trans = GNUTranslations(iso639)
                t.add_fallback(iso639)

    if t is None:
        t = NullTranslations()

    t.install(unicode=True, names=('ngettext',))
示例#6
0
def set_translators():
    # To test different translations invoke as
    # CALIBRE_OVERRIDE_LANG=de_DE.utf8 program
    lang = get_lang()
    t = None

    if lang:
        buf = iso639 = None
        mpath = get_lc_messages_path(lang)
        if mpath and os.access(mpath + '.po', os.R_OK):
            from calibre.translations.msgfmt import make
            buf = cStringIO.StringIO()
            try:
                make(mpath + '.po', buf)
            except:
                print(('Failed to compile translations file: %s,'
                       ' ignoring') % (mpath + '.po'))
                buf = None
            else:
                buf = cStringIO.StringIO(buf.getvalue())

        if mpath is not None:
            from zipfile import ZipFile
            with ZipFile(
                    P('localization/locales.zip', allow_user_override=False),
                    'r') as zf:
                if buf is None:
                    buf = cStringIO.StringIO(zf.read(mpath + '/messages.mo'))
                if mpath == 'nds':
                    mpath = 'de'
                isof = mpath + '/iso639.mo'
                try:
                    iso639 = cStringIO.StringIO(zf.read(isof))
                except:
                    pass  # No iso639 translations for this lang

        if buf is not None:
            t = GNUTranslations(buf)
            if iso639 is not None:
                iso639 = GNUTranslations(iso639)
                t.add_fallback(iso639)

    if t is None:
        t = NullTranslations()

    t.install(unicode=True, names=('ngettext', ))