<commit_before>package org.fedorahosted.flies.adapter.po;

import java.io.File;
import java.io.IOException;
import java.util.List;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;

import junit.framework.Assert;

import org.fedorahosted.flies.common.LocaleId;
import org.fedorahosted.flies.rest.dto.Document;
import org.fedorahosted.flies.rest.dto.DocumentResource;
import org.fedorahosted.flies.rest.dto.TextFlow;
import org.fedorahosted.flies.rest.dto.TextFlowTargets;
import org.fedorahosted.flies.rest.dto.po.PoHeader;
import org.fedorahosted.flies.rest.dto.po.PotEntryData;
import org.junit.Test;
import org.xml.sax.InputSource;

public class PoReaderTest {
	
	LocaleId ja = new LocaleId("ja-JP");

	@Test
	public void extractTemplateThenAdd2Targets() throws IOException, JAXBException {
		String testDir = "src/test/resources/";

		Document doc = new Document("doc1", "doc1.pot", "/", PoReader.PO_CONTENT_TYPE);
		
		InputSource inputSource = new InputSource(
				new File(testDir, "pot/Accounts_And_Subscriptions.pot").toURI().toString()
		);
		inputSource.setEncoding("utf8");
		
		PoReader poReader = new PoReader();

		System.out.println("parsing template");
		poReader.extractTemplate(doc, inputSource);
		String [] locales = new String[]{"ja-JP"};
		for (String locale : locales){
			inputSource = new InputSource(
					new File(testDir, locale+"/Accounts_And_Subscriptions.po").toURI().toString()
			);
			inputSource.setEncoding("utf8");
			System.out.println("extracting target: " + locale);
			poReader.extractTarget(doc, inputSource, new LocaleId(locale));
		}
		
		System.out.println("marshalling");
		JAXBContext jaxbContext = JAXBContext.newInstance(Document.class, PotEntryData.class, PoHeader.class, TextFlowTargets.class);
		Marshaller m = jaxbContext.createMarshaller();
		m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
		m.marshal(doc, System.out);
		
		List<DocumentResource> resources = doc.getResources();
		
		TextFlow tf1 = (TextFlow) resources.get(0);
		Assert.assertEquals("Accounts and Subscriptions", tf1.getContent());
		Assert.assertEquals("アカウントと登録", tf1.getTarget(ja).getContent());
		
		// TODO test PO headers and attributes
	}
}
<commit_msg>- Removed unwanted or dirty test sample files of adapter-po and client-po. - Added clean po/pot files RPM.{po.pot} to adapter-po and client-po. - Updated PoReaderTest for new test sample files.<commit_after>package org.fedorahosted.flies.adapter.po;

import java.io.File;
import java.io.IOException;
import java.util.List;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;

import junit.framework.Assert;

import org.fedorahosted.flies.common.LocaleId;
import org.fedorahosted.flies.rest.dto.Document;
import org.fedorahosted.flies.rest.dto.DocumentResource;
import org.fedorahosted.flies.rest.dto.TextFlow;
import org.fedorahosted.flies.rest.dto.TextFlowTargets;
import org.fedorahosted.flies.rest.dto.po.PoHeader;
import org.fedorahosted.flies.rest.dto.po.PotEntryData;
import org.junit.Test;
import org.xml.sax.InputSource;

public class PoReaderTest {
	
	LocaleId ja = new LocaleId("ja-JP");

	@Test
	public void extractTemplateThenAdd2Targets() throws IOException, JAXBException {
		String testDir = "src/test/resources/";

		Document doc = new Document("doc1", "doc1.pot", "/", PoReader.PO_CONTENT_TYPE);
		
		InputSource inputSource = new InputSource(
				new File(testDir, "pot/RPM.pot").toURI().toString()
		);
		inputSource.setEncoding("utf8");
		
		PoReader poReader = new PoReader();

		System.out.println("parsing template");
		poReader.extractTemplate(doc, inputSource);
		String [] locales = new String[]{"ja-JP"};
		for (String locale : locales){
			inputSource = new InputSource(
					new File(testDir, locale+"/RPM.po").toURI().toString()
			);
			inputSource.setEncoding("utf8");
			System.out.println("extracting target: " + locale);
			poReader.extractTarget(doc, inputSource, new LocaleId(locale));
		}
		
		System.out.println("marshalling");
		JAXBContext jaxbContext = JAXBContext.newInstance(Document.class, PotEntryData.class, PoHeader.class, TextFlowTargets.class);
		Marshaller m = jaxbContext.createMarshaller();
		m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
		m.marshal(doc, System.out);
		
		List<DocumentResource> resources = doc.getResources();
		
		TextFlow tf1 = (TextFlow) resources.get(3);
		Assert.assertEquals("Important", tf1.getContent());
		Assert.assertEquals("キーのインポート", tf1.getTarget(ja).getContent());
		
		// TODO test PO headers and attributes
	}
}

{'fraction_non_alphanumeric': 0.12941686538044656, 'fraction_numerical': 0.0039020160416215043, 'mean_word_length': 5.111258278145695, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 8}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6992659', 'n_tokens_mistral': 1673, 'n_tokens_neox': 1530, 'n_words': 281}