From 4c17255a5891b836e8212ba669fd23bfe43b41df Mon Sep 17 00:00:00 2001 From: Joost De Cock Date: Tue, 8 Feb 2022 20:49:19 +0100 Subject: [PATCH] wip(lab): Work on i18n-next --- .../components/workbench/draft/error.js | 22 ++++++++----- .../workbench/draft/text-on-path/index.js | 5 ++- .../components/workbench/draft/text/index.js | 5 ++- .../workbench/inputs/design-option-count.js | 8 +++-- .../workbench/inputs/design-option-list.js | 6 ++-- .../workbench/inputs/design-option-pct-deg.js | 10 +++--- .../workbench/measurements/index.js | 2 +- .../menu/core-settings/core-setting-bool.js | 6 ++-- .../menu/core-settings/core-setting-list.js | 4 ++- .../menu/core-settings/core-setting-mm.js | 6 ++-- .../menu/core-settings/core-setting-nr.js | 6 ++-- .../menu/core-settings/core-setting-only.js | 8 +++-- .../core-settings/core-setting-sa-bool.js | 10 +++--- .../menu/core-settings/core-setting-sa-mm.js | 6 ++-- .../workbench/menu/core-settings/index.js | 31 +++++++++++-------- .../workbench/menu/core-settings/setting.js | 29 ++++++++--------- .../workbench/menu/design-options/index.js | 4 ++- .../menu/design-options/option-group.js | 4 ++- .../menu/design-options/option-sub-group.js | 4 ++- .../workbench/menu/design-options/option.js | 18 ++++++----- .../components/workbench/menu/xray/disable.js | 29 ++++++++++------- .../components/workbench/menu/xray/index.js | 8 +++-- .../components/workbench/menu/xray/list.js | 10 +++--- .../components/workbench/menu/xray/path.js | 5 +-- .../components/workbench/menu/xray/reset.js | 25 +++++++++------ .../freesewing.shared/config/i18n.config.mjs | 4 +++ 26 files changed, 170 insertions(+), 105 deletions(-) diff --git a/packages/freesewing.shared/components/workbench/draft/error.js b/packages/freesewing.shared/components/workbench/draft/error.js index ff05f20ea30..43fc2e2f316 100644 --- a/packages/freesewing.shared/components/workbench/draft/error.js +++ b/packages/freesewing.shared/components/workbench/draft/error.js @@ -1,15 +1,21 @@ import Robot from 'shared/components/robot/index.js' import Events from './events.js' +import { useTranslation } from 'next-i18next' -const Error = props => ( -
-
-

{props.app.t('errors.something')}

-
+const Error = props => { + const { t } = useTranslation(['errors']) + + return ( +
+
+

{t('errors:something')}

+
+
+
- -
-) + ) +} + export default Error diff --git a/packages/freesewing.shared/components/workbench/draft/text-on-path/index.js b/packages/freesewing.shared/components/workbench/draft/text-on-path/index.js index 29eb91d25c0..9714cfb95b5 100644 --- a/packages/freesewing.shared/components/workbench/draft/text-on-path/index.js +++ b/packages/freesewing.shared/components/workbench/draft/text-on-path/index.js @@ -1,9 +1,12 @@ +import { useTranslation } from 'next-i18next' + const TextOnPath = (props) => { + const { t } = useTranslation(['app']) const text = [] // Handle translation (and spaces) let translated = '' for (let string of props.path.attributes.getAsArray('data-text')) { - translated += props.app.t(string, false, props.locale).replace(/"/g, '"') + ' ' + translated += t(string).replace(/"/g, '"') + ' ' } const textPathProps = { xlinkHref: '#' + props.pathId, diff --git a/packages/freesewing.shared/components/workbench/draft/text/index.js b/packages/freesewing.shared/components/workbench/draft/text/index.js index c75044569c1..7671e38e2b1 100644 --- a/packages/freesewing.shared/components/workbench/draft/text/index.js +++ b/packages/freesewing.shared/components/workbench/draft/text/index.js @@ -1,9 +1,12 @@ +import { useTranslation } from 'next-i18next' + const Text = (props) => { + const { t } = useTranslation(['app']) let text = [] // Handle translation let translated = '' for (let string of props.point.attributes.getAsArray('data-text')) { - translated += props.app.t(string.toString(), false, props.locale).replace(/"/g, '"') + ' ' + translated += t(string.toString()).replace(/"/g, '"') + ' ' } // Handle muti-line text if (translated.indexOf('\n') !== -1) { diff --git a/packages/freesewing.shared/components/workbench/inputs/design-option-count.js b/packages/freesewing.shared/components/workbench/inputs/design-option-count.js index d69c2693307..20bb961ec3a 100644 --- a/packages/freesewing.shared/components/workbench/inputs/design-option-count.js +++ b/packages/freesewing.shared/components/workbench/inputs/design-option-count.js @@ -1,6 +1,7 @@ import { useState } from 'react' import ClearIcon from 'shared/components/icons/clear.js' import EditIcon from 'shared/components/icons/edit.js' +import { useTranslation } from 'next-i18next' const EditCount = props => (
@@ -25,6 +26,7 @@ const EditCount = props => ( const DesignOptionCount = props => { + const { t } = useTranslation(['app']) const { count, max, min } = props.pattern.config.options[props.option] const val = (typeof props.gist?.options?.[props.option] === 'undefined') ? count @@ -53,7 +55,7 @@ const DesignOptionCount = props => { min={min} max={max} setEditCount={setEditCount} - t={props.app.t} + t={t} /> : ( <> @@ -84,7 +86,7 @@ const DesignOptionCount = props => {
))}
- {props.app.t('cfp.thingIsDisabled', { thing: props.app.t('settings.xray.title') })} + {t('cfp:thingIsDisabled', { thing: t('settings:xray.title') })} ) diff --git a/packages/freesewing.shared/components/workbench/menu/xray/list.js b/packages/freesewing.shared/components/workbench/menu/xray/list.js index aa67a5e96d2..1134dee3be3 100644 --- a/packages/freesewing.shared/components/workbench/menu/xray/list.js +++ b/packages/freesewing.shared/components/workbench/menu/xray/list.js @@ -5,6 +5,7 @@ import SearchIcon from 'shared/components/icons/search.js' import { Ul, Li, Details, Summary, SumDiv, Deg } from 'shared/components/workbench/menu' import Path from './path.js' import Point from './point.js' +import { useTranslation } from 'next-i18next' const types = { paths: Path, @@ -12,8 +13,9 @@ const types = { } const XrayList = props => { + const { t } = useTranslation(['app', 'parts']) - let title = props.app.t(`parts.${props.partName}`) + let title = t(`parts.${props.partName}`) if (title !== props.partName || true) title + ` (${props.partName})` const part = props.gist.xray.parts[props.partName] @@ -36,7 +38,7 @@ const XrayList = props => {