-
-
Notifications
You must be signed in to change notification settings - Fork 429
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add i18n-maven-plugin to make internationalization easier (#2544)
* Add i18n-maven-plugin to make internationalization easier This plugin simplifies generating the default translation .properties files from the add-on XML information files. It reuses the same XStream parsing classes that are used by openhab-core for parsing the binding/config/thing XML files. It will also keep any existing default translations already present in property files for translations using `@text/`. Furthermore it will nicely group and sort the translations. After building this Maven plugin you can use it on add-ons using: `mvn org.openhab.core.tools:i18n-maven-plugin:3.2.0-SNAPSHOT:generate-default-translations` Signed-off-by: Wouter Born <[email protected]>
- Loading branch information
Showing
32 changed files
with
2,323 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="src" output="target/classes" path="src/main/java"> | ||
<attributes> | ||
<attribute name="optional" value="true"/> | ||
<attribute name="maven.pomderived" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"> | ||
<attributes> | ||
<attribute name="maven.pomderived" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="src" output="target/test-classes" path="src/test/java"> | ||
<attributes> | ||
<attribute name="optional" value="true"/> | ||
<attribute name="maven.pomderived" value="true"/> | ||
<attribute name="test" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"> | ||
<attributes> | ||
<attribute name="maven.pomderived" value="true"/> | ||
<attribute name="test" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11"> | ||
<attributes> | ||
<attribute name="maven.pomderived" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"> | ||
<attributes> | ||
<attribute name="maven.pomderived" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="output" path="target/classes"/> | ||
</classpath> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>i18n-maven-plugin</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>org.eclipse.m2e.core.maven2Builder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
<nature>org.eclipse.m2e.core.maven2Nature</nature> | ||
</natures> | ||
</projectDescription> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
|
||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>org.openhab.core.tools</groupId> | ||
<artifactId>org.openhab.core.reactor.tools</artifactId> | ||
<version>3.2.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>i18n-maven-plugin</artifactId> | ||
|
||
<packaging>maven-plugin</packaging> | ||
|
||
<name>Internationalization Maven Plugin</name> | ||
<description>Generates translations files</description> | ||
|
||
<properties> | ||
<maven.core.version>3.6.0</maven.core.version> | ||
<maven.plugin.api.version>3.6.0</maven.plugin.api.version> | ||
<maven.plugin.annotations.version>3.6.0</maven.plugin.annotations.version> | ||
<maven.plugin.plugin.version>3.6.0</maven.plugin.plugin.version> | ||
<maven.plugin.compiler.version>3.8.1</maven.plugin.compiler.version> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.thoughtworks.xstream</groupId> | ||
<artifactId>xstream</artifactId> | ||
<version>1.4.18</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.maven</groupId> | ||
<artifactId>maven-plugin-api</artifactId> | ||
<version>${maven.plugin.api.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.maven.plugin-tools</groupId> | ||
<artifactId>maven-plugin-annotations</artifactId> | ||
<version>${maven.plugin.annotations.version}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-plugin-plugin</artifactId> | ||
<version>${maven.plugin.plugin.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.jdt</groupId> | ||
<artifactId>org.eclipse.jdt.annotation</artifactId> | ||
<version>2.2.100</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.openhab.core.bundles</groupId> | ||
<artifactId>org.openhab.core.binding.xml</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.openhab.core.bundles</groupId> | ||
<artifactId>org.openhab.core.config.xml</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.openhab.core.bundles</groupId> | ||
<artifactId>org.openhab.core.thing.xml</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.openhab.core.bom</groupId> | ||
<artifactId>org.openhab.core.bom.test</artifactId> | ||
<version>${project.version}</version> | ||
<type>pom</type> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.openhab.core.bom</groupId> | ||
<artifactId>org.openhab.core.bom.test-index</artifactId> | ||
<version>${project.version}</version> | ||
<type>pom</type> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-plugin-plugin</artifactId> | ||
<version>${maven.plugin.plugin.version}</version> | ||
<executions> | ||
<execution> | ||
<id>default-addPluginArtifactMetadata</id> | ||
<goals> | ||
<goal>addPluginArtifactMetadata</goal> | ||
</goals> | ||
<phase>package</phase> | ||
</execution> | ||
<execution> | ||
<id>default-descriptor</id> | ||
<goals> | ||
<goal>descriptor</goal> | ||
</goals> | ||
<phase>process-classes</phase> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
50 changes: 50 additions & 0 deletions
50
tools/i18n-plugin/src/main/java/org/openhab/core/tools/i18n/plugin/AbstractI18nMojo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/** | ||
* Copyright (c) 2010-2021 Contributors to the openHAB project | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.openhab.core.tools.i18n.plugin; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
|
||
import org.apache.maven.plugin.AbstractMojo; | ||
import org.apache.maven.plugins.annotations.Parameter; | ||
import org.eclipse.jdt.annotation.NonNullByDefault; | ||
|
||
/** | ||
* Base class for internationalization mojos using openHAB XML information. | ||
* | ||
* @author Wouter Born - Initial contribution | ||
*/ | ||
@NonNullByDefault | ||
public abstract class AbstractI18nMojo extends AbstractMojo { | ||
|
||
/** | ||
* The directory containing the bundle openHAB information | ||
*/ | ||
@Parameter(property = "i18n.ohinf.dir", defaultValue = "${project.basedir}/src/main/resources/OH-INF") | ||
protected @NonNullByDefault({}) File ohinfDirectory; | ||
|
||
protected BundleInfo bundleInfo = new BundleInfo(); | ||
|
||
protected boolean ohinfExists() { | ||
return ohinfDirectory.exists(); | ||
} | ||
|
||
protected void readAddonInfo() throws IOException { | ||
BundleInfoReader bundleInfoReader = new BundleInfoReader(getLog()); | ||
bundleInfo = bundleInfoReader.readBundleInfo(ohinfDirectory.toPath()); | ||
} | ||
|
||
void setOhinfDirectory(File ohinfDirectory) { | ||
this.ohinfDirectory = ohinfDirectory; | ||
} | ||
} |
95 changes: 95 additions & 0 deletions
95
tools/i18n-plugin/src/main/java/org/openhab/core/tools/i18n/plugin/BundleInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/** | ||
* Copyright (c) 2010-2021 Contributors to the openHAB project | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.openhab.core.tools.i18n.plugin; | ||
|
||
import java.net.URI; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import org.eclipse.jdt.annotation.NonNullByDefault; | ||
import org.eclipse.jdt.annotation.Nullable; | ||
import org.openhab.core.binding.xml.internal.BindingInfoXmlResult; | ||
import org.openhab.core.config.core.ConfigDescription; | ||
import org.openhab.core.thing.xml.internal.ChannelGroupTypeXmlResult; | ||
import org.openhab.core.thing.xml.internal.ChannelTypeXmlResult; | ||
import org.openhab.core.thing.xml.internal.ThingTypeXmlResult; | ||
|
||
/** | ||
* The bundle information provided by the openHAB XML files in the <code>OH-INF</code> directory. | ||
* | ||
* @author Wouter Born - Initial contribution | ||
*/ | ||
@NonNullByDefault | ||
public class BundleInfo { | ||
|
||
private @Nullable BindingInfoXmlResult bindingInfoXml; | ||
private List<ConfigDescription> configDescriptions = new ArrayList<>(5); | ||
private List<ChannelGroupTypeXmlResult> channelGroupTypesXml = new ArrayList<>(5); | ||
private List<ChannelTypeXmlResult> channelTypesXml = new ArrayList<>(5); | ||
private List<ThingTypeXmlResult> thingTypesXml = new ArrayList<>(5); | ||
|
||
public @Nullable BindingInfoXmlResult getBindingInfoXml() { | ||
return bindingInfoXml; | ||
} | ||
|
||
public void setBindingInfoXml(BindingInfoXmlResult bindingInfo) { | ||
this.bindingInfoXml = bindingInfo; | ||
} | ||
|
||
public List<ConfigDescription> getConfigDescriptions() { | ||
return configDescriptions; | ||
} | ||
|
||
public void setConfigDescriptions(List<ConfigDescription> configDescriptions) { | ||
this.configDescriptions = configDescriptions; | ||
} | ||
|
||
public List<ChannelGroupTypeXmlResult> getChannelGroupTypesXml() { | ||
return channelGroupTypesXml; | ||
} | ||
|
||
public void setChannelGroupTypesXml(List<ChannelGroupTypeXmlResult> channelGroupTypesXml) { | ||
this.channelGroupTypesXml = channelGroupTypesXml; | ||
} | ||
|
||
public List<ChannelTypeXmlResult> getChannelTypesXml() { | ||
return channelTypesXml; | ||
} | ||
|
||
public void setChannelTypesXml(List<ChannelTypeXmlResult> channelTypesXml) { | ||
this.channelTypesXml = channelTypesXml; | ||
} | ||
|
||
public List<ThingTypeXmlResult> getThingTypesXml() { | ||
return thingTypesXml; | ||
} | ||
|
||
public void setThingTypesXml(List<ThingTypeXmlResult> thingTypesXml) { | ||
this.thingTypesXml = thingTypesXml; | ||
} | ||
|
||
public String getBindingId() { | ||
BindingInfoXmlResult localBindingInfoXml = bindingInfoXml; | ||
return localBindingInfoXml == null ? "" : localBindingInfoXml.getBindingInfo().getUID(); | ||
} | ||
|
||
public Optional<ConfigDescription> getConfigDescription(@Nullable URI uri) { | ||
if (uri == null) { | ||
return Optional.empty(); | ||
} | ||
|
||
return configDescriptions.stream().filter(configDescription -> configDescription.getUID().equals(uri)) | ||
.findFirst(); | ||
} | ||
} |
Oops, something went wrong.