JAL-1424 Ant task to report missing language bundle entries
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Fri, 18 Sep 2015 10:41:43 +0000 (11:41 +0100)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Fri, 18 Sep 2015 10:41:43 +0000 (11:41 +0100)
utils/ant-contrib-1.0b3.jar [new file with mode: 0644]
utils/i18nAnt.xml [new file with mode: 0755]

diff --git a/utils/ant-contrib-1.0b3.jar b/utils/ant-contrib-1.0b3.jar
new file mode 100644 (file)
index 0000000..0625376
Binary files /dev/null and b/utils/ant-contrib-1.0b3.jar differ
diff --git a/utils/i18nAnt.xml b/utils/i18nAnt.xml
new file mode 100755 (executable)
index 0000000..eaabc47
--- /dev/null
@@ -0,0 +1,71 @@
+<?xml version="1.0"?>
+<!--
+  Ant utilities to help with internationalisation of Jalview.
+  Require the additional antcontrib targets (jar file).
+-->
+<project name="jalviewLang" default="checkLang" basedir="..">
+
+<taskdef resource="net/sf/antcontrib/antcontrib.properties">
+  <classpath>
+    <pathelement location="${basedir}/utils/ant-contrib-0.3.jar"/>
+  </classpath>
+</taskdef>
+<taskdef resource="net/sf/antcontrib/antlib.xml"/>
+<target name="checkLang" description="Reports missing entries in language bundles compared to Message.properties">
+       <!-- adapted from http://stackoverflow.com/questions/14381660/ant-task-to-compare-two-properties-files -->
+       <!-- reduce logging level so 'reportMissingProperty' does not clutter up the output -->
+       <script language="javascript">
+        var logger = project.getBuildListeners( ).firstElement( );
+        logger.setMessageOutputLevel( 1 );
+    </script>
+       <foreach target="compareProperties" param="file2">
+               <path>
+                       <fileset dir="${basedir}/resources/lang">
+                               <exclude name="Messages.properties" />
+                       </fileset>
+               </path>
+       </foreach>
+</target>
+
+<target name="compareProperties" description="reports missing entries in one message bundle">
+    <loadproperties srcFile="resources/lang/Messages.properties" prefix="prefixfile1"/>
+    <loadproperties srcFile="${file2}" prefix="prefixfile2"/>
+
+    <propertyselector property="file1.list" delimiter="," match="prefixfile1\.(.+)" select="\1"/>
+    <propertyselector property="file2.list" delimiter="," match="prefixfile2\.(.+)" select="\1"/>
+       
+    <for list="${file1.list}" param="file1.property">
+        <sequential>
+            <if>
+                <not>
+                    <matches pattern=",@{file1.property}," string=",${file2.list}," />
+                </not>
+                <then>
+                    <if>
+                        <not>
+                            <isset property="some_missing"/>
+                        </not>
+                           <then>
+                               <echo message=" "/>
+                               <echo>**** Missing in ${file2}: ****</echo>
+                           </then>
+                    </if>
+                    <property name="some_missing" value="true"/>
+                       <antcall target="reportMissingProperty">
+                               <param name="textLabel" value="@{file1.property}"/>
+                               <param name="prefixedPropertyName" value="prefixfile1.@{file1.property}" />
+                       </antcall>
+                </then>
+            </if>
+        </sequential>
+    </for>
+</target>
+
+<target name="reportMissingProperty" description="double dereference 'prefixedPropertyName' and report missing language property">
+       <propertycopy name="textValue" from="${prefixedPropertyName}"/>
+       <!-- output the property name (message label) and value (English text) -->
+    <echo message="${textLabel}=${textValue}"/>
+</target>
+
+</project>