【问题标题】:Extract keywords in a pystache template with gettext使用 gettext 在 pystache 模板中提取关键字
【发布时间】:2014-05-02 02:21:57
【问题描述】:

我的项目中有 html-template,它们包含 pystache 代码,例如

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

我想知道,如何通过 PoEditor 解析器提取这些单词

【问题讨论】:

    标签: internationalization gettext poedit


    【解决方案1】:

    现在我只是使用此代码制作文件,以便在 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
    

    【讨论】:

      【解决方案2】:

      您可以使用正则表达式来获取它们,然后删除您不想要的:

      import re
      regex=re.compile("\{\{\#\_\}\}.+\{\\\_\}\} ")
      words=re.findall(regex, data) 
      #To remove it use re.split or simply now searching for [A-Z].
      

      【讨论】:

      • 我需要一个用于 PoEditor 应用程序的 pystache 解析器,用于在我的项目中查找要翻译的单词PoEdit
      • 所以...这不起作用,您想知道如何在 PoEdit 工具中执行此操作。如果您发布您尝试过的内容,它可能对使用 PoEdit 的用户有用
      猜你喜欢
      • 2022-12-08
      • 2012-08-15
      • 2018-03-24
      • 2017-02-10
      • 2020-11-04
      • 2022-07-31
      • 2013-10-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多