Example #1
0
def install_gettext():
    """ Initialize gettext with the correct directory that contains
    MComix translations. This has to be done before any calls to gettext.gettext
    have been made to ensure all strings are actually translated. """

    # Add the sources' base directory to PATH to allow development without
    # explicitly installing the package.
    sys.path.append(constants.BASE_PATH)

    # Initialize default locale
    locale.setlocale(locale.LC_ALL, '')

    if preferences.prefs['language'] != 'auto':
        lang_identifiers = [preferences.prefs['language']]
    else:
        # Get the user's current locale
        code = portability.get_default_locale()
        lang_identifiers = gettext._expand_lang(code)

    domain = constants.APPNAME.lower()
    translation = gettext.NullTranslations()

    # Search for .mo files manually, since gettext doesn't support setuptools/pkg_resources.
    for lang in lang_identifiers:
        resource = os.path.join(lang, 'LC_MESSAGES', '%s.mo' % domain)
        if pkg_resources.resource_exists('mcomix.messages', resource):
            translation = gettext.GNUTranslations(
                pkg_resources.resource_stream('mcomix.messages', resource))
            break

    translation.install(unicode=True)

    global _translation
    _translation = translation
Example #2
0
File: i18n.py Project: Gosha/mcomix
def install_gettext():
    """ Initialize gettext with the correct directory that contains
    MComix translations. This has to be done before any calls to gettext.gettext
    have been made to ensure all strings are actually translated. """

    # Add the sources' base directory to PATH to allow development without
    # explicitly installing the package.
    sys.path.append(constants.BASE_PATH)

    # Initialize default locale
    locale.setlocale(locale.LC_ALL, '')

    if preferences.prefs['language'] != 'auto':
        lang_identifiers = [ preferences.prefs['language'] ]
    else:
        # Get the user's current locale
        code = portability.get_default_locale()
        lang_identifiers = gettext._expand_lang(code)

    domain = constants.APPNAME.lower()
    translation = gettext.NullTranslations()

    # Search for .mo files manually, since gettext doesn't support setuptools/pkg_resources.
    for lang in lang_identifiers:
        resource = os.path.join(lang, 'LC_MESSAGES', '%s.mo' % domain)
        if pkg_resources.resource_exists('mcomix.messages', resource):
            translation = gettext.GNUTranslations(
                    pkg_resources.resource_stream('mcomix.messages', resource))
            break

    translation.install(unicode=True)

    global _translation
    _translation = translation
Example #3
0
def install_gettext():
    ''' Initialize gettext with the correct directory that contains
    MComix translations. This has to be done before any calls to gettext.gettext
    have been made to ensure all strings are actually translated. '''

    # Add the sources' base directory to PATH to allow development without
    # explicitly installing the package.
    sys.path.append(constants.BASE_PATH)

    # Initialize default locale
    locale.setlocale(locale.LC_ALL, '')

    lang_identifiers = []
    if preferences.prefs['language'] != 'auto':
        lang = preferences.prefs['language']
        if lang not in ('en', 'en_US'):
            # .mo is not needed for english
            lang_identifiers.append(lang)
    else:
        # Get the user's current locale
        lang = portability.get_default_locale()
        for s in gettext._expand_lang(lang):
            lang = s.split('.')[0]
            if lang in ('en', 'en_US'):
                # .mo is not needed for english
                continue
            if lang not in lang_identifiers:
                lang_identifiers.append(lang)

    # Make sure GTK uses the correct language.
    os.environ['LANGUAGE'] = lang

    domain = constants.APPNAME.lower()

    for lang in lang_identifiers:
        resource_path = tools.pkg_path('messages', lang, 'LC_MESSAGES',
                                       '%s.mo' % domain)
        try:
            with open(resource_path, mode='rb') as fp:
                translation = gettext.GNUTranslations(fp)
            break
        except IOError:
            log.error('locale file: %s not found.', resource_path)
    else:
        translation = gettext.NullTranslations()

    translation.install()

    global _translation
    _translation = translation
Example #4
0
def install_gettext():
    """ Initialize gettext with the correct directory that contains
    MComix translations. This has to be done before any calls to gettext.gettext
    have been made to ensure all strings are actually translated. """

    # Add the sources' base directory to PATH to allow development without
    # explicitly installing the package.
    sys.path.append(constants.BASE_PATH)

    # Initialize default locale
    locale.setlocale(locale.LC_ALL, '')

    if preferences.prefs['language'] != 'auto':
        lang = preferences.prefs['language']
        lang_identifiers = [ lang ]
    else:
        # Get the user's current locale
        lang = portability.get_default_locale()
        lang_identifiers = gettext._expand_lang(lang)

    # Make sure GTK uses the correct language.
    os.environ['LANGUAGE'] = lang

    domain = constants.APPNAME.lower()
    translation = gettext.NullTranslations()

    # Search for .mo files manually, since gettext doesn't support setuptools/pkg_resources.
    for lang in lang_identifiers:
        resource = os.path.join(lang, 'LC_MESSAGES', '%s.mo' % domain)
        if pkg_resources.resource_exists('mcomix.messages', resource):
            translation = gettext.GNUTranslations(
                    pkg_resources.resource_stream('mcomix.messages', resource))
            break

    try:  # dirty-ish hack for py23
        translation.install(**{'unicode': True})  # in the weird way because of a 2to3 bug
    except TypeError:
        translation.install()

    global _translation
    _translation = translation