diff --git a/public/js/cat_source/es6/actions/SegmentActions.js b/public/js/cat_source/es6/actions/SegmentActions.js index 5844a844b2..95d09a7e36 100644 --- a/public/js/cat_source/es6/actions/SegmentActions.js +++ b/public/js/cat_source/es6/actions/SegmentActions.js @@ -301,8 +301,7 @@ const SegmentActions = { if (!currentSegment) return var tagProjectionEnabled = - TagUtils.hasDataOriginalTags(currentSegment.segment) && - !currentSegment.tagged + TagUtils.hasTagsToHide(currentSegment.segment) && !currentSegment.tagged if (SegmentUtils.checkTPEnabled() && tagProjectionEnabled) { SegmentActions.setSegmentAsTagged( currentSegment.sid, diff --git a/public/js/cat_source/es6/components/segments/Editarea.js b/public/js/cat_source/es6/components/segments/Editarea.js index 69ecbf1905..abb5f66101 100644 --- a/public/js/cat_source/es6/components/segments/Editarea.js +++ b/public/js/cat_source/es6/components/segments/Editarea.js @@ -24,7 +24,6 @@ import checkForMissingTags from './utils/DraftMatecatUtils/TagMenu/checkForMissi import updateEntityData from './utils/DraftMatecatUtils/updateEntityData' import LexiqaUtils from '../../utils/lxq.main' import updateLexiqaWarnings from './utils/DraftMatecatUtils/updateLexiqaWarnings' -import insertText from './utils/DraftMatecatUtils/insertText' import {tagSignatures} from './utils/DraftMatecatUtils/tagModel' import SegmentActions from '../../actions/SegmentActions' import getFragmentFromSelection from './utils/DraftMatecatUtils/DraftSource/src/component/handlers/edit/getFragmentFromSelection' @@ -85,7 +84,7 @@ class Editarea extends React.Component { const cleanTranslation = SegmentUtils.checkCurrentSegmentTPEnabled( this.props.segment, ) - ? DraftMatecatUtils.cleanSegmentString(translation) + ? TagUtils.removeAllTagsForGuessTags(translation) : translation // Inizializza Editor State con solo testo const plainEditorState = EditorState.createEmpty(decorator) diff --git a/public/js/cat_source/es6/components/segments/Segment.js b/public/js/cat_source/es6/components/segments/Segment.js index d0e405d9e6..fcc287b492 100644 --- a/public/js/cat_source/es6/components/segments/Segment.js +++ b/public/js/cat_source/es6/components/segments/Segment.js @@ -61,7 +61,7 @@ class Segment extends React.Component { (this.props.segment.status.toLowerCase() === 'draft' || this.props.segment.status.toLowerCase() === 'new') && !TagUtils.checkXliffTagsInText(this.props.segment.translation) && - TagUtils.removeAllTags(this.props.segment.segment) !== '', + TagUtils.removeAllTagsForGuessTags(this.props.segment.segment) !== '', selectedTextObj: null, showActions: false, } diff --git a/public/js/cat_source/es6/components/segments/SegmentPlaceholderLite.js b/public/js/cat_source/es6/components/segments/SegmentPlaceholderLite.js index 618fed8085..12e32b6dd5 100644 --- a/public/js/cat_source/es6/components/segments/SegmentPlaceholderLite.js +++ b/public/js/cat_source/es6/components/segments/SegmentPlaceholderLite.js @@ -3,6 +3,7 @@ import {CompositeDecorator, Editor, EditorState} from 'draft-js' import DraftMatecatUtils from './utils/DraftMatecatUtils' import SegmentUtils from '../../utils/segmentUtils' +import TagUtils from '../../utils/tagUtils' class SegmentPlaceholderLite extends React.Component { constructor(props) { @@ -24,7 +25,7 @@ class SegmentPlaceholderLite extends React.Component { const cleanSource = SegmentUtils.checkCurrentSegmentTPEnabled( this.props.segment, ) - ? DraftMatecatUtils.cleanSegmentString(source) + ? TagUtils.removeAllTagsForGuessTags(source) : source const contentEncodedSource = DraftMatecatUtils.encodeContent( plainEditorStateSource, @@ -40,7 +41,7 @@ class SegmentPlaceholderLite extends React.Component { const cleanTranslation = SegmentUtils.checkCurrentSegmentTPEnabled( this.props.segment, ) - ? DraftMatecatUtils.cleanSegmentString(translation) + ? TagUtils.removeAllTagsForGuessTags(translation) : translation const contentEncodedTarget = DraftMatecatUtils.encodeContent( plainEditorStateTarget, diff --git a/public/js/cat_source/es6/components/segments/SegmentSource.js b/public/js/cat_source/es6/components/segments/SegmentSource.js index eb99893424..542c7cfaef 100644 --- a/public/js/cat_source/es6/components/segments/SegmentSource.js +++ b/public/js/cat_source/es6/components/segments/SegmentSource.js @@ -19,6 +19,7 @@ import {SegmentContext} from './SegmentContext' import Assistant from '../icons/Assistant' import Education from '../icons/Education' import {TERM_FORM_FIELDS} from './SegmentFooterTabGlossary/SegmentFooterTabGlossary' +import TagUtils from '../../utils/tagUtils' class SegmentSource extends React.Component { static contextType = SegmentContext @@ -55,7 +56,7 @@ class SegmentSource extends React.Component { const cleanSource = SegmentUtils.checkCurrentSegmentTPEnabled( this.props.segment, ) - ? DraftMatecatUtils.cleanSegmentString(translation) + ? TagUtils.removeAllTagsForGuessTags(translation) : translation // New EditorState with translation const contentEncoded = DraftMatecatUtils.encodeContent( @@ -121,7 +122,7 @@ class SegmentSource extends React.Component { // If GuessTag enabled, clean string from tag const cleanSource = SegmentUtils.checkCurrentSegmentTPEnabled() - ? DraftMatecatUtils.cleanSegmentString(translation) + ? TagUtils.removeAllTagsForGuessTags(translation) : translation // TODO: get taggedSource from store const contentEncoded = DraftMatecatUtils.encodeContent( diff --git a/public/js/cat_source/es6/components/segments/SegmentsContainer.js b/public/js/cat_source/es6/components/segments/SegmentsContainer.js index a13785676e..e939211d88 100644 --- a/public/js/cat_source/es6/components/segments/SegmentsContainer.js +++ b/public/js/cat_source/es6/components/segments/SegmentsContainer.js @@ -742,8 +742,8 @@ const getSegmentStructure = (segment, sideOpen) => { let source = segment.segment let target = segment.translation if (SegmentUtils.checkCurrentSegmentTPEnabled(segment)) { - source = TagUtils.removeAllTags(source) - target = TagUtils.removeAllTags(target) + source = TagUtils.removeAllTagsForGuessTags(source) + target = TagUtils.removeAllTagsForGuessTags(target) } source = TagUtils.matchTag( diff --git a/public/js/cat_source/es6/components/segments/SimpleEditor.js b/public/js/cat_source/es6/components/segments/SimpleEditor.js index 5e766092d5..a4ca024532 100644 --- a/public/js/cat_source/es6/components/segments/SimpleEditor.js +++ b/public/js/cat_source/es6/components/segments/SimpleEditor.js @@ -18,7 +18,7 @@ class SimpleEditor extends React.Component { const sid = segment.sid let htmlText = SegmentUtils.checkCurrentSegmentTPEnabled(segment) - ? TagUtils.removeAllTags(text) + ? TagUtils.removeAllTagsForGuessTags(text) : text htmlText = TagUtils.matchTag( diff --git a/public/js/cat_source/es6/components/segments/utils/DraftMatecatUtils/tagModel.js b/public/js/cat_source/es6/components/segments/utils/DraftMatecatUtils/tagModel.js index c9a1a0a767..502b5d0b0e 100644 --- a/public/js/cat_source/es6/components/segments/utils/DraftMatecatUtils/tagModel.js +++ b/public/js/cat_source/es6/components/segments/utils/DraftMatecatUtils/tagModel.js @@ -334,7 +334,9 @@ const isToReplaceForLexiqa = (tagType, isClosure = false) => { const getXliffRegExpression = () => { return /(<\s*\/*\s*(g|x|bx|ex|bpt|ept|ph|it|mrk)\s*((?!<|<).)*?>)/gim } - +const getPhGuessTagsXliffRegExpression = () => { + return /(<\s*\/*\s*(ph.+?ctype=["'](?:x-twig|x-ruby-on-rails|x-snails|x-percent-snails|x-percent-number-snails|x-percentages|x-sprintf|x-smart-count|x-double-square-brackets|x-dollar-curly-brackets|x-percent-variable|x-square-sprintf)["'])\s*((?!<|<).)*?>)/ +} const getTagSignature = (tagType) => { return tagSignatures[tagType] } @@ -353,6 +355,7 @@ export { getCorrectTag, getSplitPointTag, getXliffRegExpression, + getPhGuessTagsXliffRegExpression, isToReplaceForLexiqa, getTagSignature, } diff --git a/public/js/cat_source/es6/components/segments/utils/translationMatches.js b/public/js/cat_source/es6/components/segments/utils/translationMatches.js index 2514853a73..0a1b205765 100644 --- a/public/js/cat_source/es6/components/segments/utils/translationMatches.js +++ b/public/js/cat_source/es6/components/segments/utils/translationMatches.js @@ -80,7 +80,7 @@ let TranslationMatches = { translation = currentContribution.translation if (SegmentUtils.checkCurrentSegmentTPEnabled(segmentObj)) { if (parseInt(match) !== 100) { - translation = DraftMatecatUtils.cleanSegmentString(translation) + translation = TagUtils.removeAllTagsForGuessTags(translation) } else { SegmentActions.disableTPOnSegment(segmentObj) } diff --git a/public/js/cat_source/es6/utils/segmentUtils.js b/public/js/cat_source/es6/utils/segmentUtils.js index c216d7b4a4..54ecd18c9a 100644 --- a/public/js/cat_source/es6/utils/segmentUtils.js +++ b/public/js/cat_source/es6/utils/segmentUtils.js @@ -44,9 +44,11 @@ const SegmentUtils = { : SegmentStore.getCurrentSegment() if (currentSegment && this.checkTPEnabled()) { // If the segment has tag projection enabled (has tags and has the enableTP class) - var segmentNoTags = TagUtils.removeAllTags(currentSegment.segment) + var segmentNoTags = TagUtils.removeAllTagsForGuessTags( + currentSegment.segment, + ) var tagProjectionEnabled = - TagUtils.hasDataOriginalTags(currentSegment.segment) && + TagUtils.hasTagsToHide(currentSegment.segment) && !currentSegment.tagged && segmentNoTags !== '' // If the segment has already be tagged diff --git a/public/js/cat_source/es6/utils/tagUtils.js b/public/js/cat_source/es6/utils/tagUtils.js index 1d1c22389f..123119c7f3 100644 --- a/public/js/cat_source/es6/utils/tagUtils.js +++ b/public/js/cat_source/es6/utils/tagUtils.js @@ -1,11 +1,10 @@ import _ from 'lodash' import {Base64} from 'js-base64' - -// import SegmentStore from '../stores/SegmentStore'; import TextUtils from './textUtils' import { tagSignatures, getXliffRegExpression, + getPhGuessTagsXliffRegExpression, } from '../components/segments/utils/DraftMatecatUtils/tagModel' const TAGS_UTILS = { @@ -399,27 +398,34 @@ const TAGS_UTILS = { }, /** - * Check if the data-original attribute in the source of the segment contains special tags (Ex: ) - * (Note that in the data-original attribute there are the &lt instead of <) + * Check the string has tags to hide by the guess tags * @param segmentSource * @returns {boolean} */ - hasDataOriginalTags: function (segmentSource) { - var originalText = segmentSource - const reg = getXliffRegExpression() - return !_.isUndefined(originalText) && reg.test(originalText) + hasTagsToHide: function (originalText) { + if (originalText) { + const stringWithGuessTag = this.removeAllTagsForGuessTags(originalText) + return originalText !== stringWithGuessTag + } + return false }, /** * Remove all xliff source tags from the string + * less the placeholder we want to show * @param currentString : string to parse * @returns the decoded String - * TODO: Same of function cleanTextFromTag */ - removeAllTags: function (currentString) { + removeAllTagsForGuessTags: function (currentString) { if (currentString) { - var regExp = getXliffRegExpression() - currentString = currentString.replace(regExp, '') + const regExp = getXliffRegExpression() + const regExpPh = getPhGuessTagsXliffRegExpression() + currentString = currentString.replace(regExp, (match, contents) => { + if (regExpPh.test(match)) { + return match + } + return '' + }) return currentString } else { return ''