2020-04-18 18:14:09 +02:00
|
|
|
import React from 'react'
|
|
|
|
import { strings } from '@freesewing/i18n'
|
|
|
|
|
|
|
|
const TextOnPath = (props) => {
|
|
|
|
let text = []
|
|
|
|
// Handle translation
|
|
|
|
let translated = ''
|
|
|
|
for (let string of props.path.attributes.getAsArray('data-text')) {
|
|
|
|
if (strings[props.language]['plugin.' + string])
|
|
|
|
translated += strings[props.language]['plugin.' + string]
|
2020-07-12 15:27:21 +02:00
|
|
|
else translated += string.toString().replace(/"/g, '"')
|
2020-04-18 18:14:09 +02:00
|
|
|
translated += ' '
|
|
|
|
}
|
|
|
|
let textPathProps = {
|
|
|
|
xlinkHref: '#' + props.pathId,
|
|
|
|
startOffset: '0%'
|
|
|
|
}
|
|
|
|
let align = props.path.attributes.get('data-text-class')
|
|
|
|
if (align && align.indexOf('center') > -1) textPathProps.startOffset = '50%'
|
|
|
|
else if (align && align.indexOf('right') > -1) textPathProps.startOffset = '100%'
|
|
|
|
|
|
|
|
return (
|
|
|
|
<text>
|
|
|
|
<textPath {...textPathProps}>
|
|
|
|
<tspan {...props.path.attributes.asPropsIfPrefixIs('data-text-')}>{translated}</tspan>
|
|
|
|
</textPath>
|
|
|
|
</text>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default TextOnPath
|