我在http://blog.armbruster-it.de/2010/07/getting-a-list-of-all-i18n-properties-used-in-a-grails-application/上找到了这个很棒的 gant 脚本,谢谢 Stefan !
描述:创建 groovy 代码和 gsp 模板中使用的所有 i18n 属性的列表
def properties = []
new File(".").eachFileRecurse {
if (it.file) {
switch (it) {
case ~/.*\.groovy/:
def matcher = it.text =~ /code:\s*["'](.*?)["']/
matcher.each { properties << it[1] }
break
case ~/.*\.gsp/:
def matcher = it.text =~ /code=["'](.*?)["']/
matcher.each { properties << it[1] }
break
}
}
}
println properties.sort().unique().join("\n")
我尝试通过以下方式扩展它。假设我们有一些消息属性,例如:
message(code: 'product.label', default: 'Product')
我们希望作为脚本输出的内容类似于:
product.label=Product
我试图在正则表达式中添加一些条件:
def matcher = it.text =~ /code=["'](.*?)["'] | default=\s*["'](.*?)["']/
并将其填充到属性中。但是由于正则表达式没有找到成对的“代码和默认”部分,所以这是行不通的。
知道如何更改正则表达式或整个脚本来做到这一点吗?