| 
1 |  | -import type { FC, JSX, PropsWithChildren } from "hono/jsx";  | 
 | 1 | +import type { FC } from "hono/jsx";  | 
2 | 2 | import {  | 
3 | 3 | 	discordServerUrl,  | 
4 | 4 | 	githubOrganizationUrl,  | 
5 | 5 | 	githubRepositoryUrl,  | 
6 | 6 | 	typstOfficialDocsUrl,  | 
7 | 7 | } from "./metadata";  | 
8 | 8 | 
 
  | 
9 |  | -type MyMap = {  | 
10 |  | -	[key: string]: string;  | 
11 |  | -};  | 
12 |  | - | 
13 |  | -export const menuTranslations: MyMap = {  | 
14 |  | -	lang: "ja",  | 
15 |  | -	ariaCloseMenu: "メニューを閉じる",  | 
16 |  | -	documentationTitle: "Typstドキュメント日本語版",  | 
17 |  | -	ariaShowInformation: "の詳細情報を表示",  | 
18 |  | -	ariaClose: "閉じる",  | 
19 |  | -	ariaOpenSearch: "検索を開く",  | 
20 |  | -	ariaOpenMenu: "メニューを開く",  | 
21 |  | -	ariaCloseSearch: "検索を閉じる",  | 
22 |  | -};  | 
23 |  | - | 
24 |  | -export const t = (key: keyof MyMap) => {  | 
25 |  | -	if (typeof menuTranslations[key] === "string") {  | 
26 |  | -		return menuTranslations[key];  | 
27 |  | -	}  | 
28 |  | -	throw new Error(`Not translation found for ${key}`);  | 
29 |  | -};  | 
 | 9 | +/**  | 
 | 10 | + * Translation dictionary for UI attributes and aria labels.  | 
 | 11 | + *  | 
 | 12 | + * @example  | 
 | 13 | + * translation.ariaCloseMenu()  | 
 | 14 | + * translation.ariaShowInformation({ name: "foo" })  | 
 | 15 | + */  | 
 | 16 | +export const translation = {  | 
 | 17 | +	lang: () => "ja",  | 
 | 18 | +	ariaCloseMenu: () => "メニューを閉じる",  | 
 | 19 | +	documentationTitle: () => "Typstドキュメント日本語版",  | 
 | 20 | +	ariaShowInformation: (props: {  | 
 | 21 | +		name: string;  | 
 | 22 | +	}) => `${props.name}の詳細情報を表示`,  | 
 | 23 | +	ariaClose: () => "閉じる",  | 
 | 24 | +	ariaOpenSearch: () => "検索を開く",  | 
 | 25 | +	ariaOpenMenu: () => "メニューを開く",  | 
 | 26 | +	ariaCloseSearch: () => "検索を閉じる",  | 
 | 27 | +} as const;  | 
30 | 28 | 
 
  | 
31 | 29 | type TranslationKey =  | 
32 | 30 | 	| "definition"  | 
@@ -80,21 +78,15 @@ type TranslationKey =  | 
80 | 78 | 
 
  | 
81 | 79 | export type TranslationProps =  | 
82 | 80 | 	| { translationKey: TranslationKey }  | 
83 |  | -	| PropsWithChildren<{ translationKey: "banner"; version: string }>;  | 
84 |  | - | 
85 |  | -/*  | 
86 |  | -This is inferred as the following type:  | 
87 |  | -
  | 
88 |  | -type TranslationProps = {  | 
89 |  | -    translationKey: "lang";  | 
90 |  | -} |  | 
91 |  | -	...  | 
92 |  | -| {  | 
93 |  | -    translationKey: "banner";  | 
94 |  | -    children?: string | number | boolean | Promise<string> | JSXNode | Child[] | null;  | 
95 |  | -}  | 
96 |  | -*/  | 
 | 81 | +	| { translationKey: "banner"; version: string };  | 
97 | 82 | 
 
  | 
 | 83 | +/**  | 
 | 84 | + * Translation component for UI text, descriptions, and other content to be embedded as JSX.  | 
 | 85 | + *  | 
 | 86 | + * @example  | 
 | 87 | + * <Translation translationKey="definition" />  | 
 | 88 | + * <Translation translationKey="banner" version="1.0.0" />  | 
 | 89 | + */  | 
98 | 90 | export const Translation: FC<TranslationProps> = (props) => {  | 
99 | 91 | 	switch (props.translationKey) {  | 
100 | 92 | 		case "definition":  | 
@@ -240,6 +232,6 @@ export const Translation: FC<TranslationProps> = (props) => {  | 
240 | 232 | 		case "information":  | 
241 | 233 | 			return <>情報</>;  | 
242 | 234 | 		default:  | 
243 |  | -			throw new Error("No translationKey found for Translation Element");  | 
 | 235 | +			return null;  | 
244 | 236 | 	}  | 
245 | 237 | };  | 
0 commit comments