@Override public AlignmentStatus getAlignmentStatus() { for (LocaleId loc : parent.getTargetLocales()) { ISegments trgSegs = parent.getTargetSegments(loc); if (trgSegs.getAlignmentStatus() == AlignmentStatus.NOT_ALIGNED) { return AlignmentStatus.NOT_ALIGNED; } } return AlignmentStatus.ALIGNED; }
/** * Removes all inline tags in the source (or optionally the target) text unit resource. * @param textUnit the given text unit * @param removeTargetCodes - remove target codes? */ public static void removeCodes(ITextUnit textUnit, boolean removeTargetCodes) { Logger localLogger = LoggerFactory.getLogger(TextUnitUtil.class); if (textUnit == null) { localLogger.warn("Text unit is null."); return; } // remove source inline codes TextContainer stc = textUnit.getSource(); removeCodes(stc); // if requested and if targets exist remove inline codes for all targets if (removeTargetCodes && !textUnit.getTargetLocales().isEmpty()) { for (LocaleId locale: textUnit.getTargetLocales()) { TextContainer ttc = textUnit.getTarget(locale); removeCodes(ttc); } } }
Set<LocaleId> targetLocales = tu2.getTargetLocales(); if(targetLocales.size()==1 && !targetLocales.contains(targetLocale)){ LocaleId overridenLocaleId = targetLocales.iterator().next(); if (tu1.getTargetLocales().size() > tu2.getTargetLocales().size()-1){ LOGGER.warn("compareTextUnits warning: ITextUnit targetCount difference. Tu1 has more targets than Tu2"); return false; }else if (tu2.getTargetLocales().size()-1 > tu1.getTargetLocales().size()){ LOGGER.warn("compareTextUnits warning: ITextUnit targetCount difference. Tu2 has more targets than Tu1"); return false; if (tu1.getTargetLocales().size() > tu2.getTargetLocales().size()){ LOGGER.warn("compareTextUnits warning: ITextUnit targetCount difference. Tu1 has more targets than Tu2"); return false; }else if (tu2.getTargetLocales().size() > tu1.getTargetLocales().size()){ LOGGER.warn("compareTextUnits warning: ITextUnit targetCount difference. Tu2 has more targets than Tu1"); return false; for (LocaleId locId : tu1.getTargetLocales()) { if (!compareTextContainers(tu1.getTarget(locId), tu2.getTarget(locId))) { return false;
public static void unsegmentTU(ITextUnit tu) { tu.getSource().joinAll(); for (LocaleId trgLoc : tu.getTargetLocales()) { tu.getTarget(trgLoc).joinAll(); } } }
public static boolean needsPreserveWhitespaces(ITextUnit tu) { if (needsPreserveWhitespaces(tu.getSource())) return true; for (LocaleId trgLoc : tu.getTargetLocales()) { if (needsPreserveWhitespaces(tu.getTarget(trgLoc))) return true; } return false; }
for (LocaleId locId : tu.getTargetLocales()) { tu.removeTarget(locId); if (!Util.isEmpty(targetLocales)) { ITextUnit tu = event.getTextUnit(); for (LocaleId locId : tu.getTargetLocales()) { if (!targetLocales.contains(locId)) { tu.removeTarget(locId); if (event.getTextUnit().getTargetLocales().isEmpty()) { return Event.NOOP_EVENT;
if (tu.getTargetLocales().isEmpty()) { int segCount = 0; for (Segment srcSeg: tu.getSourceSegments()) { for (LocaleId variantTrgLoc : tu.getTargetLocales()) { for (LocaleId l : tu.getTargetLocales()) { Segment trgSeg = alignedSegments.getCorrespondingTarget(srcSeg, l); if (trgSeg != null) {
/** * Simplifies all possible tags in the source part of a given text unit resource. If the * TextUnit has a target then skip simplification. * @param textUnit the given text unit * @param rules rules for the data-driven simplification * @param removeLeadingTrailingCodes true to remove leading and/or trailing codes * of the source part and place their text in the corresponding inter-segment TextPart. * @param mergeCodes true to merge adjacent codes, false to leave as-is */ public static void simplifyCodesPostSegmentation(ITextUnit textUnit, String rules, boolean removeLeadingTrailingCodes, boolean mergeCodes) { if (textUnit == null || TextUnitUtil.isEmpty(textUnit) || !textUnit.isTranslatable()) { return; } // source simplifyCodesPostSegmentation(textUnit.getSource(), rules, removeLeadingTrailingCodes, mergeCodes); // codes can become desynchronized in target - depend on TextUnitMerger // to align codes and reset matching id's for (LocaleId tl : textUnit.getTargetLocales()) { simplifyCodesPostSegmentation(textUnit.getTarget(tl), rules, removeLeadingTrailingCodes, mergeCodes); } }
@Override public void alignCollapseAll(LocaleId trgLoc) { ContainerIterator ci = new ContainerIterator(trgLoc); // keeping track of collapsed containers to check which to set to // ALIGNED LinkedList<TextContainer> collapsed = new LinkedList<TextContainer>(); if (ci.hasSource()) { ci.getSource().joinAll(); ci.getSource().setHasBeenSegmentedFlag(false); collapsed.add(ci.getSource()); } if (ci.hasTarget()) { ci.getTarget().joinAll(); ci.getTarget().setHasBeenSegmentedFlag(false); collapsed.add(ci.getTarget()); } // mark target/source pairs aligned if both have been collapsed TextContainer src, trg; for (LocaleId loc : parent.getTargetLocales()) { src = getSource(loc); if (collapsed.contains(src)) { trg = parent.getTarget(loc); if (collapsed.contains(trg)) { trg.getSegments().setAlignmentStatus(AlignmentStatus.ALIGNED); // TODO: check that this is the desired behavior trg.getFirstSegment().id = src.getFirstSegment().getId(); } } } }
if (textUnit.getTargetLocales().size() > 0) { localLogger.warn(String.format("Text unit %s has one or more targets, " + "desynchronization of codes in source and targets is possible.", textUnit.getId()));
Set<LocaleId> locales = item.getTargetLocales(); Set<String> names = item.getPropertyNames();
private void convertRefs (Event event) { if ( event.isMultiEvent() ) { MultiEvent me = event.getMultiEvent(); for (Event e : me) { convertRefs(e); } } else { if ( event.isTextUnit() ) { ITextUnit tu = event.getTextUnit(); convertTextContainer(tu.getSource()); for (LocaleId locId : tu.getTargetLocales()) { convertTextContainer(tu.getTarget(locId)); } } ISkeleton skel = event.getResource().getSkeleton(); subFilter.convertRefsInSkeleton(skel); } }
private void resolveTU (ITextUnit tu) { MetricsAnnotation ma = tu.getAnnotation(MetricsAnnotation.class); resolve(ma, true); TextContainer tc = tu.getSource(); ma = tc.getAnnotation(MetricsAnnotation.class); resolve(ma, false); for (Segment seg : tc.getSegments()) { ma = seg.getAnnotation(MetricsAnnotation.class); resolve(ma, false); } for (LocaleId trgLoc : tu.getTargetLocales()) { tc = tu.getTarget(trgLoc); ma = tc.getAnnotation(MetricsAnnotation.class); resolve(ma, false); for (Segment seg : tc.getSegments()) { ma = seg.getAnnotation(MetricsAnnotation.class); resolve(ma, false); } } }
for (LocaleId t : tu.getTargetLocales()) {
AltTranslation bestMatch = null; for ( LocaleId loc : tu.getTargetLocales() ) {