@@ -3,7 +3,7 @@ import { mkdir, readFile, writeFile } from 'node:fs/promises'
33import os from 'node:os'
44import path from 'node:path'
55import { afterEach , describe , expect , it } from 'vitest'
6- import { applyTranslations , approveTranslations , initProject , restoreBackups , scanProject } from '../index'
6+ import { applyTranslations , approveTranslations , initGlossary , initProject , restoreBackups , scanProject } from '../index'
77import { collectMapStats , formatMapStatsReport } from '../stats'
88
99const tempDirs : string [ ] = [ ]
@@ -153,6 +153,42 @@ describe('i18n migrate workflow', () => {
153153 expect ( overriddenAppMap . entries [ '旧文案' ] ?. approved ) . toBe ( true )
154154 } )
155155
156+ it ( 'seeds glossary presets without clobbering existing manual terms by default' , async ( ) => {
157+ const cwd = await createTempProject ( )
158+ await initProject ( { cwd, overwrite : false , from : 'zh' , to : 'en' } )
159+ const glossaryPath = path . join ( cwd , '.tmigrate' , 'glossary.json' )
160+ await writeFile ( glossaryPath , JSON . stringify ( { 提交 : 'Send' , 自定义 : 'Custom' } , null , 2 ) , 'utf8' )
161+
162+ const preview = await initGlossary ( { cwd, preset : 'business' , dryRun : true } )
163+ expect ( preview . entries . 订单 ) . toBe ( 'Order' )
164+ expect ( JSON . parse ( await readFile ( glossaryPath , 'utf8' ) ) . 订单 ) . toBeUndefined ( )
165+
166+ const seeded = await initGlossary ( { cwd, preset : 'all' } )
167+ expect ( seeded . added ) . toBeGreaterThan ( 0 )
168+ expect ( seeded . skipped ) . toBe ( 1 )
169+ expect ( seeded . entries . 提交 ) . toBe ( 'Send' )
170+ expect ( seeded . entries . 自定义 ) . toBe ( 'Custom' )
171+
172+ const saved = JSON . parse ( await readFile ( glossaryPath , 'utf8' ) ) as Record < string , string >
173+ expect ( saved . 订单 ) . toBe ( 'Order' )
174+ expect ( saved . 提交 ) . toBe ( 'Send' )
175+
176+ const overwritten = await initGlossary ( { cwd, preset : 'ui' , overwrite : true } )
177+ expect ( overwritten . updated ) . toBe ( 1 )
178+ expect ( overwritten . entries . 提交 ) . toBe ( 'Submit' )
179+ } )
180+
181+ it ( 'supports English to Chinese glossary presets from project config' , async ( ) => {
182+ const cwd = await createTempProject ( )
183+ await initProject ( { cwd, overwrite : false , from : 'en' , to : 'zh' } )
184+
185+ const seeded = await initGlossary ( { cwd, preset : 'ui' } )
186+ expect ( seeded . sourceLocale ) . toBe ( 'en' )
187+ expect ( seeded . targetLocale ) . toBe ( 'zh' )
188+ expect ( seeded . entries . Submit ) . toBe ( '提交' )
189+ expect ( seeded . entries . Search ) . toBe ( '搜索' )
190+ } )
191+
156192 it ( 'summarizes map progress and flags orphaned files' , async ( ) => {
157193 const cwd = await createTempProject ( )
158194 const appPath = path . join ( cwd , 'src' , 'App.vue' )
0 commit comments