|
| 1 | +/** @jsx jsx */ |
| 2 | +import { Amplitude, LogOnMount } from '@amplitude/react-amplitude'; |
| 3 | +import { css, jsx } from '@emotion/core'; |
| 4 | +import * as Sentry from '@sentry/node'; |
| 5 | +import { isBrowser } from '@unly/utils'; |
| 6 | +import { createLogger } from '@unly/utils-simple-logger'; |
| 7 | +import { NextPage } from 'next'; |
| 8 | +// eslint-disable-next-line @typescript-eslint/no-unused-vars,no-unused-vars |
| 9 | +import React from 'react'; |
| 10 | +import { Trans, useTranslation, UseTranslationResponse } from 'react-i18next'; |
| 11 | +import { Alert, Container } from 'reactstrap'; |
| 12 | +import uuid from 'uuid/v1'; |
| 13 | + |
| 14 | +import Head from '../components/Head'; |
| 15 | +import { PageProps } from '../types/PageProps'; |
| 16 | + |
| 17 | +const fileLabel = 'pages/examples'; |
| 18 | +const logger = createLogger({ // eslint-disable-line no-unused-vars,@typescript-eslint/no-unused-vars |
| 19 | + label: fileLabel, |
| 20 | +}); |
| 21 | + |
| 22 | +const Examples: NextPage<PageProps> = (props: PageProps): JSX.Element => { |
| 23 | + const { t }: UseTranslationResponse = useTranslation(); |
| 24 | + |
| 25 | + Sentry.addBreadcrumb({ // See https://docs.sentry.io/enriching-error-data/breadcrumbs |
| 26 | + category: fileLabel, |
| 27 | + message: `Rendering examples page (${isBrowser() ? 'browser' : 'server'})`, |
| 28 | + level: Sentry.Severity.Debug, |
| 29 | + }); |
| 30 | + |
| 31 | + return ( |
| 32 | + <Amplitude |
| 33 | + eventProperties={(inheritedProps): object => ({ |
| 34 | + ...inheritedProps, |
| 35 | + page: { |
| 36 | + ...inheritedProps.page, |
| 37 | + name: 'examples', |
| 38 | + }, |
| 39 | + })} |
| 40 | + > |
| 41 | + {({ logEvent }): JSX.Element => ( |
| 42 | + <> |
| 43 | + <LogOnMount eventType="page-displayed" /> |
| 44 | + <Head /> |
| 45 | + <div |
| 46 | + css={css` |
| 47 | + justify-content: center; |
| 48 | + text-align: center; |
| 49 | + margin-left: auto; |
| 50 | + margin-right: auto; |
| 51 | + `} |
| 52 | + > |
| 53 | + <h1>Code snippet examples</h1> |
| 54 | + |
| 55 | + <hr /> |
| 56 | + |
| 57 | + <h2>i18n examples</h2> |
| 58 | + <Alert color={'info'}> |
| 59 | + <div> |
| 60 | + Each example shows the rendered version and its code snippet.<br /> |
| 61 | + The goal is to showcase real-world examples to help you get started faster and give a wider overview of what's possible.<br /> |
| 62 | + <a href={'https://react.i18next.com/'} target="blank" rel={'nofollow noreferrer'}> |
| 63 | + Check the official documentation |
| 64 | + </a> |
| 65 | + </div> |
| 66 | + </Alert> |
| 67 | + |
| 68 | + <Container> |
| 69 | + <div> |
| 70 | + {t('examples.i18n.simpleTranslation', 'Traduction simple')}<br /> |
| 71 | + <code>{'{t(\'examples.i18n.simpleTranslation\', \'Traduction simple\')}'}</code> |
| 72 | + </div> |
| 73 | + <hr /> |
| 74 | + |
| 75 | + <div> |
| 76 | + {t('examples.i18n.pluralTranslation', 'Traduction avec gestion du pluriel', { count: 1 })}<br /> |
| 77 | + <code>{'{t(\'examples.i18n.pluralTranslation\', \'Traduction avec gestion du pluriel\', { count: 1 })}'}</code> |
| 78 | + </div> |
| 79 | + <div> |
| 80 | + {t('examples.i18n.pluralTranslation', 'Traduction avec gestion du pluriel', { count: 2 })}<br /> |
| 81 | + <code>{'{t(\'examples.i18n.pluralTranslation\', \'Traduction avec gestion du pluriel\', { count: 2 })}'}</code> |
| 82 | + </div> |
| 83 | + <hr /> |
| 84 | + |
| 85 | + <div> |
| 86 | + <Trans |
| 87 | + i18nKey={'examples.i18n.dynamicTranslation'} |
| 88 | + > |
| 89 | + Contenu dynamique : <b>{{ uuid: uuid() }}</b> |
| 90 | + </Trans> |
| 91 | + <br /> |
| 92 | + <code> |
| 93 | + {'<Trans\n' + |
| 94 | + ' i18nKey="{\'examples.i18n.dynamicTranslation\'}"\n' + |
| 95 | + '>\n' + |
| 96 | + ' Contenu dynamique : <b>{{ uuid: uuid() }}</b>\n' + |
| 97 | + '</Trans>'} |
| 98 | + </code> |
| 99 | + </div> |
| 100 | + <hr /> |
| 101 | + |
| 102 | + <div> |
| 103 | + <Trans |
| 104 | + i18nKey={'examples.i18n.dynamicPluralTranslation'} |
| 105 | + count={1} |
| 106 | + > |
| 107 | + Nous avons trouvé {{ count: 1 }} solution pour vous. |
| 108 | + </Trans> |
| 109 | + <br /> |
| 110 | + <code> |
| 111 | + {'<Trans\n' + |
| 112 | + ' i18nKey="{\'examples.i18n.dynamicPluralTranslation\'}"\n' + |
| 113 | + ' count="{1}"\n' + |
| 114 | + '>\n' + |
| 115 | + ' Nous avons trouvé {{ count: 1 }} solution pour vous.\n' + |
| 116 | + '</Trans>'} |
| 117 | + </code> |
| 118 | + </div> |
| 119 | + <div> |
| 120 | + <Trans |
| 121 | + i18nKey={'examples.i18n.dynamicPluralTranslation'} |
| 122 | + count={2} |
| 123 | + > |
| 124 | + Nous avons trouvé {{ count: 2 }} solution pour vous. |
| 125 | + </Trans> |
| 126 | + <br /> |
| 127 | + <code> |
| 128 | + {'<Trans\n' + |
| 129 | + ' i18nKey="{\'examples.i18n.dynamicPluralTranslation\'}"\n' + |
| 130 | + ' count="{2}"\n' + |
| 131 | + '>\n' + |
| 132 | + ' Nous avons trouvé {{ count: 2 }} solution pour vous.\n' + |
| 133 | + '</Trans>'} |
| 134 | + </code> |
| 135 | + </div> |
| 136 | + <hr /> |
| 137 | + |
| 138 | + </Container> |
| 139 | + </div> |
| 140 | + </> |
| 141 | + )} |
| 142 | + </Amplitude> |
| 143 | + ); |
| 144 | + |
| 145 | +}; |
| 146 | + |
| 147 | +export default Examples; |
0 commit comments