Fix string translations in multiple views and SVG export and theming in SVG draft view (#244)
Fixes #227 Fixes #78 Reviewed-on: https://codeberg.org/freesewing/freesewing/pulls/244 Reviewed-by: Joost De Cock <joostdecock@noreply.codeberg.org> Co-authored-by: Jonathan Haas <haasjona@gmail.com> Co-committed-by: Jonathan Haas <haasjona@gmail.com>
This commit is contained in:
parent
04a0b4b099
commit
a9f5ba5392
6 changed files with 29 additions and 8 deletions
|
@ -13,7 +13,7 @@ export const MovablePattern = ({
|
||||||
update,
|
update,
|
||||||
fitImmovable = false,
|
fitImmovable = false,
|
||||||
immovable = [],
|
immovable = [],
|
||||||
t,
|
strings,
|
||||||
}) => {
|
}) => {
|
||||||
const svgRef = useRef(null)
|
const svgRef = useRef(null)
|
||||||
if (!renderProps) return null
|
if (!renderProps) return null
|
||||||
|
@ -91,7 +91,7 @@ export const MovablePattern = ({
|
||||||
stackName,
|
stackName,
|
||||||
stack,
|
stack,
|
||||||
components,
|
components,
|
||||||
t,
|
strings,
|
||||||
movable: !immovable.includes(stackName),
|
movable: !immovable.includes(stackName),
|
||||||
layout: layout.stacks[stackName],
|
layout: layout.stacks[stackName],
|
||||||
updateLayout,
|
updateLayout,
|
||||||
|
@ -161,7 +161,7 @@ export const MovableStack = ({
|
||||||
stackName,
|
stackName,
|
||||||
stack,
|
stack,
|
||||||
components,
|
components,
|
||||||
t,
|
strings,
|
||||||
movable = true,
|
movable = true,
|
||||||
layout,
|
layout,
|
||||||
updateLayout,
|
updateLayout,
|
||||||
|
@ -345,7 +345,7 @@ export const MovableStack = ({
|
||||||
<Group id={`stack-${stackName}`} {...getProps(stack)} ref={stackRef}>
|
<Group id={`stack-${stackName}`} {...getProps(stack)} ref={stackRef}>
|
||||||
<Group id={`stack-inner-${stackName}`} ref={innerRef}>
|
<Group id={`stack-inner-${stackName}`} ref={innerRef}>
|
||||||
{[...stack.parts].map((part, key) => (
|
{[...stack.parts].map((part, key) => (
|
||||||
<Part {...{ components, t, part, stackName, settings }} key={key} />
|
<Part {...{ components, strings, part, stackName, settings }} key={key} />
|
||||||
))}
|
))}
|
||||||
</Group>
|
</Group>
|
||||||
{movable && (
|
{movable && (
|
||||||
|
|
|
@ -6,6 +6,9 @@ import { Null } from '@freesewing/react/components/Null'
|
||||||
import { ZoomablePattern } from '../ZoomablePattern.mjs'
|
import { ZoomablePattern } from '../ZoomablePattern.mjs'
|
||||||
import { PatternLayout } from '../PatternLayout.mjs'
|
import { PatternLayout } from '../PatternLayout.mjs'
|
||||||
import { DraftErrorHandler } from './DraftErrorHandler.mjs'
|
import { DraftErrorHandler } from './DraftErrorHandler.mjs'
|
||||||
|
import { i18nPlugin } from '@freesewing/plugin-i18n'
|
||||||
|
import { themePlugin } from '@freesewing/plugin-theme'
|
||||||
|
import { translateStrings } from '../../../Pattern/index.mjs'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The draft view allows users to tweak their pattern
|
* The draft view allows users to tweak their pattern
|
||||||
|
@ -39,7 +42,13 @@ export const DraftView = ({ Design, state, update, config, plugins = [], PluginO
|
||||||
/*
|
/*
|
||||||
* First, attempt to draft
|
* First, attempt to draft
|
||||||
*/
|
*/
|
||||||
const { pattern, failure, errors } = draft(Design, state.settings, plugins)
|
const { pattern, failure, errors } = draft(Design, state.settings, plugins, (pattern) => {
|
||||||
|
if (state.ui?.renderer === 'svg') {
|
||||||
|
const strings = bundlePatternTranslations(pattern.designConfig.data.id)
|
||||||
|
pattern.use(i18nPlugin, (t) => translateStrings([t], strings))
|
||||||
|
pattern.use(themePlugin)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Create object holding strings for translation
|
* Create object holding strings for translation
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
// Dependencies
|
// Dependencies
|
||||||
import { linkClasses, horFlexClasses, patternUrlFromState } from '@freesewing/utils'
|
import { linkClasses, horFlexClasses, patternUrlFromState } from '@freesewing/utils'
|
||||||
import { handleExport } from '../../lib/export/index.mjs'
|
import { handleExport } from '../../lib/export/index.mjs'
|
||||||
|
import { translateStrings } from '../../../Pattern/index.mjs'
|
||||||
|
import { bundlePatternTranslations } from '../../lib/index.mjs'
|
||||||
// Hooks
|
// Hooks
|
||||||
import React, { useState } from 'react'
|
import React, { useState } from 'react'
|
||||||
// Components
|
// Components
|
||||||
|
@ -33,6 +35,8 @@ export const ExportView = (props) => {
|
||||||
b: `${site}${patternUrlFromState(state, false)}`,
|
b: `${site}${patternUrlFromState(state, false)}`,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const translations = bundlePatternTranslations(props.design)
|
||||||
|
|
||||||
const exportProps = {
|
const exportProps = {
|
||||||
design: props.design,
|
design: props.design,
|
||||||
Design: props.Design,
|
Design: props.Design,
|
||||||
|
@ -42,6 +46,7 @@ export const ExportView = (props) => {
|
||||||
setFormat,
|
setFormat,
|
||||||
startLoading: update.startLoading,
|
startLoading: update.startLoading,
|
||||||
stopLoading: update.stopLoading,
|
stopLoading: update.stopLoading,
|
||||||
|
t: (string) => translateStrings([string], translations),
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -3,7 +3,7 @@ import React from 'react'
|
||||||
import { defaultPrintSettings } from '../../lib/export/index.mjs'
|
import { defaultPrintSettings } from '../../lib/export/index.mjs'
|
||||||
import { tilerPlugin } from '../../lib/export/plugin-tiler.mjs'
|
import { tilerPlugin } from '../../lib/export/plugin-tiler.mjs'
|
||||||
import { get } from '@freesewing/utils'
|
import { get } from '@freesewing/utils'
|
||||||
import { draft } from '../../lib/index.mjs'
|
import { bundlePatternTranslations, draft } from '../../lib/index.mjs'
|
||||||
// Components
|
// Components
|
||||||
import { PatternLayout } from '../PatternLayout.mjs'
|
import { PatternLayout } from '../PatternLayout.mjs'
|
||||||
import { MovablePattern } from '../MovablePattern.mjs'
|
import { MovablePattern } from '../MovablePattern.mjs'
|
||||||
|
@ -25,6 +25,11 @@ export const LayoutView = (props) => {
|
||||||
*/
|
*/
|
||||||
const { pattern, failure, errors } = draft(Design, settings, [tilerPlugin(pageSettings)])
|
const { pattern, failure, errors } = draft(Design, settings, [tilerPlugin(pageSettings)])
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Create object holding strings for translation
|
||||||
|
*/
|
||||||
|
const strings = bundlePatternTranslations(pattern.designConfig.data.id)
|
||||||
|
|
||||||
const output = (
|
const output = (
|
||||||
<>
|
<>
|
||||||
<DraftErrorHandler {...{ failure, errors }} />
|
<DraftErrorHandler {...{ failure, errors }} />
|
||||||
|
@ -33,6 +38,7 @@ export const LayoutView = (props) => {
|
||||||
update,
|
update,
|
||||||
renderProps: pattern.getRenderProps(),
|
renderProps: pattern.getRenderProps(),
|
||||||
immovable: ['pages'],
|
immovable: ['pages'],
|
||||||
|
strings: strings,
|
||||||
state,
|
state,
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|
|
@ -52,9 +52,10 @@ export const bundlePatternTranslations = (design) => {
|
||||||
* @param {array} plugins - Any (extra) plugins to load into the pattern
|
* @param {array} plugins - Any (extra) plugins to load into the pattern
|
||||||
* @return {object} data - The drafted pattern, along with errors and failure data
|
* @return {object} data - The drafted pattern, along with errors and failure data
|
||||||
*/
|
*/
|
||||||
export function draft(Design, settings, plugins = []) {
|
export function draft(Design, settings, plugins = [], pluginsHook = false) {
|
||||||
const pattern = new Design(settings)
|
const pattern = new Design(settings)
|
||||||
for (const plugin of plugins) pattern.use(plugin)
|
for (const plugin of plugins) pattern.use(plugin)
|
||||||
|
if (pluginsHook) pluginsHook(pattern)
|
||||||
const data = {
|
const data = {
|
||||||
// The pattern
|
// The pattern
|
||||||
pattern,
|
pattern,
|
||||||
|
|
|
@ -36,7 +36,7 @@ const themedPattern = (Design, settings, overwrite, format, t) => {
|
||||||
|
|
||||||
// add the theme and translation to the pattern
|
// add the theme and translation to the pattern
|
||||||
pattern.use(themePlugin, { stripped: format !== 'svg', skipGrid: ['pages'] })
|
pattern.use(themePlugin, { stripped: format !== 'svg', skipGrid: ['pages'] })
|
||||||
pattern.use(pluginI18n, (key) => key)
|
pattern.use(pluginI18n, t)
|
||||||
|
|
||||||
return pattern
|
return pattern
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue