示例#1
0
def read_plural_dict_aux(filename):
    lang_text = read_locked(filename).replace('\r\n', '\n')
    try:
        return eval(lang_text) or {}
    except Exception:
        e = sys.exc_info()[1]
        status = 'Syntax error in %s (%s)' % (filename, e)
        logging.error(status)
        return {'__corrupted__': status}
示例#2
0
def read_plural_dict_aux(filename):
    lang_text = read_locked(filename).replace("\r\n", "\n")
    try:
        return eval(lang_text) or {}
    except Exception:
        e = sys.exc_info()[1]
        status = "Syntax error in %s (%s)" % (filename, e)
        logging.error(status)
        return {"__corrupted__": status}
示例#3
0
def read_dict_aux(filename):
    lang_text = read_locked(filename).replace(b'\r\n', b'\n')
    clear_cache(filename)
    try:
        return safe_eval(to_native(lang_text)) or {}
    except Exception:
        e = sys.exc_info()[1]
        status = 'Syntax error in %s (%s)' % (filename, e)
        logging.error(status)
        return {'__corrupted__': status}
示例#4
0
def findT(path, language=DEFAULT_LANGUAGE):
    """
    Note:
        Must be run by the admin app
    """
    lang_file = pjoin(path, 'languages', language + '.py')
    sentences = read_dict(lang_file)
    mp = pjoin(path, 'models')
    cp = pjoin(path, 'controllers')
    vp = pjoin(path, 'views')
    mop = pjoin(path, 'modules')
    for filename in \
            listdir(mp, '^.+\.py$', 0) + listdir(cp, '^.+\.py$', 0)\
            + listdir(vp, '^.+\.html$', 0) + listdir(mop, '^.+\.py$', 0):
        data = read_locked(filename)
        items = regex_translate.findall(data)
        items += regex_translate_m.findall(data)
        for item in items:
            try:
                message = safe_eval(item)
            except:
                continue  # silently ignore inproperly formatted strings
            if not message.startswith('#') and not '\n' in message:
                tokens = message.rsplit('##', 1)
            else:
                # this allows markmin syntax in translations
                tokens = [message]
            if len(tokens) == 2:
                message = tokens[0].strip() + '##' + tokens[1].strip()
            if message and not message in sentences:
                sentences[message] = message
    if not '!langcode!' in sentences:
        sentences['!langcode!'] = (DEFAULT_LANGUAGE if language
                                   in ('default',
                                       DEFAULT_LANGUAGE) else language)
    if not '!langname!' in sentences:
        sentences['!langname!'] = (DEFAULT_LANGUAGE_NAME if language in (
            'default', DEFAULT_LANGUAGE) else sentences['!langcode!'])
    write_dict(lang_file, sentences)
示例#5
0
def findT(path, language=DEFAULT_LANGUAGE):
    """
    Note:
        Must be run by the admin app
    """
    lang_file = pjoin(path, 'languages', language + '.py')
    sentences = read_dict(lang_file)
    mp = pjoin(path, 'models')
    cp = pjoin(path, 'controllers')
    vp = pjoin(path, 'views')
    mop = pjoin(path, 'modules')
    for filename in \
            listdir(mp, '^.+\.py$', 0) + listdir(cp, '^.+\.py$', 0)\
            + listdir(vp, '^.+\.html$', 0) + listdir(mop, '^.+\.py$', 0):
        data = read_locked(filename)
        items = regex_translate.findall(data)
        items += regex_translate_m.findall(data)
        for item in items:
            try:
                message = safe_eval(item)
            except:
                continue  # silently ignore inproperly formatted strings
            if not message.startswith('#') and not '\n' in message:
                tokens = message.rsplit('##', 1)
            else:
                # this allows markmin syntax in translations
                tokens = [message]
            if len(tokens) == 2:
                message = tokens[0].strip() + '##' + tokens[1].strip()
            if message and not message in sentences:
                sentences[message] = message
    if not '!langcode!' in sentences:
        sentences['!langcode!'] = (
            DEFAULT_LANGUAGE if language in ('default', DEFAULT_LANGUAGE) else language)
    if not '!langname!' in sentences:
        sentences['!langname!'] = (
            DEFAULT_LANGUAGE_NAME if language in ('default', DEFAULT_LANGUAGE)
            else sentences['!langcode!'])
    write_dict(lang_file, sentences)
示例#6
0
def findT(path, language=DEFAULT_LANGUAGE):
    """
    must be run by the admin app
    """
    lang_file = pjoin(path, "languages", language + ".py")
    sentences = read_dict(lang_file)
    mp = pjoin(path, "models")
    cp = pjoin(path, "controllers")
    vp = pjoin(path, "views")
    mop = pjoin(path, "modules")
    for filename in (
        listdir(mp, "^.+\.py$", 0)
        + listdir(cp, "^.+\.py$", 0)
        + listdir(vp, "^.+\.html$", 0)
        + listdir(mop, "^.+\.py$", 0)
    ):
        data = read_locked(filename)
        items = regex_translate.findall(data)
        for item in items:
            try:
                message = safe_eval(item)
            except:
                continue  # silently ignore inproperly formatted strings
            if not message.startswith("#") and not "\n" in message:
                tokens = message.rsplit("##", 1)
            else:
                # this allows markmin syntax in translations
                tokens = [message]
            if len(tokens) == 2:
                message = tokens[0].strip() + "##" + tokens[1].strip()
            if message and not message in sentences:
                sentences[message] = message
    if not "!langcode!" in sentences:
        sentences["!langcode!"] = DEFAULT_LANGUAGE if language in ("default", DEFAULT_LANGUAGE) else language
    if not "!langname!" in sentences:
        sentences["!langname!"] = (
            DEFAULT_LANGUAGE_NAME if language in ("default", DEFAULT_LANGUAGE) else sentences["!langcode!"]
        )
    write_dict(lang_file, sentences)