コード例 #1
0
def read_plural_dict_aux(filename):
    lang_text = portalocker.read_locked(filename).replace('\r\n', '\n')
    try:
        return eval(lang_text) or {}
    except Exception, e:
        status='Syntax error in %s (%s)' % (filename, e)
        logging.error(status)
        return {'__corrupted__':status}
コード例 #2
0
ファイル: languages.py プロジェクト: bachbouch/intministry
def read_plural_dict_aux(filename):
    lang_text = portalocker.read_locked(filename).replace("\r\n", "\n")
    try:
        return eval(lang_text) or {}
    except Exception, e:
        status = "Syntax error in %s (%s)" % (filename, e)
        logging.error(status)
        return {"__corrupted__": status}
コード例 #3
0
def read_plural_dict_aux(filename):
    lang_text = portalocker.read_locked(filename).replace('\r\n', '\n')
    try:
        return eval(lang_text) or {}
    except Exception, e:
        status = 'Syntax error in %s (%s)' % (filename, e)
        logging.error(status)
        return {'__corrupted__': status}
コード例 #4
0
ファイル: languages.py プロジェクト: PopoWow/web2py
def read_dict_aux(filename):
    lang_text = read_locked(filename).replace('\r\n', '\n')
    clear_cache(filename)
    try:
        return safe_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}
コード例 #5
0
def read_dict_aux(filename):
    lang_text = read_locked(filename).replace('\r\n', '\n')
    clear_cache(filename)
    try:
        return safe_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}
コード例 #6
0
ファイル: languages.py プロジェクト: pbreit/web2py-1
def read_global_plural_rules(filename):
    """
    retrieve plural rules from rules/*plural_rules-lang*.py file.

    args:
        filename (str): plural_rules filename

    returns:
        (nplurals, get_plural_id, construct_plural_form, status)
        e.g.: (3, <function>, <function>, ok)
    """
    env = {}
    data = portalocker.read_locked(filename)
    try:
        exec(data) in env
        status='ok'
    except Exception, e:
        status='Syntax error in %s (%s)' % (filename, e)
        logging.error(status)
コード例 #7
0
ファイル: languages.py プロジェクト: bachbouch/intministry
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 = portalocker.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)
コード例 #8
0
def findT(path, language='en'):
    """
    must be run by the admin app
    """
    lang_file = ospath.join(path, 'languages', language + '.py')
    sentences = read_dict(lang_file)
    mp = ospath.join(path, 'models')
    cp = ospath.join(path, 'controllers')
    vp = ospath.join(path, 'views')
    mop = ospath.join(path, 'modules')
    for filename in \
            listdir(mp, '^.+\.py$', 0)+listdir(cp, '^.+\.py$', 0)\
            +listdir(vp, '^.+\.html$', 0)+listdir(mop, '^.+\.py$', 0):
        data = portalocker.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!'] = (
            'en' if language in ('default', 'en') else language)
    if not '!langname!' in sentences:
        sentences['!langname!'] = (
            'English' if language in ('default', 'en')
            else sentences['!langcode!'])
    write_dict(lang_file, sentences)
コード例 #9
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 = portalocker.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)