|
1 |
| -import viteLogo from '/vite.svg' |
2 |
| -import {useTranslation} from "../src"; |
3 | 1 | import {useTranslation as useTranslationT} from "./useAutocompleteT";
|
| 2 | +import {Card, CardContent, CardDescription, CardHeader, CardTitle} from "@/components/ui/card"; |
| 3 | +import {Table, TableBody, TableCell, TableHead, TableHeader, TableRow} from "@/components/ui/table"; |
| 4 | +import {Earth, Languages} from "lucide-react"; |
4 | 5 |
|
| 6 | +/** |
| 7 | + * TODO: Display available JSON files |
| 8 | + * TODO: Display available languages |
| 9 | + * TODO: Add functionality to change language |
| 10 | + * TODO: Add functionality to change JSON file |
| 11 | + */ |
5 | 12 | function ExampleApp() {
|
6 |
| - const { locale, setLocale } = useTranslation(); |
7 | 13 | const {T} = useTranslationT();
|
8 |
| - |
9 | 14 | return (
|
10 |
| - <> |
11 |
| - <div> |
12 |
| - <a href="https://vitejs.dev" target="_blank"> |
13 |
| - <img src={viteLogo} className="logo" alt="Vite logo"/> |
14 |
| - </a> |
15 |
| - </div> |
16 |
| - <h1>Selected Locale: {locale}</h1> |
17 |
| - <div className="flex-box"> |
18 |
| - <button onClick={() => setLocale("en")} disabled={locale === "en"}>English</button> |
19 |
| - <button onClick={() => setLocale("de")} disabled={locale === "de"}>German</button> |
20 |
| - </div> |
21 |
| - <div>Simple translation: <code>T('hello')</code> results in <pre>{T('hello')}</pre></div> |
22 |
| - <div>Translation with parameters: <code>{`T('user.describe.simple', {name: "John"})`}</code> results |
23 |
| - in <pre>{T('user.describe.simple', {name: "John"})}</pre></div> |
24 |
| - <div>Pluralization: <code> |
25 |
| - {`T('message-count', {count: 5})`} |
26 |
| - </code> results in <pre>{T('message-count', {count: 5})}</pre></div> |
27 |
| - <div>Fallback: <code> |
28 |
| - {`T('fallback.valid')`} |
29 |
| - </code> results in <pre>{T('fallback.valid')}</pre></div> |
30 |
| - {/*Date and Time section*/} |
31 |
| - <div>Date: <code> |
32 |
| - {`T('date')`} |
33 |
| - </code> results in <pre>{T('date')}</pre></div> |
34 |
| - <div>Date UTC: <code> |
35 |
| - {`T('date-utc')`} |
36 |
| - </code> results in <pre>{T('date-utc')}</pre></div> |
37 |
| - <div>Nested Dates (Simple Format): |
38 |
| - <code> |
39 |
| - {`T('dates.simple')`} |
40 |
| - </code> results in <pre>{T('dates.simple')}</pre></div> |
41 |
| - <div>Nested Dates (Simple Format): |
42 |
| - <code> |
43 |
| - {`T('dates.nested.simple')`} |
44 |
| - </code> results in <pre>{T('dates.nested.simple')}</pre></div> |
45 |
| - <div>Nested Dates (Complex Format): |
46 |
| - <code> |
47 |
| - {`T('dates.nested.complex')`} |
48 |
| - </code> results in <pre>{T('dates.nested.complex')}</pre></div> |
49 |
| - <div>Parameters in Dates: |
50 |
| - <code> |
51 |
| - {`T('dates.parameter', {date: new Date()})`} |
52 |
| - </code> results in <pre>{T('dates.parameter', {date: Date.now()})}</pre></div> |
53 |
| - |
54 |
| - {/*Missing Keys section*/} |
55 |
| - <div>Missing key: <code> |
56 |
| - {`T('missing.key')`} |
57 |
| - </code> results in <pre>{T('missing.key')}</pre></div> |
58 |
| - <div>Missing key with fallback: <code> |
59 |
| - {`T('fallback.valid')`} |
60 |
| - </code> results in <pre>{T('fallback.valid')}</pre></div> |
61 |
| - </> |
| 15 | + <div className="flex min-h-screen w-full flex-col"> |
| 16 | + <header className="sticky top-0 flex h-16 items-center justify-between gap-4 border-b bg-background p-6 w-full"> |
| 17 | + <div className="p-2 flex flex-row items-center"> |
| 18 | + <Earth className="mr-4" /> |
| 19 | + <Languages className="mr-4"/> |
| 20 | + <h1 className="text-2xl font-semibold">React Intl - Example</h1> |
| 21 | + </div> |
| 22 | + </header> |
| 23 | + <main className="flex flex-1 flex-col gap-4 p-4 md:gap-8 md:p-8"> |
| 24 | + <div className="grid gap-4 md:grid-cols-2 md:gap-8 lg:grid-cols-4"> |
| 25 | + <Card className="mx-auto max-w-sm"> |
| 26 | + <CardHeader className="flex flex-col justify-between"> |
| 27 | + <CardTitle>Translations</CardTitle> |
| 28 | + <CardDescription> |
| 29 | + Example of translations using the <code className="text-secondary-foreground">useTranslation</code> hook |
| 30 | + </CardDescription> |
| 31 | + </CardHeader> |
| 32 | + <CardContent> |
| 33 | + <Table> |
| 34 | + <TableHeader> |
| 35 | + <TableRow> |
| 36 | + <TableHead>Translation Type</TableHead> |
| 37 | + <TableHead>Code</TableHead> |
| 38 | + <TableHead>Output</TableHead> |
| 39 | + </TableRow> |
| 40 | + </TableHeader> |
| 41 | + <TableBody> |
| 42 | + <TableRow> |
| 43 | + <TableCell> |
| 44 | + Simple translation |
| 45 | + </TableCell> |
| 46 | + <TableCell> |
| 47 | + <code>T('hello')</code> |
| 48 | + </TableCell> |
| 49 | + <TableCell> |
| 50 | + {T('hello')} |
| 51 | + </TableCell> |
| 52 | + </TableRow> |
| 53 | + <TableRow> |
| 54 | + <TableCell> |
| 55 | + Translation with parameters |
| 56 | + </TableCell> |
| 57 | + <TableCell> |
| 58 | + <code>{`T('user.describe.simple', {name: "John"})`}</code> |
| 59 | + </TableCell> |
| 60 | + <TableCell> |
| 61 | + {T('user.describe.simple', {name: 'John'})} |
| 62 | + </TableCell> |
| 63 | + </TableRow> |
| 64 | + <TableRow> |
| 65 | + <TableCell> |
| 66 | + Pluralization |
| 67 | + </TableCell> |
| 68 | + <TableCell> |
| 69 | + <code>{`T('message-count', {count: 5})`}</code> |
| 70 | + </TableCell> |
| 71 | + <TableCell> |
| 72 | + {T('message-count', {count: 5})} |
| 73 | + </TableCell> |
| 74 | + </TableRow> |
| 75 | + <TableRow> |
| 76 | + <TableCell> |
| 77 | + Fallback |
| 78 | + </TableCell> |
| 79 | + <TableCell> |
| 80 | + <code>{`T('fallback.valid')`}</code> |
| 81 | + </TableCell> |
| 82 | + <TableCell> |
| 83 | + {T('fallback.valid')} |
| 84 | + </TableCell> |
| 85 | + </TableRow> |
| 86 | + <TableRow> |
| 87 | + <TableCell> |
| 88 | + Date |
| 89 | + </TableCell> |
| 90 | + <TableCell> |
| 91 | + <code>{`T('date')`}</code> |
| 92 | + </TableCell> |
| 93 | + <TableCell> |
| 94 | + {T('date')} |
| 95 | + </TableCell> |
| 96 | + </TableRow> |
| 97 | + <TableRow> |
| 98 | + <TableCell> |
| 99 | + Date UTC |
| 100 | + </TableCell> |
| 101 | + <TableCell> |
| 102 | + <code>{`T('date-utc')`}</code> |
| 103 | + </TableCell> |
| 104 | + <TableCell> |
| 105 | + {T('date-utc')} |
| 106 | + </TableCell> |
| 107 | + </TableRow> |
| 108 | + <TableRow> |
| 109 | + <TableCell> |
| 110 | + Nested Dates (Simple Format) |
| 111 | + </TableCell> |
| 112 | + <TableCell> |
| 113 | + <code>{`T('dates.simple')`}</code> |
| 114 | + </TableCell> |
| 115 | + <TableCell> |
| 116 | + {T('dates.simple')} |
| 117 | + </TableCell> |
| 118 | + </TableRow> |
| 119 | + <TableRow> |
| 120 | + <TableCell> |
| 121 | + Nested Dates (Complex Format) |
| 122 | + </TableCell> |
| 123 | + <TableCell> |
| 124 | + <code>{`T('dates.nested.complex')`}</code> |
| 125 | + </TableCell> |
| 126 | + <TableCell> |
| 127 | + {T('dates.nested.complex')} |
| 128 | + </TableCell> |
| 129 | + </TableRow> |
| 130 | + <TableRow> |
| 131 | + <TableCell> |
| 132 | + Parameters in Dates |
| 133 | + </TableCell> |
| 134 | + <TableCell> |
| 135 | + <code>{`T('dates.parameter', {date: new Date()})`}</code> |
| 136 | + </TableCell> |
| 137 | + <TableCell> |
| 138 | + {T('dates.parameter', {date: new Date().toDateString()})} |
| 139 | + </TableCell> |
| 140 | + </TableRow> |
| 141 | + <TableRow> |
| 142 | + <TableCell> |
| 143 | + Missing key |
| 144 | + </TableCell> |
| 145 | + <TableCell> |
| 146 | + <code>{`T('missing.key')`}</code> |
| 147 | + </TableCell> |
| 148 | + <TableCell> |
| 149 | + {T('missing.key')} |
| 150 | + </TableCell> |
| 151 | + </TableRow> |
| 152 | + <TableRow> |
| 153 | + <TableCell> |
| 154 | + Missing key with fallback |
| 155 | + </TableCell> |
| 156 | + <TableCell> |
| 157 | + <code>{`T('fallback.valid')`}</code> |
| 158 | + </TableCell> |
| 159 | + <TableCell> |
| 160 | + {T('fallback.valid')} |
| 161 | + </TableCell> |
| 162 | + </TableRow> |
| 163 | + </TableBody> |
| 164 | + </Table> |
| 165 | + </CardContent> |
| 166 | + </Card> |
| 167 | + </div> |
| 168 | + </main> |
| 169 | + </div> |
62 | 170 | )
|
63 | 171 | }
|
64 | 172 |
|
|
0 commit comments