1
0
Fork 0
freesewing/sites/shared/components/workbench/views/draft/index.mjs
joostdecock 3111a6df8b [shared] fix: Pattern translation in UI
This fixes problems with pattern translation where the translation
inside a pattern we using the UI's i18n instance to do the translation.

That causes issues when the pattern language and UI langauges are
different (something we support). Furthermore, we need to load the
design's own namespace as the default, and load the annotations plugin
namespace and do some other things that are specific to translation
inside the patterns.

This resolves that by creating a dedicated i18n instance to handle
translation inside patterns.

This unblocks #6340
2024-03-16 11:39:26 +01:00

76 lines
1.7 KiB
JavaScript

// __SDEFILE__ - This file is a dependency for the stand-alone environment
import { PanZoomPattern as ShowPattern } from 'shared/components/workbench/pan-zoom-pattern.mjs'
import { DraftMenu, ns as menuNs } from './menu.mjs'
import { PatternWithMenu } from '../pattern-with-menu.mjs'
import { DraftHeader, ns as headerNs } from './header.mjs'
export const ns = [...menuNs, ...headerNs]
export const DraftView = ({
design,
pattern,
patternConfig,
settings,
setSettings,
ui,
update,
language,
account,
setView,
view,
saveAs,
}) => {
let output = null
let renderProps = false
if (ui.renderer === 'svg') {
try {
const __html = pattern.render()
output = (
<ShowPattern>
<div className="w-full h-full" dangerouslySetInnerHTML={{ __html }} />
</ShowPattern>
)
} catch (err) {
console.log(err)
}
} else {
renderProps = pattern.getRenderProps()
output = <ShowPattern {...{ renderProps }} design={design} patternLocale={settings.locale} />
}
return (
<PatternWithMenu
{...{
settings,
ui,
update,
control: account.control,
account,
design,
pattern: output,
setSettings,
saveAs,
Header: DraftHeader,
menu: (
<DraftMenu
{...{
design,
pattern,
patternConfig,
setSettings,
settings,
ui,
update,
language,
account,
renderProps,
view,
setView,
flags: pattern.setStores?.[0]?.plugins?.['plugin-annotations']?.flags,
}}
/>
),
}}
/>
)
}