1
0
Fork 0

feat(shared): Use i18n-next for example translations

This commit is contained in:
Joost De Cock 2022-05-24 18:55:10 +02:00
parent a867666b9d
commit 7aba490544
2 changed files with 13 additions and 15 deletions

View file

@ -1,22 +1,21 @@
import React from 'react' import React from 'react'
import { strings } from '@freesewing/i18n' import { useTranslation } from 'next-i18next'
const Text = (props) => { const Text = (props) => {
let text = [] const { t } = useTranslation(['plugin'])
const text = []
// Handle translation // Handle translation
let translated = '' let translated = ''
for (let string of props.point.attributes.getAsArray('data-text')) { for (let string of props.point.attributes.getAsArray('data-text')) {
if (strings[props.language]['plugin.' + string]) translated += t(string)
translated += strings[props.language]['plugin.' + string] translated += ' '
else translated += string.toString().replace(/"/g, '"')
translated += ' '
} }
// Handle muti-line text // Handle muti-line text
if (translated.indexOf('\n') !== -1) { if (translated.indexOf('\n') !== -1) {
let key = 0 let key = 0
let lines = translated.split('\n') const lines = translated.split('\n')
text.push(<tspan key={'tspan-' + key}>{lines.shift()}</tspan>) text.push(<tspan key={'tspan-' + key}>{lines.shift()}</tspan>)
for (let line of lines) { for (const line of lines) {
key++ key++
text.push( text.push(
<tspan <tspan

View file

@ -1,21 +1,20 @@
import React from 'react' import React from 'react'
import { strings } from '@freesewing/i18n' import { useTranslation } from 'next-i18next'
const TextOnPath = (props) => { const TextOnPath = (props) => {
let text = [] const { t } = useTranslation(['plugin'])
const text = []
// Handle translation // Handle translation
let translated = '' let translated = ''
for (let string of props.path.attributes.getAsArray('data-text')) { for (let string of props.path.attributes.getAsArray('data-text')) {
if (strings[props.language]['plugin.' + string]) translated += t(string)
translated += strings[props.language]['plugin.' + string]
else translated += string.toString().replace(/&quot;/g, '"')
translated += ' ' translated += ' '
} }
let textPathProps = { const textPathProps = {
xlinkHref: '#' + props.pathId, xlinkHref: '#' + props.pathId,
startOffset: '0%' startOffset: '0%'
} }
let align = props.path.attributes.get('data-text-class') const align = props.path.attributes.get('data-text-class')
if (align && align.indexOf('center') > -1) textPathProps.startOffset = '50%' if (align && align.indexOf('center') > -1) textPathProps.startOffset = '50%'
else if (align && align.indexOf('right') > -1) textPathProps.startOffset = '100%' else if (align && align.indexOf('right') > -1) textPathProps.startOffset = '100%'