This is a simple maven plugin that generates enums for every property file you run it on. Its intent is to have compile-time checks on the keys of property files, similar to how Android Studio handles resource identifiers. You can, for instance, use it to access translations in resource bundles.
Add this to your pom.xml
<plugin>
<groupId>de.torks</groupId>
<artifactId>property-keys-to-enum-maven-plugin</artifactId>
<version>0.0.1-SNAPSHOT</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<targetPackage>com.example.application.localization</targetPackage>
<!-- the file names in your resources folder, separated by comma, without extension -->
<resourceFiles>
<resourceFile>
<file>mail</file>
<enumValueContent>KEY</enumValueContent>
</resourceFile>
<resourceFile>
<file>mail</file>
<enumValueContent>VALUE</enumValueContent>
</resourceFile>
</resourceFiles>
</configuration>
</execution>
</executions>
</plugin>
In your …/src/main/resources/
folder add mail.properties
:
topic=Urgent Mail
content.header=<h1>Behead me</h1>
content.body= ....
content.footer-without-images=Fee(d/t) me
This will give you a generated file com.example.application.localization.Mail
which you can use to name your translation keys with a compiler-checked enum.
import com.example.application.localization.Mail;
EMail sendMail(Locale locale) {
return new EMail()
.topic(Translations.get(locale, Mail.TOPIC))
.contentHeader(Translations.get(locale, Mail.CONTENT_HEADER))
.receiver( ... );
}