diff --git a/client/zanata-adapter-properties/src/main/java/org/zanata/adapter/properties/PropWriter.java b/client/zanata-adapter-properties/src/main/java/org/zanata/adapter/properties/PropWriter.java index 158e96afc4..3c234ba912 100644 --- a/client/zanata-adapter-properties/src/main/java/org/zanata/adapter/properties/PropWriter.java +++ b/client/zanata-adapter-properties/src/main/java/org/zanata/adapter/properties/PropWriter.java @@ -3,7 +3,8 @@ import java.io.File; import java.io.FileOutputStream; import java.io.IOException; -import java.io.PrintStream; +import java.io.OutputStreamWriter; +import java.io.Writer; import org.fedorahosted.openprops.Properties; import org.zanata.rest.dto.extensions.comment.SimpleComment; @@ -35,7 +36,7 @@ private static void makeParentDirs(File f) * @param baseDir * @throws IOException */ - public static void write(final Resource doc, final File baseDir) throws IOException + public static void write(final Resource doc, final File baseDir, String charset) throws IOException { File baseFile = new File(baseDir, doc.getName() + ".properties"); makeParentDirs(baseFile); @@ -50,14 +51,19 @@ public static void write(final Resource doc, final File baseDir) throws IOExcept props.setComment(textFlow.getId(), simpleComment.getValue()); } // props.store(System.out, null); - PrintStream out = new PrintStream(new FileOutputStream(baseFile)); - props.store(out, null); - out.close(); + Writer out = new OutputStreamWriter(new FileOutputStream(baseFile), charset); + try + { + props.store(out, null); + } + finally + { + out.close(); + } } - public static void write(final TranslationsResource doc, final File baseDir, String bundleName, String locale) throws IOException + public static void write(final TranslationsResource doc, final File baseDir, String bundleName, String locale, String charset) throws IOException { - Properties targetProp = new Properties(); for (TextFlowTarget target : doc.getTextFlowTargets()) { @@ -71,8 +77,15 @@ public static void write(final TranslationsResource doc, final File baseDir, Str makeParentDirs(langFile); logVerbose("Creating target file " + langFile); // targetProp.store(System.out, null); - PrintStream out2 = new PrintStream(new FileOutputStream(langFile)); - targetProp.store(out2, null); + Writer out2 = new OutputStreamWriter(new FileOutputStream(langFile), charset); + try + { + targetProp.store(out2, null); + } + finally + { + out2.close(); + } } } diff --git a/client/zanata-adapter-properties/src/test/java/org/zanata/adapter/properties/PropReaderTests.java b/client/zanata-adapter-properties/src/test/java/org/zanata/adapter/properties/PropReaderTests.java index 042bced2ff..689e9587e8 100644 --- a/client/zanata-adapter-properties/src/test/java/org/zanata/adapter/properties/PropReaderTests.java +++ b/client/zanata-adapter-properties/src/test/java/org/zanata/adapter/properties/PropReaderTests.java @@ -32,8 +32,8 @@ public class PropReaderTests private static final Logger log = LoggerFactory.getLogger(PropReaderTests.class); private static final String TEST_OUTPUT_DIR_STRING = "target/test-output"; private static final File TEST_OUTPUT_DIR = new File(TEST_OUTPUT_DIR_STRING); - PropReader propReader; + static final String ISO_8859_1 = "ISO-8859-1"; @BeforeMethod public void resetReader() @@ -45,7 +45,6 @@ public void resetReader() public void roundtripSrcPropsToDocXmlToProps() throws Exception { String docName = "test.properties"; - Resource srcDoc = new Resource("test"); InputStream testStream = getResourceAsStream(docName); @@ -60,7 +59,7 @@ public void roundtripSrcPropsToDocXmlToProps() throws Exception Unmarshaller unmarshal = jc.createUnmarshaller(); Resource docIn = (Resource) unmarshal.unmarshal(new StringReader(sw.toString())); - PropWriter.write(docIn, TEST_OUTPUT_DIR); + PropWriter.write(docIn, TEST_OUTPUT_DIR, ISO_8859_1); assertInputAndOutputDocContentSame(docName); } @@ -84,8 +83,8 @@ public void roundtripTransPropsToDocXmlToProps() throws Exception Unmarshaller unmarshal = jc.createUnmarshaller(); TranslationsResource docIn = (TranslationsResource) unmarshal.unmarshal(new StringReader(sw.toString())); - PropWriter.write(docIn, TEST_OUTPUT_DIR, "test", locale); - + PropWriter.write(docIn, TEST_OUTPUT_DIR, "test", locale, ISO_8859_1); + assertInputAndOutputDocContentSame(docName); } diff --git a/client/zanata-client-commands/src/main/java/org/zanata/client/commands/ConfigurableProjectCommand.java b/client/zanata-client-commands/src/main/java/org/zanata/client/commands/ConfigurableProjectCommand.java index 8e3553715c..fcffe79212 100644 --- a/client/zanata-client-commands/src/main/java/org/zanata/client/commands/ConfigurableProjectCommand.java +++ b/client/zanata-client-commands/src/main/java/org/zanata/client/commands/ConfigurableProjectCommand.java @@ -34,8 +34,9 @@ public abstract class ConfigurableProjectCommand extends ConfigurableCommand { - protected static final String PROJECT_TYPE_PUBLICAN = "podir"; + protected static final String PROJECT_TYPE_UTF8_PROPERTIES = "utf8properties"; protected static final String PROJECT_TYPE_PROPERTIES = "properties"; + protected static final String PROJECT_TYPE_PUBLICAN = "podir"; protected static final String PROJECT_TYPE_XLIFF = "xliff"; protected static final String PROJECT_TYPE_XML = "xml"; diff --git a/client/zanata-client-commands/src/main/java/org/zanata/client/commands/pull/PropertiesStrategy.java b/client/zanata-client-commands/src/main/java/org/zanata/client/commands/pull/PropertiesStrategy.java index d30fb53163..11d1fa2db1 100644 --- a/client/zanata-client-commands/src/main/java/org/zanata/client/commands/pull/PropertiesStrategy.java +++ b/client/zanata-client-commands/src/main/java/org/zanata/client/commands/pull/PropertiesStrategy.java @@ -35,8 +35,22 @@ */ public class PropertiesStrategy implements PullStrategy { + // "8859_1" is used in Properties.java... + private static final String ISO_8859_1 = "ISO-8859-1"; + StringSet extensions = new StringSet("comment"); private PullOptions opts; + private final String charset; + + public PropertiesStrategy() + { + this(ISO_8859_1); + } + + public PropertiesStrategy(String charset) + { + this.charset = charset; + } @Override public void setPullOptions(PullOptions opts) @@ -59,13 +73,13 @@ public boolean needsDocToWriteTrans() @Override public void writeSrcFile(Resource doc) throws IOException { - PropWriter.write(doc, opts.getSrcDir()); + PropWriter.write(doc, opts.getSrcDir(), charset); } @Override public void writeTransFile(Resource doc, String docName, LocaleMapping localeMapping, TranslationsResource targetDoc) throws IOException { - PropWriter.write(targetDoc, opts.getTransDir(), docName, localeMapping.getJavaLocale()); + PropWriter.write(targetDoc, opts.getTransDir(), docName, localeMapping.getJavaLocale(), charset); } } diff --git a/client/zanata-client-commands/src/main/java/org/zanata/client/commands/pull/PullCommand.java b/client/zanata-client-commands/src/main/java/org/zanata/client/commands/pull/PullCommand.java index fe7e142109..fbc8e83915 100644 --- a/client/zanata-client-commands/src/main/java/org/zanata/client/commands/pull/PullCommand.java +++ b/client/zanata-client-commands/src/main/java/org/zanata/client/commands/pull/PullCommand.java @@ -38,10 +38,12 @@ public class PullCommand extends ConfigurableProjectCommand { private static final Logger log = LoggerFactory.getLogger(PullCommand.class); + private static final String UTF_8 = "UTF-8"; private static final Map strategies = new HashMap(); { + strategies.put(PROJECT_TYPE_UTF8_PROPERTIES, new PropertiesStrategy(UTF_8)); strategies.put(PROJECT_TYPE_PROPERTIES, new PropertiesStrategy()); strategies.put(PROJECT_TYPE_PUBLICAN, new GettextDirStrategy()); strategies.put(PROJECT_TYPE_XLIFF, new XliffStrategy()); diff --git a/client/zanata-client-commands/src/main/java/org/zanata/client/commands/push/PropertiesStrategy.java b/client/zanata-client-commands/src/main/java/org/zanata/client/commands/push/PropertiesStrategy.java index 0dfeb33939..4cd50e01a1 100644 --- a/client/zanata-client-commands/src/main/java/org/zanata/client/commands/push/PropertiesStrategy.java +++ b/client/zanata-client-commands/src/main/java/org/zanata/client/commands/push/PropertiesStrategy.java @@ -21,12 +21,12 @@ package org.zanata.client.commands.push; -import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; -import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -46,9 +46,20 @@ class PropertiesStrategy extends AbstractPushStrategy { + // "8859_1" is used in Properties.java... + private static final String ISO_8859_1 = "ISO-8859-1"; + + private final String charset; + public PropertiesStrategy() + { + this(ISO_8859_1); + } + + public PropertiesStrategy(String charset) { super(new StringSet("comment"), ".properties"); + this.charset = charset; } @Override @@ -68,16 +79,16 @@ public Set findDocNames(File srcDir, List includes, List private Properties loadPropFile(File propFile) throws FileNotFoundException, IOException { - InputStream is = new BufferedInputStream(new FileInputStream(propFile)); + Reader reader = new InputStreamReader(new FileInputStream(propFile), charset); try { Properties props = new Properties(); - props.load(is); + props.load(reader); return props; } finally { - is.close(); + reader.close(); } } @@ -147,7 +158,14 @@ private void addPropEntryToDoc(TranslationsResource targetDoc, Properties props, return; TextFlowTarget textFlowTarget = new TextFlowTarget(key); textFlowTarget.setContent(content); - textFlowTarget.setState(ContentState.Approved); + if (!content.isEmpty()) + { + textFlowTarget.setState(ContentState.Approved); + } + else + { + textFlowTarget.setState(ContentState.New); + } String comment = props.getComment(key); if (comment != null) { diff --git a/client/zanata-client-commands/src/main/java/org/zanata/client/commands/push/PushCommand.java b/client/zanata-client-commands/src/main/java/org/zanata/client/commands/push/PushCommand.java index 5e2e20f2b9..6912ee34a9 100644 --- a/client/zanata-client-commands/src/main/java/org/zanata/client/commands/push/PushCommand.java +++ b/client/zanata-client-commands/src/main/java/org/zanata/client/commands/push/PushCommand.java @@ -39,6 +39,7 @@ public class PushCommand extends ConfigurableProjectCommand { private static final Logger log = LoggerFactory.getLogger(PushCommand.class); + private static final String UTF_8 = "UTF-8"; private static final Map strategies = new HashMap(); @@ -48,6 +49,7 @@ public static interface TranslationResourcesVisitor } { + strategies.put(PROJECT_TYPE_UTF8_PROPERTIES, new PropertiesStrategy(UTF_8)); strategies.put(PROJECT_TYPE_PROPERTIES, new PropertiesStrategy()); strategies.put(PROJECT_TYPE_PUBLICAN, new GettextDirStrategy()); strategies.put(PROJECT_TYPE_XLIFF, new XliffStrategy());