import * as React from 'react' import {defineMessages, FormattedMessage, IntlProvider} from 'react-intl' const messages = defineMessages<{ readonly unread: {readonly count: number | bigint} }>({ unread: { id: 'workflow.unread', defaultMessage: '{count, plural, one {# new message} other {# new messages}}', description: 'Inbox header, count of unread mail', }, }) const FR_MESSAGES = { [messages.unread.id]: '{count, plural, one {# nouveau message} other {# nouveaux messages}}', } const STEPS = [ { say: 'First, declare messages where they render.', sub: ( <> defineMessages keeps the English default, a note for translators and a stable ID next to the component that uses it. ), }, { say: 'Then extract them with one command.', sub: ( <> formatjs extract reads your source and writes a catalog your translation tool can open. The CLI ships native binaries for macOS, Linux and Windows. ), }, { say: 'Finally, compile and ship each locale.', sub: ( <> formatjs compile --ast pre-parses every translation, so the browser formats messages without loading the parser. ), }, ] const TABS = ['Inbox.tsx', 'Terminal', 'compiled-lang/fr.json'] const K = ({children}: {children: React.ReactNode}): React.ReactNode => ( {children} ) const S = ({children}: {children: React.ReactNode}): React.ReactNode => ( {children} ) const M = ({children}: {children: React.ReactNode}): React.ReactNode => ( {children} ) const VIEWS: React.ReactNode[] = [
    
      import {'{defineMessages, FormattedMessage}'} from{' '}
      'react-intl'
      {'\n\n'}
      const messages = defineMessages({'{\n'}
      {'  unread: {\n    defaultMessage:\n      '}
      '{'{count, plural, one {# new message} other {# new messages}}'}'
      {',\n    description: '}
      'Inbox header, count of unread mail'
      {',\n  },\n})\n\n'}
      export function {'InboxHeader({count}) {\n  '}
      return
      {
        ' (\n    

\n \n

\n )\n}' }
,
    
      $ formatjs extract 'src/**/*.tsx'
      {' \\\n    --out-file lang/en.json \\\n    --id-interpolation-pattern '}
      '[sha512:contenthash:base64:6]'
      {'\n\n'}
      lang/en.json
      {'\n{\n  '}
      "hak27d"
      {': {\n    '}
      "defaultMessage"
      {': '}
      "{'{count, plural, one {# new message} other {# new messages}}'}"
      {',\n    '}
      "description"
      {': '}
      "Inbox header, count of unread mail"
      {'\n  }\n}'}
    
  
,
      
        $ formatjs compile lang/fr.json --ast \
        {'\n    --out-file compiled-lang/fr.json\n\n'}
        compiled-lang/fr.json
        {'\n{'}
        "hak27d"
        {': [{'}
        "type"
        {': 6, '}
        "value"
        {': '}
        "count"
        {',\n  '}
        "options"
        {': {'}
        "one"
        {': …, '}
        "other"
        {': …}}]}'}
      
    
Rendered, locale fr
, ] export default function WorkflowSection(): React.ReactNode { const [active, setActive] = React.useState(0) const steps = React.useRef<(HTMLDivElement | null)[]>([]) // The pinned pane follows whichever statement sits in the middle band. React.useEffect(() => { if (!('IntersectionObserver' in window)) { return } const observer = new IntersectionObserver( entries => { for (const entry of entries) { if (entry.isIntersecting) { setActive(Number((entry.target as HTMLElement).dataset.step)) } } }, {rootMargin: '-45% 0px -45% 0px'} ) steps.current.forEach(el => el && observer.observe(el)) return () => observer.disconnect() }, []) return (
{STEPS.map((step, i) => (
{ steps.current[i] = el }} className="flex min-h-[60svh] flex-col justify-center sm:min-h-[80vh] sm:last:min-h-[70vh]" > {i === 0 && (

From component to catalog

)}

{step.say}

{step.sub}

))}
{TABS.map((tab, i) => ( {tab} ))}
{VIEWS[active]}
) }