mirror of https://github.com/FreeCol/freecol.git
Port change 5612 from 0.8.x.
This commit is contained in:
parent
0d1bfa19e2
commit
05457afccd
15
build.xml
15
build.xml
|
@ -689,6 +689,21 @@
|
|||
</java>
|
||||
</target>
|
||||
|
||||
<!-- Merges new translations from trunk. You can specify a
|
||||
particular language by setting the localeKey property
|
||||
("-DlocaleKey=fi", for example), or all translations. -->
|
||||
<target name="merge-translations" depends="build"
|
||||
description="Merges translations from trunk.">
|
||||
<condition property="localeKey" else="">
|
||||
<isset property="localeKey" />
|
||||
</condition>
|
||||
<java classname="net.sf.freecol.tools.MergeTranslations" classpath="build/" >
|
||||
<arg value="../../trunk/src/net/sf/freecol/client/gui/i18n/" />
|
||||
<arg value="src/net/sf/freecol/client/gui/i18n/" />
|
||||
<arg value="${localeKey}" />
|
||||
</java>
|
||||
</target>
|
||||
|
||||
<target name="pmd">
|
||||
<taskdef name="pmd" classname="net.sourceforge.pmd.ant.PMDTask"
|
||||
classpath="./pmd-4.1/lib/pmd-4.1.jar"/>
|
||||
|
|
|
@ -0,0 +1,115 @@
|
|||
/**
|
||||
* Copyright (C) 2002-2007 The FreeCol Team
|
||||
*
|
||||
* This file is part of FreeCol.
|
||||
*
|
||||
* FreeCol is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* FreeCol is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with FreeCol. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
package net.sf.freecol.tools;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FilenameFilter;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.text.DateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Properties;
|
||||
|
||||
|
||||
public class MergeTranslations {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
File sourceDirectory = new File(args[0]);
|
||||
if (!sourceDirectory.isDirectory()) {
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
File targetDirectory = new File(args[1]);
|
||||
if (!targetDirectory.isDirectory()) {
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
final String localeKey = args.length > 2 ? args[2] : "";
|
||||
String[] sourceFiles = sourceDirectory.list(new FilenameFilter() {
|
||||
public boolean accept(File dir, String name) {
|
||||
return name.matches("FreeColMessages_" + localeKey + ".*\\.properties");
|
||||
}
|
||||
});
|
||||
String[] targetFiles = targetDirectory.list(new FilenameFilter() {
|
||||
public boolean accept(File dir, String name) {
|
||||
return name.matches("FreeColMessages_" + localeKey + ".*\\.properties");
|
||||
}
|
||||
});
|
||||
|
||||
for (String name : sourceFiles) {
|
||||
|
||||
System.out.println("Processing source file: " + name);
|
||||
|
||||
File sourceFile = new File(sourceDirectory, name);
|
||||
Properties sourceProperties = new Properties();
|
||||
sourceProperties.load(new FileInputStream(sourceFile));
|
||||
|
||||
File targetFile = new File(targetDirectory, name);
|
||||
|
||||
if (targetFile.exists()) {
|
||||
|
||||
Properties targetProperties = new Properties();
|
||||
targetProperties.load(new FileInputStream(targetFile));
|
||||
|
||||
List<Entry> missingProperties = new ArrayList<Entry>();
|
||||
for (Entry entry : sourceProperties.entrySet()) {
|
||||
if (!targetProperties.containsKey(entry.getKey())) {
|
||||
missingProperties.add(entry);
|
||||
}
|
||||
}
|
||||
|
||||
if (!missingProperties.isEmpty()) {
|
||||
FileWriter out = new FileWriter(targetFile, true);
|
||||
out.write("### Merged from trunk on "
|
||||
+ DateFormat.getDateTimeInstance().format(new Date())
|
||||
+ " ###\n");
|
||||
for (Entry entry : missingProperties) {
|
||||
out.write((String) entry.getKey());
|
||||
out.write("=");
|
||||
out.write((String) entry.getValue());
|
||||
out.write("\n");
|
||||
}
|
||||
out.close();
|
||||
}
|
||||
} else {
|
||||
System.out.println("Copying " + name + " from trunk.");
|
||||
FileReader in = new FileReader(sourceFile);
|
||||
FileWriter out = new FileWriter(targetFile);
|
||||
|
||||
int c;
|
||||
|
||||
while ((c = in.read()) != -1) {
|
||||
out.write(c);
|
||||
}
|
||||
|
||||
in.close();
|
||||
out.close();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue