|
1 | 1 | import type { FC } from "hono/jsx"; |
2 | 2 | import type { TooltipProps } from "../components/ui/Tooltip"; |
3 | 3 | import { language } from "../metadata"; |
4 | | -import { |
5 | | - Translation as EnUSTranslation, |
6 | | - translation as enUSTranslation, |
7 | | -} from "./en-US"; |
8 | | -import { |
9 | | - Translation as JaJPTranslation, |
10 | | - translation as jaJPTranslation, |
11 | | -} from "./ja-JP"; |
12 | 4 |
|
13 | 5 | /** |
14 | 6 | * Translation dictionary for UI attributes and aria labels. |
@@ -105,12 +97,15 @@ export type TranslationComponentProps = |
105 | 97 | export type TranslationComponent = FC<TranslationComponentProps>; |
106 | 98 |
|
107 | 99 | // Switch translation language. |
108 | | -const { Translation, translation } = (() => { |
| 100 | +const { Translation, translation } = await (() => { |
| 101 | + // These imports should be lazy and static. |
| 102 | + // - Lazy: A translation may use special metadata (e.g., Discord/QQ URL), so not all translations can be safely imported in every build. Therefore, we have to use the import function, not the import statement. |
| 103 | + // - Static: The argument of the import function has to be a plain string, not a variable. Dynamic import has limitations even with rollup and vite properly configured. |
109 | 104 | switch (language) { |
110 | | - case "ja-JP": |
111 | | - return { Translation: JaJPTranslation, translation: jaJPTranslation }; |
112 | 105 | case "en-US": |
113 | | - return { Translation: EnUSTranslation, translation: enUSTranslation }; |
| 106 | + return import("./en-US"); |
| 107 | + case "ja-JP": |
| 108 | + return import("./ja-JP"); |
114 | 109 | default: |
115 | 110 | throw new Error(`Unsupported language: ${language}`); |
116 | 111 | } |
|
0 commit comments