Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Guess Tags #2813

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions public/js/cat_source/es6/actions/SegmentActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions public/js/cat_source/es6/components/segments/Editarea.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion public/js/cat_source/es6/components/segments/Segment.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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,
Expand All @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions public/js/cat_source/es6/components/segments/SegmentSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,9 @@ const isToReplaceForLexiqa = (tagType, isClosure = false) => {
const getXliffRegExpression = () => {
return /(&lt;\s*\/*\s*(g|x|bx|ex|bpt|ept|ph|it|mrk)\s*((?!&lt;|<).)*?&gt;)/gim
}

const getPhGuessTagsXliffRegExpression = () => {
return /(&lt;\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*((?!&lt;|<).)*?&gt;)/
}
const getTagSignature = (tagType) => {
return tagSignatures[tagType]
}
Expand All @@ -353,6 +355,7 @@ export {
getCorrectTag,
getSplitPointTag,
getXliffRegExpression,
getPhGuessTagsXliffRegExpression,
isToReplaceForLexiqa,
getTagSignature,
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
6 changes: 4 additions & 2 deletions public/js/cat_source/es6/utils/segmentUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 18 additions & 12 deletions public/js/cat_source/es6/utils/tagUtils.js
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down Expand Up @@ -399,27 +398,34 @@ const TAGS_UTILS = {
},

/**
* Check if the data-original attribute in the source of the segment contains special tags (Ex: <g id=1></g>)
* (Note that in the data-original attribute there are the &amp;lt instead of &lt)
* 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 ''
Expand Down