Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
feat(ZNTA-689): Support Qt TS files
Browse files Browse the repository at this point in the history
  • Loading branch information
djansen-redhat committed May 18, 2016
1 parent 8fbc422 commit 0464a20
Show file tree
Hide file tree
Showing 8 changed files with 198 additions and 6 deletions.
Expand Up @@ -43,7 +43,7 @@ public VersionDocumentsPage(WebDriver driver) {
}

public VersionDocumentsPage expectSourceDocsContains(final String document) {
log.info("Click Project link");
log.info("Expect Project documents contains {}", document);
waitForPageSilence();
assertThat(getSourceDocumentNames()).contains(document);
return new VersionDocumentsPage(getDriver());
Expand Down
Expand Up @@ -67,6 +67,9 @@ public void before() {
private static String testString = "Test text 1";
private static String htmlString = "<html><title>" + testString +
"</title>" + "<body/> </html>";
private static String qtTsString = "<!DOCTYPE TS []><TS><context><name>Test</name>" +
"<message><source>" + testString + "</source><translation>Teststring1</translation>" +
"</message></context></TS>";

@DataPoint
public static File TXT_FILE = new TestFileGenerator()
Expand Down Expand Up @@ -114,6 +117,10 @@ public void before() {
public static File HTML_FILE = new TestFileGenerator()
.generateTestFileWithContent("testhtmlfile", ".html", htmlString);

@DataPoint
public static File QTTS_FILE = new TestFileGenerator()
.generateTestFileWithContent("testtsfile", ".ts", qtTsString);

@DataPoint
public static File IDML_FILE = new TestFileGenerator()
.openTestFile("upload-idml.idml");
Expand Down
@@ -0,0 +1,130 @@
/*
* Copyright 2015, 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.feature.editor;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.zanata.feature.Feature;
import org.zanata.feature.testharness.TestPlan.DetailedTest;
import org.zanata.feature.testharness.ZanataTestCase;
import org.zanata.page.webtrans.EditorPage;
import org.zanata.util.CleanDocumentStorageRule;
import org.zanata.util.TestFileGenerator;
import org.zanata.util.ZanataRestCaller;
import org.zanata.workflow.BasicWorkFlow;
import org.zanata.workflow.LoginWorkFlow;
import org.zanata.workflow.ProjectWorkFlow;

import java.io.File;

import static org.assertj.core.api.Assertions.assertThat;
import static org.zanata.util.FunctionalTestHelper.assumeFalse;

/**
* @author Damian Jansen <a
* href="mailto:djansen@redhat.com">djansen@redhat.com</a>
*/
@Category(DetailedTest.class)
public class TranslateTsTest extends ZanataTestCase {

@Rule
public CleanDocumentStorageRule documentStorageRule =
new CleanDocumentStorageRule();

private ZanataRestCaller zanataRestCaller;

private TestFileGenerator testFileGenerator = new TestFileGenerator();

@Before
public void before() {
zanataRestCaller = new ZanataRestCaller();
new BasicWorkFlow().goToHome().deleteCookiesAndRefresh();
assumeFalse(
"",
new File(CleanDocumentStorageRule.getDocumentStoragePath()
.concat(File.separator).concat("documents")
.concat(File.separator)).exists());
new LoginWorkFlow().signIn("admin", "admin");
}

@Feature(summary = "The user can translate a Qt .ts file",
tcmsTestPlanIds = 5316, tcmsTestCaseIds = 0)
@Test(timeout = ZanataTestCase.MAX_SHORT_TEST_DURATION)
public void translateBasicTsFile() {
String testString = "<!DOCTYPE TS []><TS><context><name>Test</name>" +
"<message><source>Line One</source><translation>Teststring1</translation></message>" +
"<message><source>Line Two</source><translation>Teststring2</translation></message>" +
"<message><source>Line Three</source><translation>Teststring3</translation></message>" +
"</context></TS>";
File testfile = testFileGenerator.generateTestFileWithContent(
"basicts", ".ts", testString);
zanataRestCaller.createProjectAndVersion("ts-translate", "ts", "file");
EditorPage editorPage = new ProjectWorkFlow()
.goToProjectByName("ts-translate")
.gotoVersion("ts")
.gotoSettingsTab()
.gotoSettingsDocumentsTab()
.pressUploadFileButton()
.enterFilePath(testfile.getAbsolutePath())
.submitUpload()
.clickUploadDone()
.gotoLanguageTab()
.translate("fr", testfile.getName());

assertThat(editorPage.getMessageSourceAtRowIndex(0))
.isEqualTo("Line One")
.as("Item 1 shows Line One");
assertThat(editorPage.getMessageSourceAtRowIndex(1))
.isEqualTo("Line Two")
.as("Item 2 shows Line Two");
assertThat(editorPage.getMessageSourceAtRowIndex(2))
.isEqualTo("Line Three")
.as("Item 3 shows Line Three");

editorPage = editorPage.translateTargetAtRowIndex(0, "Une Ligne")
.approveTranslationAtRow(0)
.translateTargetAtRowIndex(1, "Deux Ligne")
.approveTranslationAtRow(1)
.translateTargetAtRowIndex(2, "Ligne Trois")
.approveTranslationAtRow(2);

assertTranslations(editorPage);

// Close and reopen the editor to test save, switches to CodeMirror
editorPage.reload();

assertTranslations(editorPage);
}

private void assertTranslations(EditorPage editorPage) {
assertThat(editorPage.getBasicTranslationTargetAtRowIndex(0))
.isEqualTo("Une Ligne")
.as("Item 1 shows a translation of Line One");
assertThat(editorPage.getBasicTranslationTargetAtRowIndex(1))
.isEqualTo("Deux Ligne")
.as("Item 2 shows a translation of Line Two");
assertThat(editorPage.getBasicTranslationTargetAtRowIndex(2))
.isEqualTo("Ligne Trois")
.as("Item 3 shows a translation of Line Three");
}
}
4 changes: 2 additions & 2 deletions pom.xml
Expand Up @@ -45,7 +45,7 @@
<groovy.version>2.4.5</groovy.version>
<guava.version>19.0</guava.version>
<gwt.version>2.7.0</gwt.version>
<icu4j.version>50.1.1</icu4j.version>
<icu4j.version>55.1</icu4j.version>
<lombok.source.dir>${project.build.sourceDirectory}/org/zanata</lombok.source.dir>
<lucene.version>3.6.2</lucene.version>
<org.mock-server.version>3.9.17</org.mock-server.version>
Expand Down Expand Up @@ -84,7 +84,7 @@
<solr.version>${lucene.version}</solr.version>
<slf4j.version>1.7.18</slf4j.version>
<gwteventservice.version>1.2.1</gwteventservice.version>
<okapi.version>0.22</okapi.version>
<okapi.version>0.29</okapi.version>

<zanata.assets.version>9.0-SNAPSHOT</zanata.assets.version>
<zanata.api.version>4.0.0-SNAPSHOT</zanata.api.version>
Expand Down
7 changes: 5 additions & 2 deletions zanata-war/pom.xml
Expand Up @@ -1708,7 +1708,7 @@
<dependency>
<groupId>net.htmlparser.jericho</groupId>
<artifactId>jericho-html</artifactId>
<version>3.3</version>
<version>3.4-dev</version>
</dependency>

<!-- Okapi Filters -->
Expand Down Expand Up @@ -1737,7 +1737,10 @@
<groupId>net.sf.okapi.filters</groupId>
<artifactId>okapi-filter-regex</artifactId>
</dependency>

<dependency>
<groupId>net.sf.okapi.filters</groupId>
<artifactId>okapi-filter-ts</artifactId>
</dependency>
<dependency>
<groupId>net.sf.okapi</groupId>
<artifactId>okapi-core</artifactId>
Expand Down
Expand Up @@ -172,6 +172,9 @@ public Resource parseDocumentFile(URI documentContent,
RawDocument rawDoc =
new RawDocument(documentContent, "UTF-8",
net.sf.okapi.common.LocaleId.fromString("en"));
if (rawDoc.getTargetLocale() == null) {
rawDoc.setTargetLocale(net.sf.okapi.common.LocaleId.ENGLISH);
}
updateParams(filterParams);
try {
filter.open(rawDoc);
Expand Down Expand Up @@ -421,6 +424,9 @@ private void generateTranslatedFile(URI originalFile,
RawDocument rawDoc =
new RawDocument(originalFile, "UTF-8",
net.sf.okapi.common.LocaleId.fromString("en"));
if (rawDoc.getTargetLocale() == null) {
rawDoc.setTargetLocale(localeId);
}
updateParams(params);
try {
filter.open(rawDoc);
Expand Down
42 changes: 42 additions & 0 deletions zanata-war/src/main/java/org/zanata/adapter/TSAdapter.java
@@ -0,0 +1,42 @@
/*
* Copyright 2014, 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.adapter;

import net.sf.okapi.filters.ts.TsFilter;

/**
* Adapter to handle Qt translation (.ts) files.<br/> using the
* Okapi {@link net.sf.okapi.filters.ts.TsFilter} class
*
* @author Damian Jansen
* <a href="mailto:djansen@redhat.com">djansen@redhat.com</a>
*/
public class TSAdapter extends OkapiFilterAdapter {

public TSAdapter() {
super(prepareFilter(), IdSource.contentHash, true);
}

private static TsFilter prepareFilter() {
return new TsFilter();
}
}
Expand Up @@ -40,9 +40,10 @@
import org.zanata.adapter.PlainTextAdapter;
import org.zanata.adapter.PropertiesLatinOneAdapter;
import org.zanata.adapter.PropertiesUTF8Adapter;
import org.zanata.adapter.SubtitleAdapter;
import org.zanata.adapter.TSAdapter;
import org.zanata.adapter.XliffAdapter;
import org.zanata.adapter.po.PoReader2;
import org.zanata.adapter.SubtitleAdapter;
import org.zanata.common.DocumentType;
import org.zanata.common.LocaleId;
import org.zanata.common.ProjectType;
Expand Down Expand Up @@ -79,6 +80,7 @@
import static org.zanata.common.DocumentType.PROPERTIES;
import static org.zanata.common.DocumentType.PROPERTIES_UTF8;
import static org.zanata.common.DocumentType.SUBTITLE;
import static org.zanata.common.DocumentType.TS;
import static org.zanata.common.DocumentType.XLIFF;
import static org.zanata.common.DocumentType.XML_DOCUMENT_TYPE_DEFINITION;

Expand Down Expand Up @@ -111,6 +113,8 @@ public class TranslationFileServiceImpl implements TranslationFileService {
DOCTYPEMAP.put(PROPERTIES_UTF8, PropertiesUTF8Adapter.class);
DOCTYPEMAP.put(XLIFF, XliffAdapter.class);
DOCTYPEMAP.put(GETTEXT, GettextAdapter.class);
DOCTYPEMAP.put(TS, TSAdapter.class);

}

private static Set<String> SUPPORTED_EXTENSIONS =
Expand Down

0 comments on commit 0464a20

Please sign in to comment.