TranslationKitService { @Transactional public TranslationKitAsXliff generateTranslationKitAsXLIFF(Long dropId, Long tmId, Long localeId, TranslationKit.Type type, Boolean useInheritance) { logger.debug("Get translation kit for in tmId: {} and locale: {}", tmId, localeId); TranslationKit translationKit = addTranslationKit(dropId, localeId, type); logger.trace("Create XLIFFWriter"); XLIFFWriter xliffWriter = new XLIFFWriter(); logger.trace("Prepare FilterEventsWriterStep to use an XLIFFWriter with outputstream (allows only one doc to be processed)"); FilterEventsWriterStep filterEventsWriterStep = new FilterEventsWriterStep(xliffWriter); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); filterEventsWriterStep.setOutputStream(byteArrayOutputStream); filterEventsWriterStep.setOutputEncoding(StandardCharsets.UTF_8.toString()); TranslationKitStep tksStep = new TranslationKitStep(translationKit.getId()); logger.trace("Prepare the Okapi pipeline"); IPipelineDriver driver = new PipelineDriver(); driver.addStep(new RawDocumentToFilterEventsStep(new TranslationKitFilter(translationKit.getId(), type, useInheritance))); driver.addStep(tksStep); driver.addStep(filterEventsWriterStep); logger.trace("Add single document with fake output URI to be processed with an outputStream"); Locale locale = localeService.findById(localeId); RawDocument rawDocument = new RawDocument(RawDocument.EMPTY, LocaleId.ENGLISH, LocaleId.fromBCP47(locale.getBcp47Tag())); driver.addBatchItem(rawDocument, RawDocument.getFakeOutputURIForStream(), null); logger.debug("Start processing batch"); driver.processBatch(); logger.trace("Get the output result from the stream"); TranslationKitAsXliff translationKitAsXliff = new TranslationKitAsXliff(); translationKitAsXliff.setContent(StreamUtil.getUTF8OutputStreamAsString(byteArrayOutputStream)); translationKitAsXliff.setTranslationKitId(translationKit.getId()); translationKitAsXliff.setEmpty(tksStep.wordCount < 1); return translationKitAsXliff; }  @Transactional TranslationKitAsXliff generateTranslationKitAsXLIFF(Long dropId, Long tmId, Long localeId, TranslationKit.Type type, Boolean useInheritance); TranslationKitAsXliff generateTranslationKitAsXLIFF(Long dropId, Long tmId, Long localeId, TranslationKit.Type type); List<TextUnitDTO> getTextUnitDTOsForTranslationKit(Long translationKitId, TranslationKit.Type type); @Transactional TranslationKit addTranslationKit(Long dropId, Long localeId, TranslationKit.Type type); @Transactional void updateTranslationKitWithTmTextUnits(Long translationKitId, List<TranslationKitTextUnit> translationKitTextUnits, Long wordCount); void markTranslationKitTextUnitAsImported(TranslationKit translationKit, TMTextUnitVariant tmTextUnitVariant); @Transactional void updateStatistics(Long translationKitId, Set<String> notFoundTextUnitIds); @Transactional void checkForPartiallyImported(Long dropId); Map<Long, TranslationKitExportedImportedAndCurrentTUV> getTranslationKitExportedAndCurrentTUVs(Long translationKitId); List<TextUnitDTO> getTextUnitDTOsForTranslationKitWithInheritance(Long translationKitId);  }
@Test public void testGetXLIFF() { tmTestData = new TMTestData(testIdWatcher); Drop drop = dropService.createDrop(tmTestData.repository); TranslationKitAsXliff translationKitAsXLIFF = translationKitService.generateTranslationKitAsXLIFF( drop.getId(), tmTestData.tm.getId(), tmTestData.frCA.getId(), TranslationKit.Type.TRANSLATION); logger.debug(translationKitAsXLIFF.getContent()); String xliffWithoutIds = XliffUtils.replaceXliffVariableContent(translationKitAsXLIFF.getContent()); logger.debug(xliffWithoutIds); assertEquals( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<xliff version=\"1.2\" xmlns=\"urn:oasis:names:tc:xliff:document:1.2\" xmlns:okp=\"okapi-framework:xliff-extensions\">\n" + "<file original=\"replaced-original\" source-language=\"en\" target-language=\"fr-CA\" datatype=\"x-undefined\" okp:inputEncoding=\"UTF-8\">\n" + "<body>\n" + "<trans-unit id=\"replaced-id\" resname=\"zuora_error_message_verify_state_province\" xml:space=\"preserve\">\n" + "<source xml:lang=\"en\">Please enter a valid state, region or province</source>\n" + "<target xml:lang=\"fr-CA\" state=\"new\">Please enter a valid state, region or province</target>\n" + "<note>Comment1</note>\n" + "</trans-unit>\n" + "</body>\n" + "</file>\n" + "</xliff>\n", xliffWithoutIds); logger.debug("Check the translation kit entities"); TranslationKit translationKit = translationKitRepository.findById(translationKitAsXLIFF.getTranslationKitId()).orElse(null); List<TranslationKitTextUnit> findByTranslationKitId = translationKitTextUnitRepository.findByTranslationKit(translationKit); assertEquals("The translation kit must be of type translation", TranslationKit.Type.TRANSLATION, translationKit.getType()); assertEquals("There must be 1 TranslationKitTextUnit", 1, findByTranslationKitId.size()); assertEquals("Check the first TextUnit by name", findByTranslationKitId.get(0).getTmTextUnit().getName(), "zuora_error_message_verify_state_province"); assertNull("There shouldn't be any TmTextUnitVariant for this TextUnit", findByTranslationKitId.get(0).getExportedTmTextUnitVariant()); }
@Test @Transactional public void testTranslationNeeded() { tmTestData = new TMTestData(testIdWatcher); logger.debug("Mark on translated string as need review"); tmService.addTMTextUnitCurrentVariant( tmTestData.addCurrentTMTextUnitVariant1FrFR.getTmTextUnit().getId(), tmTestData.addCurrentTMTextUnitVariant1FrFR.getLocale().getId(), tmTestData.addCurrentTMTextUnitVariant1FrFR.getContent(), "this translation is bad in context", TMTextUnitVariant.Status.TRANSLATION_NEEDED); Drop drop = dropService.createDrop(tmTestData.repository); TranslationKitAsXliff translationKitAsXLIFF = translationKitService.generateTranslationKitAsXLIFF( drop.getId(), tmTestData.tm.getId(), tmTestData.frFR.getId(), TranslationKit.Type.TRANSLATION); logger.debug(translationKitAsXLIFF.getContent()); String xliffWithoutIds = XliffUtils.replaceXliffVariableContent(translationKitAsXLIFF.getContent()); logger.debug(xliffWithoutIds); assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<xliff version=\"1.2\" xmlns=\"urn:oasis:names:tc:xliff:document:1.2\" xmlns:okp=\"okapi-framework:xliff-extensions\">\n" + "<file original=\"replaced-original\" source-language=\"en\" target-language=\"fr-FR\" datatype=\"x-undefined\" okp:inputEncoding=\"UTF-8\">\n" + "<body>\n" + "<trans-unit id=\"replaced-id\" resname=\"zuora_error_message_verify_state_province\" xml:space=\"preserve\">\n" + "<source xml:lang=\"en\">Please enter a valid state, region or province</source>\n" + "<target xml:lang=\"fr-FR\" state=\"needs-translation\">Veuillez indiquer un état, une région ou une province valide.</target>\n" + "<note>Comment1</note>\n" + "<note annotates=\"target\" from=\"reviewer\">this translation is bad in context</note>\n" + "<note annotates=\"target\" from=\"automation\">OK</note>\n" + "</trans-unit>\n" + "<trans-unit id=\"replaced-id\" resname=\"TEST2\" xml:space=\"preserve\">\n" + "<source xml:lang=\"en\">Content2</source>\n" + "<target xml:lang=\"fr-FR\" state=\"new\">Content2</target>\n" + "<note>Comment2</note>\n" + "</trans-unit>\n" + "</body>\n" + "</file>\n" + "</xliff>\n" + "", xliffWithoutIds); logger.debug("Check the translation kit entities"); TranslationKit translationKit = translationKitRepository.findById(translationKitAsXLIFF.getTranslationKitId()).orElse(null); List<TranslationKitTextUnit> findByTranslationKitId = translationKitTextUnitRepository.findByTranslationKit(translationKit); assertEquals("The translation kit must be of type review", TranslationKit.Type.TRANSLATION, translationKit.getType()); assertEquals("There must be 2 TranslationKitTextUnits", 2, findByTranslationKitId.size()); int idx = 0; assertEquals("Check the first TextUnit by name", findByTranslationKitId.get(idx).getTmTextUnit().getName(), "zuora_error_message_verify_state_province"); assertEquals("Check the exported TmTextUnitVariant by looking at the content", "Veuillez indiquer un état, une région ou une province valide.", findByTranslationKitId.get(idx).getExportedTmTextUnitVariant().getContent()); idx++; assertEquals("Check the second TextUnit by name", findByTranslationKitId.get(idx).getTmTextUnit().getName(), "TEST2"); assertNull("There shouldn't be any TmTextUnitVariant for this TextUnit", findByTranslationKitId.get(idx).getExportedTmTextUnitVariant()); }
@Test @Transactional public void testReviewKit() { tmTestData = new TMTestData(testIdWatcher); logger.debug("Mark on translated string as need review"); tmService.addTMTextUnitCurrentVariant( tmTestData.addCurrentTMTextUnitVariant1FrFR.getTmTextUnit().getId(), tmTestData.addCurrentTMTextUnitVariant1FrFR.getLocale().getId(), tmTestData.addCurrentTMTextUnitVariant1FrFR.getContent(), null, TMTextUnitVariant.Status.REVIEW_NEEDED); Drop drop = dropService.createDrop(tmTestData.repository); TranslationKitAsXliff translationKitAsXLIFF = translationKitService.generateTranslationKitAsXLIFF( drop.getId(), tmTestData.tm.getId(), tmTestData.frFR.getId(), TranslationKit.Type.REVIEW); logger.debug(translationKitAsXLIFF.getContent()); String xliffWithoutIds = XliffUtils.replaceXliffVariableContent(translationKitAsXLIFF.getContent()); logger.info(xliffWithoutIds); assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<xliff version=\"1.2\" xmlns=\"urn:oasis:names:tc:xliff:document:1.2\" xmlns:okp=\"okapi-framework:xliff-extensions\">\n" + "<file original=\"replaced-original\" source-language=\"en\" target-language=\"fr-FR\" datatype=\"x-undefined\" okp:inputEncoding=\"UTF-8\">\n" + "<body>\n" + "<trans-unit id=\"replaced-id\" resname=\"zuora_error_message_verify_state_province\" xml:space=\"preserve\">\n" + "<source xml:lang=\"en\">Please enter a valid state, region or province</source>\n" + "<target xml:lang=\"fr-FR\" state=\"needs-review-translation\">Veuillez indiquer un état, une région ou une province valide.</target>\n" + "<note>Comment1</note>\n" + "<note annotates=\"target\" from=\"automation\">NEEDS REVIEW</note>\n" + "</trans-unit>\n" + "</body>\n" + "</file>\n" + "</xliff>\n" + "", xliffWithoutIds); logger.debug("Check the translation kit entities"); TranslationKit translationKit = translationKitRepository.findById(translationKitAsXLIFF.getTranslationKitId()).orElse(null); List<TranslationKitTextUnit> findByTranslationKitId = translationKitTextUnitRepository.findByTranslationKit(translationKit); assertEquals("The translation kit must be of type review", TranslationKit.Type.REVIEW, translationKit.getType()); assertEquals("There must be 1 TranslationKitTextUnits", 1, findByTranslationKitId.size()); int idx = 0; assertEquals("Check the first TextUnit by name", findByTranslationKitId.get(idx).getTmTextUnit().getName(), "zuora_error_message_verify_state_province"); assertEquals("Check the exported TmTextUnitVariant by looking at the content", "Veuillez indiquer un état, une région ou une province valide.", findByTranslationKitId.get(idx).getExportedTmTextUnitVariant().getContent()); }