【发布时间】:2014-05-02 02:21:57
【问题描述】:
我的项目中有 html-template,它们包含 pystache 代码,例如
{{#_}}Word{{\_}}
我想知道,如何通过 PoEditor 解析器提取这些单词
【问题讨论】:
标签: internationalization gettext poedit
我的项目中有 html-template,它们包含 pystache 代码,例如
{{#_}}Word{{\_}}
我想知道,如何通过 PoEditor 解析器提取这些单词
【问题讨论】:
标签: internationalization gettext poedit
现在我只是使用此代码制作文件,以便在 PoEdit 中用于扫描和提取关键字:
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
【讨论】:
您可以使用正则表达式来获取它们,然后删除您不想要的:
import re
regex=re.compile("\{\{\#\_\}\}.+\{\\\_\}\} ")
words=re.findall(regex, data)
#To remove it use re.split or simply now searching for [A-Z].
【讨论】: