Internationalization 使用gettext提取pystache模板中的关键字
我的项目中有html模板,它们包含pystache代码,例如Internationalization 使用gettext提取pystache模板中的关键字,internationalization,gettext,poedit,Internationalization,Gettext,Poedit,我的项目中有html模板,它们包含pystache代码,例如 {{#_}}Word{{\_}} 我想知道,如何通过PoEditor解析器提取这些单词,您可以使用正则表达式获取它们,然后删除不需要的内容: import re regex=re.compile("\{\{\#\_\}\}.+\{\\\_\}\} ") words=re.findall(regex, data) #To remove it use re.split or simply now searching for [A-Z
{{#_}}Word{{\_}}
我想知道,如何通过PoEditor解析器提取这些单词,您可以使用正则表达式获取它们,然后删除不需要的内容:
import re
regex=re.compile("\{\{\#\_\}\}.+\{\\\_\}\} ")
words=re.findall(regex, data)
#To remove it use re.split or simply now searching for [A-Z].
现在,我只使用以下代码制作一个文件,用于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
我需要一个PoEditor应用程序的pystache解析器,用于在我的项目中查找要翻译的单词,以便。。。这不起作用,您想知道如何在PoEdit工具中实现这一点。如果您发布了您尝试过的内容,对于使用PoEdit的用户可能会很有用