0

I have html-template in my project that they are contain pystache codes such as

{{#_}}Word{{\_}} 

I want to know , how I can extract this words by PoEditor parsers

llrs
  • 3,308
  • 35
  • 68
Siamand
  • 1,080
  • 10
  • 19

2 Answers2

0

You could use a regular expression to get them, and then remove what you don't want:

import re
regex=re.compile("\{\{\#\_\}\}.+\{\\\_\}\} ")
words=re.findall(regex, data) 
#To remove it use re.split or simply now searching for [A-Z].
llrs
  • 3,308
  • 35
  • 68
  • I need a pystache parser for PoEditor app for finding the words in my projects to translate [PoEdit](http://www.poedit.net/) – Siamand Mar 24 '14 at 19:36
  • So... that is not working and you want to know how to do it in PoEdit tool. If you post what did you tried it might be useful for the users who work with PoEdit – llrs Mar 25 '14 at 10:33
0

now I just using this code for making a file for using in PoEdit for scan and extracting the keywords:

def makeTempLang():
    fs = getFiles('templates/')
    words = []

    regex =re.compile("\{\{\#\_\}\}(.+)\{\{/\_\}\}")

    for f in fs:
        data=open(f,'r').read()
        fwords=re.findall(regex, data)
        words.extend(fwords)

    clean = (words[4:])
    data='from core import config\n_=config.i18n\n'
    for c in clean:
        data = "%s_('%s')\n"%(data,c)
    open('locale/temp2.py','w+').write(data)

    pass

def getFiles(spath=''):
    res =[]

    arr = os.listdir(spath)

    for d in arr:
        dpath =os.path.join(spath,d)

        if d.endswith('.htm'):
            res.append(dpath)
        if os.path.isdir(dpath):
            sub=getFiles(dpath)
            if len(sub) > 0 :
                res.extend(sub)
    return res
Siamand
  • 1,080
  • 10
  • 19