This repository has been archived by the owner on Nov 9, 2017. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:zanata/zanata
- Loading branch information
Showing
10 changed files
with
294 additions
and
35 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
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
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
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
57 changes: 57 additions & 0 deletions
57
...client-commands/src/main/java/org/zanata/client/commands/pull/UTF8PropertiesStrategy.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,57 @@ | ||
/* | ||
* Copyright 2011, Red Hat, Inc. and individual contributors | ||
* as indicated by the @author tags. See the copyright.txt file in the | ||
* distribution for a full listing of individual contributors. | ||
* | ||
* This is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU Lesser General Public License as | ||
* published by the Free Software Foundation; either version 2.1 of | ||
* the License, or (at your option) any later version. | ||
* | ||
* This software 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 | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this software; if not, write to the Free | ||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org. | ||
*/ | ||
|
||
package org.zanata.client.commands.pull; | ||
|
||
import java.io.IOException; | ||
|
||
import org.zanata.adapter.properties.PropWriter; | ||
import org.zanata.client.config.LocaleMapping; | ||
import org.zanata.rest.dto.resource.Resource; | ||
import org.zanata.rest.dto.resource.TranslationsResource; | ||
|
||
/** | ||
* @author Sean Flanigan <a href="mailto:sflaniga@redhat.com">sflaniga@redhat.com</a> | ||
* | ||
*/ | ||
public class UTF8PropertiesStrategy extends PropertiesStrategy | ||
{ | ||
|
||
public UTF8PropertiesStrategy() | ||
{ | ||
} | ||
|
||
@Override | ||
public void writeSrcFile(Resource doc) throws IOException | ||
{ | ||
PropWriter.writeUTF8(doc, getPullOptions().getSrcDir()); | ||
} | ||
|
||
@Override | ||
public void writeTransFile(Resource doc, String docName, LocaleMapping localeMapping, TranslationsResource targetDoc) throws IOException | ||
{ | ||
if (getPullOptions().getCreateSkeletons()) | ||
PropWriter.writeUTF8(doc, targetDoc, getPullOptions().getTransDir(), docName, localeMapping.getJavaLocale()); | ||
else | ||
PropWriter.writeUTF8(null, targetDoc, getPullOptions().getTransDir(), docName, localeMapping.getJavaLocale()); | ||
} | ||
|
||
} |
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
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
83 changes: 83 additions & 0 deletions
83
...nt-commands/src/test/java/org/zanata/client/commands/pull/PullPropertiesStrategyTest.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,83 @@ | ||
package org.zanata.client.commands.pull; | ||
|
||
import static org.testng.Assert.*; | ||
|
||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.InputStream; | ||
import java.io.InputStreamReader; | ||
|
||
import org.easymock.EasyMock; | ||
import org.easymock.IMocksControl; | ||
import org.fedorahosted.openprops.Properties; | ||
import org.testng.annotations.Test; | ||
import org.zanata.rest.dto.resource.Resource; | ||
import org.zanata.rest.dto.resource.TextFlow; | ||
|
||
@Test | ||
public class PullPropertiesStrategyTest | ||
{ | ||
IMocksControl control = EasyMock.createControl(); | ||
|
||
File outDir = new File("target/test-output/writeprops/"); | ||
Properties props = new Properties(); | ||
PullOptions opts; | ||
Resource doc; | ||
|
||
public PullPropertiesStrategyTest() | ||
{ | ||
outDir.mkdirs(); | ||
opts = control.createMock(PullOptions.class); | ||
EasyMock.expect(opts.getSrcDir()).andReturn(outDir).anyTimes(); | ||
control.replay(); | ||
doc = new Resource(null); | ||
doc.getTextFlows().add(newTextFlow("key", "value")); | ||
doc.getTextFlows().add(newTextFlow("unicode", "レス")); | ||
} | ||
|
||
@Test | ||
public void utf8() throws Exception | ||
{ | ||
PullStrategy strat = new UTF8PropertiesStrategy(); | ||
strat.setPullOptions(opts); | ||
|
||
doc.setName("utf8"); | ||
strat.writeSrcFile(doc); | ||
|
||
File f = new File(outDir, "utf8.properties"); | ||
InputStreamReader r = new InputStreamReader(new FileInputStream(f), "UTF-8"); | ||
props.load(r); | ||
checkResults(props); | ||
} | ||
|
||
|
||
@Test | ||
public void latin1() throws Exception | ||
{ | ||
PullStrategy strat = new PropertiesStrategy(); | ||
strat.setPullOptions(opts); | ||
|
||
doc.setName("latin1"); | ||
strat.writeSrcFile(doc); | ||
|
||
File f = new File(outDir, "latin1.properties"); | ||
InputStream inStream = new FileInputStream(f); | ||
props.load(inStream); | ||
checkResults(props); | ||
} | ||
|
||
private TextFlow newTextFlow(String key, String value) | ||
{ | ||
TextFlow tf = new TextFlow(); | ||
tf.setId(key); | ||
tf.setContent(value); | ||
return tf; | ||
} | ||
|
||
private void checkResults(Properties props) | ||
{ | ||
assertEquals(props.getProperty("key"), "value"); | ||
assertEquals(props.getProperty("unicode"), "レス"); | ||
} | ||
|
||
} |
Oops, something went wrong.