def read_possible_plurals(): """ create list of all possible plural rules files result is cached to increase speed """ global pcache pdir = abspath('gluon','contrib','rules') plurals = {} # scan rules directory for plural_rules-*.py files: for pname in [f for f in listdir(pdir, regex_plural_rules) if osep not in f]: lang=pname[13:-3] fname=ospath.join(pdir, pname) mtime=ostat(fname).st_mtime if lang in pcache and pcache[lang][2] == mtime: # if plural_file's mtime wasn't changed - use previous value: plurals[lang]=pcache[lang] else: # otherwise, reread plural_rules-file: if 'plural_rules-'+lang in cfs: n,f1,f2,status=read_plural_rules(lang) else: n,f1,f2,status=read_plural_rules_aux(fname) plurals[lang]=(n, pname, mtime, status) pcache=plurals return pcache
def read_possible_plurals(): """ create list of all possible plural rules files result is cached to increase speed """ global pcache pdir = abspath('gluon', 'contrib', 'rules') plurals = {} # scan rules directory for plural_rules-*.py files: for pname in [ f for f in listdir(pdir, regex_plural_rules) if osep not in f ]: lang = pname[13:-3] fname = ospath.join(pdir, pname) mtime = ostat(fname).st_mtime if lang in pcache and pcache[lang][2] == mtime: # if plural_file's mtime wasn't changed - use previous value: plurals[lang] = pcache[lang] else: # otherwise, reread plural_rules-file: if 'plural_rules-' + lang in cfs: n, f1, f2, status = read_plural_rules(lang) else: n, f1, f2, status = read_plural_rules_aux(fname) plurals[lang] = (n, pname, mtime, status) pcache = plurals return pcache
def get_lang_info(lang, langdir): """retrieve lang information from *langdir*/*lang*.py file. Read few strings from lang.py file until keys !langname!, !langcode! or keys greater then '!*' were found args: lang (str): lang-code or 'default' langdir (str): path to 'languages' directory in web2py app dir returns: tuple(langcode, langname, langfile_mtime) e.g.: ('en', 'English', 1338549043.0) """ filename = ospath.join(langdir, lang+'.py') langcode=langname='' f = portalocker.LockedFile(filename, 'r') try: while not (langcode and langname): line = f.readline() if not line: break match=regex_langinfo.match(line) if match: k = match.group(1) if k == '!langname!': langname = match.group(2) elif k == '!langcode!': langcode = match.group(2) elif k[0:1] > '!': break finally: f.close() if not langcode: langcode = lang if lang != 'default' else 'en' return langcode, langname or langcode, ostat(filename).st_mtime
def get_lang_info(lang, langdir): """retrieve lang information from *langdir*/*lang*.py file. Read few strings from lang.py file until keys !langname!, !langcode! or keys greater then '!*' were found args: lang (str): lang-code or 'default' langdir (str): path to 'languages' directory in web2py app dir returns: tuple(langcode, langname, langfile_mtime) e.g.: ('en', 'English', 1338549043.0) """ filename = ospath.join(langdir, lang + '.py') langcode = langname = '' f = portalocker.LockedFile(filename, 'r') try: while not (langcode and langname): line = f.readline() if not line: break match = regex_langinfo.match(line) if match: k = match.group(1) if k == '!langname!': langname = match.group(2) elif k == '!langcode!': langcode = match.group(2) elif k[0:1] > '!': break finally: f.close() if not langcode: langcode = lang if lang != 'default' else 'en' return langcode, langname or langcode, ostat(filename).st_mtime