From 5c99dea188499f23fd4bbe3d0e0122d282986087 Mon Sep 17 00:00:00 2001 From: riccio82 Date: Thu, 15 Jun 2023 12:38:02 +0200 Subject: [PATCH 1/4] Improve Guess Tags --- .../es6/components/segments/Editarea.js | 3 +-- .../es6/components/segments/Segment.js | 2 +- .../segments/SegmentPlaceholderLite.js | 5 +++-- .../es6/components/segments/SegmentSource.js | 5 +++-- .../components/segments/SegmentsContainer.js | 4 ++-- .../es6/components/segments/SimpleEditor.js | 2 +- .../utils/DraftMatecatUtils/tagModel.js | 5 ++++- .../segments/utils/translationMatches.js | 2 +- public/js/cat_source/es6/utils/segmentUtils.js | 4 +++- public/js/cat_source/es6/utils/tagUtils.js | 17 +++++++++++------ 10 files changed, 30 insertions(+), 19 deletions(-) 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 c5fa2487be..b28a0cca28 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)["'])\s*((?!<|<).)*?>)/gim +} 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..a18b73f284 100644 --- a/public/js/cat_source/es6/utils/segmentUtils.js +++ b/public/js/cat_source/es6/utils/segmentUtils.js @@ -44,7 +44,9 @@ 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) && !currentSegment.tagged && diff --git a/public/js/cat_source/es6/utils/tagUtils.js b/public/js/cat_source/es6/utils/tagUtils.js index 72d6201584..52f29d2c22 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 = { @@ -412,14 +411,20 @@ const TAGS_UTILS = { /** * 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 '' From af7e84e65c2d33ae1f6b6bb481ae84600ac43968 Mon Sep 17 00:00:00 2001 From: riccio82 Date: Thu, 15 Jun 2023 13:06:16 +0200 Subject: [PATCH 2/4] Guess tags: fix regexp --- .../es6/components/segments/utils/DraftMatecatUtils/tagModel.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 b28a0cca28..22999f2f25 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 @@ -335,7 +335,7 @@ 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)["'])\s*((?!<|<).)*?>)/gim + 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)["'])\s*((?!<|<).)*?>)/ } const getTagSignature = (tagType) => { return tagSignatures[tagType] From a02ba1fa56e108ea6e7bc8621b96ace3396add9c Mon Sep 17 00:00:00 2001 From: riccio82 Date: Fri, 16 Jun 2023 18:01:58 +0200 Subject: [PATCH 3/4] Do not show Guess Tags button if not necessary --- public/js/cat_source/es6/actions/SegmentActions.js | 3 +-- public/js/cat_source/es6/utils/segmentUtils.js | 2 +- public/js/cat_source/es6/utils/tagUtils.js | 13 +++++++------ 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/public/js/cat_source/es6/actions/SegmentActions.js b/public/js/cat_source/es6/actions/SegmentActions.js index 92f9407db7..4469183920 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/utils/segmentUtils.js b/public/js/cat_source/es6/utils/segmentUtils.js index a18b73f284..54ecd18c9a 100644 --- a/public/js/cat_source/es6/utils/segmentUtils.js +++ b/public/js/cat_source/es6/utils/segmentUtils.js @@ -48,7 +48,7 @@ const SegmentUtils = { 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 52f29d2c22..1a45ba83d4 100644 --- a/public/js/cat_source/es6/utils/tagUtils.js +++ b/public/js/cat_source/es6/utils/tagUtils.js @@ -398,15 +398,16 @@ 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 }, /** From 64f19e9cbcafc85d577f7d62b17e1122b700d041 Mon Sep 17 00:00:00 2001 From: riccio82 Date: Mon, 17 Jul 2023 09:16:26 +0200 Subject: [PATCH 4/4] Guess tags: add new c-type tag --- .../es6/components/segments/utils/DraftMatecatUtils/tagModel.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 22999f2f25..e7f4c1d152 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 @@ -335,7 +335,7 @@ 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)["'])\s*((?!<|<).)*?>)/ + 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]