Beispiel #1
0
def build_message_files(command):
    """For each locale/*.po, build .mo file in target locale directory"""
    for (_src, _dst) in list_message_files():
        _build_dst = os.path.join("build", _dst)
        command.mkpath(os.path.dirname(_build_dst))
        command.announce("Compiling %s -> %s" % (_src, _build_dst))
        msgfmt.make(_src, _build_dst)
Beispiel #2
0
 def build_message_files(self):
     """For each locale/*.po, build .mo file in target locale directory"""
     for (_src, _dst) in list_message_files():
         _build_dst = os.path.join("build", _dst)
         self.mkpath(os.path.dirname(_build_dst))
         self.announce("Compiling %s -> %s" % (_src, _build_dst))
         msgfmt.make(_src, _build_dst)
Beispiel #3
0
def get_mofile(languages, localedir, domain=None):
    """Return the first of .mo files found in localedir for languages

    Parameters:
        languages:
            list of locale names to try
        localedir:
            path to directory containing locale files.
            Usually this is either gettext_module._default_localedir
            or 'locale' subdirectory in the tracker home.
        domain:
            optional name of messages domain.
            If omitted or None, work with simplified
            locale directory, as used in tracker homes:
            message catalogs are kept in files locale.po
            instead of locale/LC_MESSAGES/domain.po

    Return the path of the first .mo file found.
    If nothing found, return None.

    Automatically compile .po files if necessary.

    """
    for locale in languages:
        if locale == "C":
            break
        if domain:
            basename = os.path.join(localedir, locale, "LC_MESSAGES", domain)
        else:
            basename = os.path.join(localedir, locale)
        # look for message catalog files, check timestamps
        mofile = basename + ".mo"
        if os.path.isfile(mofile):
            motime = os.path.getmtime(mofile)
        else:
            motime = 0
        pofile = basename + ".po"
        if os.path.isfile(pofile):
            potime = os.path.getmtime(pofile)
        else:
            potime = 0
        # see what we've found
        if motime < potime:
            # compile
            msgfmt.make(pofile, mofile)
        elif motime == 0:
            # no files found - proceed to the next locale name
            continue
        # .mo file found or made
        return mofile
    return None
Beispiel #4
0
def get_mofile(languages, localedir, domain=None):
    """Return the first of .mo files found in localedir for languages

    Parameters:
        languages:
            list of locale names to try
        localedir:
            path to directory containing locale files.
            Usually this is either gettext_module._default_localedir
            or 'locale' subdirectory in the tracker home.
        domain:
            optional name of messages domain.
            If omitted or None, work with simplified
            locale directory, as used in tracker homes:
            message catalogs are kept in files locale.po
            instead of locale/LC_MESSAGES/domain.po

    Return the path of the first .mo file found.
    If nothing found, return None.

    Automatically compile .po files if necessary.

    """
    for locale in languages:
        if locale == "C":
            break
        if domain:
            basename = os.path.join(localedir, locale, "LC_MESSAGES", domain)
        else:
            basename = os.path.join(localedir, locale)
        # look for message catalog files, check timestamps
        mofile = basename + ".mo"
        if os.path.isfile(mofile):
            motime = os.path.getmtime(mofile)
        else:
            motime = 0
        pofile = basename + ".po"
        if os.path.isfile(pofile):
            potime = os.path.getmtime(pofile)
        else:
            potime = 0
        # see what we've found
        if motime < potime:
            # compile
            msgfmt.make(pofile, mofile)
        elif motime == 0:
            # no files found - proceed to the next locale name
            continue
        # .mo file found or made
        return mofile
    return None