Skip to content

Commit 7eaddc3

Browse files
committed
Updated translation build process
Removed maven profile
1 parent 0a42b17 commit 7eaddc3

3 files changed

Lines changed: 125 additions & 122 deletions

File tree

README.adoc

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -611,20 +611,23 @@ The built JAR file can be found under `de.tototec.cmdoption/target/de.tototec.cm
611611

612612
You want to create a new or update an existing translation?
613613

614-
CmdOption uses GNU Gettext. The translations are located under `src/main/po`. The message catalog template will be extracted in the compile phase (`mvn clean compile`) and is located under `target/po/messages.pot`.
614+
CmdOption uses GNU Gettext.
615+
The translations for the currently supported languages are located under `src/main/po`.
616+
The message catalog template will be extracted in the compile phase (`mvn clean compile`) and is located under `target/po/messages.pot` and can be used as template for a new language.
615617

616-
To update the translation files under `src/main/po` use the `update-message` profile.
618+
To update all translation files under `src/main/po` use the following Maven command:
617619

618-
.Merging all translations with current message catalog
620+
.Updating translations with extracted strings
619621
----
620-
mvn -Pupdate-messages clean compile
622+
mvn antrun:run@update-translations
621623
----
622624

623-
After that, edit the translation files and update the fuzzy or newly added messages.
625+
After that, edit the updated translation files and update the fuzzy or newly added messages.
624626
The `*.po` files are just normal text files, so you can use any editor you want.
625627
Using a special po-Editor like e.g. https://poedit.net/[Poedit] might add additional convenience.
626628

627-
If you update the translation please open a {githubUrl}/pulls[pull-request] with the new translation.
629+
If you updated or added a translation, please open a {githubUrl}/pulls[pull-request] with the new translation.
630+
Your contribution is greatly apreciated!
628631

629632

630633
=== Create `pom.xml` for interoperability, e.g. IDEs

de.tototec.cmdoption/pom.scala

Lines changed: 13 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -92,31 +92,19 @@ Model(
9292
phase = "process-sources",
9393
goals = Seq("run"),
9494
configuration = Config(
95-
target = Config(
96-
mkdir = Config(`@dir` = "${project.basedir}/target/po"),
97-
// run xgettext on the source files
98-
apply = Config(
99-
`@verbose` = "true",
100-
`@failOnError` = "true",
101-
`@executable` = "xgettext",
102-
// only one invocation with all files
103-
`@parallel` = "true",
104-
// ensure, we pass the files relative to their fileset roots
105-
`@relative` = "true",
106-
arg = Config(`@value` = "-ktr"),
107-
arg = Config(`@value` = "-kmarktr"),
108-
arg = Config(`@value` = "-kpreparetr"),
109-
arg = Config(`@value` = "--sort-by-file"),
110-
arg = Config(`@value` = "--directory"),
111-
arg = Config(`@value` = "src/main/java"),
112-
arg = Config(`@value` = "--output-dir"),
113-
arg = Config(`@value` = "${project.basedir}/target/po"),
114-
arg = Config(`@value` = "--output"),
115-
arg = Config(`@value` = "messages.pot"),
116-
// the source files to scan
117-
fileset = Config(`@dir` = "${project.basedir}/src/main/java")
95+
target = Gettext.extractMessagesTarget
96+
)
97+
),
98+
// Update/merge translations with current message catalog
99+
// Not bound to life-cycle
100+
// Please run manually with: mvn antrun:run@update-translations
101+
Execution(
102+
id = "update-translations",
103+
goals = Seq("run"),
104+
configuration = Config(
105+
target = new Config(
106+
Gettext.extractMessagesTarget.elements ++ Gettext.mergeMessagesTarget.elements
118107
)
119-
) //< target
120108
)
121109
),
122110
// Generate properties files for translations
@@ -125,76 +113,14 @@ Model(
125113
phase = "process-resources",
126114
goals = Seq("run"),
127115
configuration = Config(
128-
target = Config(
129-
mkdir = Config(`@dir` = "${project.basedir}/target/classes/de/tototec/cmdoption"),
130-
// run msgmerge on the translation files to generate property files
131-
apply = Config(
132-
`@executable` = "msgmerge",
133-
`@verbose` = "true",
134-
`@failOnError` = "true",
135-
// one invocation for each translation files
136-
`@parallel` = "false",
137-
`@dest` = "${project.basedir}/target/classes/de/tototec/cmdoption",
138-
// ensure, we pass the files relative to their fileset roots
139-
arg = Config(`@value` = "--output-file"),
140-
// marker for the target file position
141-
targetfile = Config(`@suffix` = ""),
142-
arg = Config(`@value` = "--properties-output"),
143-
// marker for the source file position
144-
srcfile = Config(`@suffix` = ""),
145-
// source files
146-
fileset = Config(`@dir` = "${project.basedir}/src/main/po", `@includes` = "*.po"),
147-
arg = Config(`@value` = "${project.basedir}/target/po/messages.pot"),
148-
mapper = Config(
149-
`@type` = "glob",
150-
`@from` = "*.po",
151-
`@to` = "Messages_*.properties"
152-
)
153-
)
154-
) //< target
116+
target = Gettext.generatePropertiesTarget
155117
)
156118
)
157119
)
158120
)
159121
)
160122
),
161123
profiles = Seq(
162-
Profile(
163-
id = "update-messages",
164-
build = BuildBase(
165-
plugins = Seq(
166-
// Update/merge translations with current message catalog
167-
Plugin(
168-
gav = "org.apache.maven.plugins" % "maven-antrun-plugin" % "1.8",
169-
executions = Seq(
170-
Execution(
171-
id = "merge-messages",
172-
phase = "generate-resources",
173-
goals = Seq("run"),
174-
configuration = Config(
175-
target = Config(
176-
// run msgmerge on the translation files to update them
177-
apply = Config(
178-
`@executable` = "msgmerge",
179-
`@verbose` = "true",
180-
`@failOnError` = "true",
181-
// one invocation for each translation files
182-
`@parallel` = "false",
183-
arg = Config(`@value` = "--backup=none"),
184-
// ensure, we pass the files relative to their fileset roots
185-
arg = Config(`@value` = "--update"),
186-
srcfile = Config(`@suffix` = ""),
187-
fileset = Config(`@dir` = "${project.basedir}/src/main/po", `@includes` = "*.po"),
188-
arg = Config(`@value` = "${project.basedir}/target/po/messages.pot")
189-
)
190-
) //< target
191-
)
192-
)
193-
)
194-
)
195-
)
196-
)
197-
),
198124
genPomXmlProfile
199125
)
200126
)

mvn-shared.scala

Lines changed: 103 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,38 +5,112 @@ object CmdOption {
55
}
66

77
val genPomXmlProfile = Profile(
8-
id = "gen-pom-xml",
9-
build = BuildBase(
10-
plugins = Seq(
11-
// Generate pom.xml from pom.scala
12-
Plugin(
13-
gav = "io.takari.polyglot" % "polyglot-translate-plugin" % "0.2.1",
14-
executions = Seq(
15-
Execution(
16-
id = "pom-scala-to-pom-xml",
17-
phase = "initialize",
18-
goals = Seq("translate-project"),
19-
configuration = Config(
20-
input = "pom.scala",
21-
output = "pom.xml"
22-
)
23-
)
24-
)
25-
),
26-
// Clean generated pom.xml
27-
Plugin(
28-
gav = "org.apache.maven.plugins" % "maven-clean-plugin" % "3.0.0",
8+
id = "gen-pom-xml",
9+
build = BuildBase(
10+
plugins = Seq(
11+
// Generate pom.xml from pom.scala
12+
Plugin(
13+
gav = "io.takari.polyglot" % "polyglot-translate-plugin" % "0.2.1",
14+
executions = Seq(
15+
Execution(
16+
id = "pom-scala-to-pom-xml",
17+
phase = "initialize",
18+
goals = Seq("translate-project"),
2919
configuration = Config(
30-
filesets = Config(
31-
fileset = Config(
32-
directory = "${basedir}",
33-
includes = Config(
34-
include = "pom.xml"
35-
)
36-
)
20+
input = "pom.scala",
21+
output = "pom.xml"
22+
)
23+
)
24+
)
25+
),
26+
// Clean generated pom.xml
27+
Plugin(
28+
gav = "org.apache.maven.plugins" % "maven-clean-plugin" % "3.0.0",
29+
configuration = Config(
30+
filesets = Config(
31+
fileset = Config(
32+
directory = "${basedir}",
33+
includes = Config(
34+
include = "pom.xml"
3735
)
3836
)
3937
)
4038
)
4139
)
42-
)
40+
)
41+
)
42+
)
43+
44+
object Gettext {
45+
46+
def extractMessagesTarget: Config = Config(
47+
mkdir = Config(`@dir` = "${project.basedir}/target/po"),
48+
// run xgettext on the source files
49+
apply = Config(
50+
`@verbose` = "true",
51+
`@failOnError` = "true",
52+
`@executable` = "xgettext",
53+
// only one invocation with all files
54+
`@parallel` = "true",
55+
// ensure, we pass the files relative to their fileset roots
56+
`@relative` = "true",
57+
arg = Config(`@value` = "-ktr"),
58+
arg = Config(`@value` = "-kmarktr"),
59+
arg = Config(`@value` = "-kpreparetr"),
60+
arg = Config(`@value` = "--sort-by-file"),
61+
arg = Config(`@value` = "--directory"),
62+
arg = Config(`@value` = "src/main/java"),
63+
arg = Config(`@value` = "--output-dir"),
64+
arg = Config(`@value` = "${project.basedir}/target/po"),
65+
arg = Config(`@value` = "--output"),
66+
arg = Config(`@value` = "messages.pot"),
67+
// the source files to scan
68+
fileset = Config(`@dir` = "${project.basedir}/src/main/java")
69+
)
70+
)
71+
72+
def mergeMessagesTarget: Config = Config(
73+
// run msgmerge on the translation files to update them
74+
apply = Config(
75+
`@executable` = "msgmerge",
76+
`@verbose` = "true",
77+
`@failOnError` = "true",
78+
// one invocation for each translation files
79+
`@parallel` = "false",
80+
arg = Config(`@value` = "--backup=none"),
81+
// ensure, we pass the files relative to their fileset roots
82+
arg = Config(`@value` = "--update"),
83+
srcfile = Config(`@suffix` = ""),
84+
fileset = Config(`@dir` = "${project.basedir}/src/main/po", `@includes` = "*.po"),
85+
arg = Config(`@value` = "${project.basedir}/target/po/messages.pot")
86+
)
87+
)
88+
89+
def generatePropertiesTarget: Config = Config(
90+
mkdir = Config(`@dir` = "${project.basedir}/target/classes/de/tototec/cmdoption"),
91+
// run msgmerge on the translation files to generate property files
92+
apply = Config(
93+
`@executable` = "msgmerge",
94+
`@verbose` = "true",
95+
`@failOnError` = "true",
96+
// one invocation for each translation files
97+
`@parallel` = "false",
98+
`@dest` = "${project.basedir}/target/classes/de/tototec/cmdoption",
99+
// ensure, we pass the files relative to their fileset roots
100+
arg = Config(`@value` = "--output-file"),
101+
// marker for the target file position
102+
targetfile = Config(`@suffix` = ""),
103+
arg = Config(`@value` = "--properties-output"),
104+
// marker for the source file position
105+
srcfile = Config(`@suffix` = ""),
106+
// source files
107+
fileset = Config(`@dir` = "${project.basedir}/src/main/po", `@includes` = "*.po"),
108+
arg = Config(`@value` = "${project.basedir}/target/po/messages.pot"),
109+
mapper = Config(
110+
`@type` = "glob",
111+
`@from` = "*.po",
112+
`@to` = "Messages_*.properties"
113+
)
114+
)
115+
)
116+
}

0 commit comments

Comments
 (0)