From 7aba49054463b9186963baf5b172b21ca04b3a3a Mon Sep 17 00:00:00 2001 From: Joost De Cock Date: Tue, 24 May 2022 18:55:10 +0200 Subject: [PATCH] feat(shared): Use i18n-next for example translations --- .../components/mdx/example/Text/index.js | 15 +++++++-------- .../components/mdx/example/TextOnPath/index.js | 13 ++++++------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/packages/freesewing.shared/components/mdx/example/Text/index.js b/packages/freesewing.shared/components/mdx/example/Text/index.js index 4c31e90a76f..768e6099cab 100644 --- a/packages/freesewing.shared/components/mdx/example/Text/index.js +++ b/packages/freesewing.shared/components/mdx/example/Text/index.js @@ -1,22 +1,21 @@ import React from 'react' -import { strings } from '@freesewing/i18n' +import { useTranslation } from 'next-i18next' const Text = (props) => { - let text = [] + const { t } = useTranslation(['plugin']) + const text = [] // Handle translation let translated = '' for (let string of props.point.attributes.getAsArray('data-text')) { - if (strings[props.language]['plugin.' + string]) - translated += strings[props.language]['plugin.' + string] - else translated += string.toString().replace(/"/g, '"') - translated += ' ' + translated += t(string) + translated += ' ' } // Handle muti-line text if (translated.indexOf('\n') !== -1) { let key = 0 - let lines = translated.split('\n') + const lines = translated.split('\n') text.push({lines.shift()}) - for (let line of lines) { + for (const line of lines) { key++ text.push( { - let text = [] + const { t } = useTranslation(['plugin']) + const 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] - else translated += string.toString().replace(/"/g, '"') + translated += t(string) translated += ' ' } - let textPathProps = { + const textPathProps = { xlinkHref: '#' + props.pathId, 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%' else if (align && align.indexOf('right') > -1) textPathProps.startOffset = '100%'