@@ -88,6 +88,149 @@ td-starter init tdesign-vue3-farm -type vue3 -bt farm
8888| -bt, --buildToolType \< buildToolType>| The construction tool for lite: vite \| webpack (default: "vite") |
8989| -h, --help | display help for command |
9090
91+ ## i18n Localization
92+
93+ The i18n command helps you convert Vue3 projects with i18n implementations to localized versions (removing i18n dependencies).
94+
95+ ### Basic Usage
96+
97+ #### Interactive Mode
98+ ``` sh
99+ # Start the i18n localization process
100+ td-starter i18n
101+
102+ # Then input the target project path when prompted
103+ ? 请输入目标项目路径: ./my-project
104+ ```
105+
106+ #### Command Mode
107+ ``` sh
108+ # Specify the target project path directly
109+ td-starter i18n --target ./my-project
110+
111+ # Short option
112+ td-starter i18n -t ./my-project
113+ ```
114+
115+ ### Requirements
116+
117+ - ** Project Type** : Currently only supports ** Vue3** projects with i18n setup
118+ - ** Project Structure** : Your project must have the following directory structure:
119+ ```
120+ src/
121+ └── locales/
122+ └── lang/
123+ ├── zh_CN.json (or other language codes)
124+ ├── en_US.json
125+ └── ...
126+ ```
127+
128+ ### How It Works
129+
130+ The i18n command performs the following operations:
131+
132+ 1 . ** Project Analysis** : Automatically detects if the project is a Vue3 project with i18n configuration
133+ 2 . ** Language Detection** : Scans the ` src/locales/lang ` directory to find all available language files
134+ 3 . ** Language Selection** : Prompts you to choose a target language for localization
135+ 4 . ** File Processing** : Replaces all i18n function calls with static strings:
136+ - ` this.$t('key') ` → ` 'translated_value' `
137+ - ` $t('key') ` → ` 'translated_value' `
138+ - ` t('key') ` → ` 'translated_value' `
139+
140+ 5 . ** Result Summary** : Shows statistics including:
141+ - Number of files processed
142+ - Number of translation replacements made
143+
144+ ### Supported Language Formats
145+
146+ The following language code formats are automatically recognized:
147+
148+ | Language Code | Language Name |
149+ | ---------------| -------------------|
150+ | zh_CN | 简体中文 |
151+ | zh_TW | 繁體中文 |
152+ | en_US | English |
153+ | en | English |
154+ | zh | 中文 |
155+ | ja | 日本語 |
156+ | ko | 한국어 |
157+ | fr | Français |
158+ | de | Deutsch |
159+ | es | Español |
160+ | ru | Русский |
161+
162+ ### Example Workflow
163+
164+ ``` sh
165+ # Step 1: Navigate to where tdesign-starter-cli is installed
166+ td-starter i18n
167+
168+ # Step 2: Input project path
169+ ? 请输入目标项目路径: /Users/username/my-vue3-project
170+
171+ # Step 3: System detects project type
172+ 🔍 目标项目路径: /Users/username/my-vue3-project
173+ ✅ 检测到项目类型: vue3
174+
175+ # Step 4: System scans language configurations
176+ 🌍 可用语言:
177+ - 简体中文 (zh_CN)
178+ - English (en_US)
179+
180+ # Step 5: Select target language
181+ ? 请选择要本地化的目标语言: (Use arrow keys to select)
182+ ❯ 简体中文 (zh_CN)
183+ English (en_US)
184+
185+ # Step 6: Process completed
186+ ✅ 本地化完成!
187+ 处理文件: 25 个
188+ 替换条目: 156 个
189+ ```
190+
191+ ### Important Notes
192+
193+ ⚠️ ** After localization:**
194+ - The i18n configuration files and import statements are ** still preserved**
195+ - Manual cleanup may be required if you want to completely remove i18n dependencies
196+ - Test your application to ensure all translations are correctly replaced
197+ - Keep your language configuration files for reference
198+
199+ ### Troubleshooting
200+
201+ | Issue | Solution |
202+ | -------| ----------|
203+ | "无法识别项目类型" | Ensure your project has ` package.json ` with Vue 3 dependencies in the correct location |
204+ | "未检测到语言配置" | Verify the ` src/locales/lang ` directory exists and contains ` .json ` language files |
205+ | "未找到翻译: key.name" | The translation key is missing in the selected language file |
206+ | No files processed | Check if there are ` .vue ` , ` .ts ` , or ` .js ` files in the ` src ` directory |
207+
208+ ### Advanced Usage
209+
210+ #### Verify Replacement Results
211+ Use the following methods to check if the replacement was successful:
212+ ``` sh
213+ # Check if there are still i18n function calls
214+ grep -r " \$ t(" src/ --include=" *.vue" --include=" *.ts" --include=" *.js"
215+
216+ # Check if there are still i18n imports
217+ grep -r " vue-i18n" src/ --include=" *.ts" --include=" *.js"
218+ ```
219+
220+ #### Manual Cleanup (Optional)
221+ After replacement, to completely remove i18n, you can execute:
222+ ``` sh
223+ # 1. Remove i18n configuration files
224+ rm -rf src/locales/
225+
226+ # 2. Remove dependencies from package.json
227+ npm uninstall vue-i18n
228+
229+ # 3. Update import statements (manually or via script)
230+ # Delete import { createI18n } from 'vue-i18n'
231+ # Delete other i18n related imports
232+ ```
233+
91234## Preview
92235
93236### Vite + React/Vue2/Vue3
0 commit comments