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"
{': …}}]}'}
{step.say}
{step.sub}