Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support English keywords, i18N generation for Jython (excluding some languages) #197

Merged
merged 8 commits into from
Feb 8, 2012
53 changes: 52 additions & 1 deletion jython/pom.xml
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,60 @@
<goal>run</goal>
</goals>
</execution>
<execution>
<id>generate-i18n-resources</id>
<goals>
<goal>run</goal>
</goals>
<phase>generate-resources</phase>
<configuration>
<target>
<taskdef name="groovy" classname="org.codehaus.groovy.ant.Groovy" classpathref="maven.plugin.classpath" />
<groovy><![CDATA[
import groovy.text.SimpleTemplateEngine
import gherkin.I18n

def engine = new SimpleTemplateEngine()

def templateSource = new File(project.baseDir, "src${File.separator}main${File.separator}code_generator${File.separator}I18n.jython.txt").getText()

I18n.all.each { i18n ->
if (!["ar", "bg", "he", "is", "ja", "ko", "pl", "ru", "sr_cyrl", "uk", "uz", "zh_cn", "zh_tw"].contains(i18n.underscoredIsoCode)) {
def binding = ["i18n":i18n]
template = engine.createTemplate(templateSource).make(binding)
file = new File(project.baseDir, "target${File.separator}generated-resources${File.separator}i18n${File.separator}cucumber${File.separator}runtime${File.separator}jython${File.separator}i18n${File.separator}${i18n.underscoredIsoCode.toUpperCase()}.py")
file.parentFile.mkdirs()
file.write(template.toString(), "UTF-8")
}
}
]]></groovy>

</target>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>add-resource</id>
<phase>generate-resources</phase>
<goals>
<goal>add-resource</goal>
</goals>
<configuration>
<resources>
<resource>
<directory>${basedir}/target/generated-resources/i18n</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>

</plugins>
</build>
</project>
7 changes: 7 additions & 0 deletions jython/src/main/code_generator/I18n.jython.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<%
import java.text.Normalizer
def keywords = i18n.codeKeywords.collect { kw ->
Normalizer.normalize(kw, Normalizer.Form.NFD).replaceAll("\\p{InCombiningDiacriticalMarks}+", "")
}.unique()
%>
${keywords.join(" = ")} = I18NKeywordTemplate
5 changes: 3 additions & 2 deletions jython/src/main/resources/cucumber/runtime/jython/dsl.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import re
from gherkin.formatter import Argument

class Given(object):
class I18NKeywordTemplate(object):
def __init__(self, regexp):
self.regexp = regexp

Expand Down Expand Up @@ -35,5 +34,7 @@ def execute(self, *args):
def pattern(self):
return self.regexp

And = But = Given = Then = When = I18NKeywordTemplate

class World:
"""The World"""
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ def something_in_the_belly(self, n, what):
self.n = int(n)
self.what = what

@Given('^I am "([^"]*)"$')
@Then('^I am "([^"]*)"$')
def i_am(self, mood):
if ("happy" != mood):
raise(Exception("Not happy, only %d %s" % (self.n, self.what)))