@@ -7,8 +7,10 @@ import { YamlParser } from '../parsers/YamlParser'
77import { JavascriptParser } from '../parsers/JavascriptParser'
88import { ConfigLocalesGuide } from '../commands/configLocales'
99import { extname } from 'path'
10+ import i18n from '../i18n'
1011
1112const configPrefix = 'vue-i18n-ally'
13+ export type KeyStyle = 'auto' | 'nested' | 'flat'
1214
1315export class Global {
1416 private static _loaders : Record < string , LocaleLoader > = { }
@@ -190,6 +192,38 @@ export class Global {
190192 this . _onDidChangeLoader . fire ( this . loader )
191193 }
192194
195+ static get keyStyle ( ) : KeyStyle {
196+ return ( Global . getConfig ( 'keystyle' ) || 'auto' ) as KeyStyle
197+ }
198+
199+ static set keyStyle ( value : KeyStyle ) {
200+ Global . setConfig ( 'keystyle' , value , false )
201+ }
202+
203+ static async requestKeyStyle ( ) : Promise < KeyStyle | undefined > {
204+ if ( this . keyStyle !== 'auto' )
205+ return this . keyStyle
206+
207+ const result = await window . showQuickPick ( [ {
208+ value : 'nested' ,
209+ label : i18n . t ( 'prompt.keystyle_nested' ) ,
210+ description : i18n . t ( 'prompt.keystyle_nested_example' ) ,
211+ } , {
212+ value : 'flat' ,
213+ label : i18n . t ( 'prompt.keystyle_flat' ) ,
214+ description : i18n . t ( 'prompt.keystyle_flat_example' ) ,
215+ } ] , {
216+ placeHolder : i18n . t ( 'prompt.keystyle_select' ) ,
217+ } )
218+
219+ if ( ! result ) {
220+ this . keyStyle = 'nested'
221+ return 'nested'
222+ }
223+ this . keyStyle = result . value as KeyStyle
224+ return result . value as KeyStyle
225+ }
226+
193227 static toggleLocaleVisibility ( locale : string , visible ?: boolean ) {
194228 const ignored = this . ignoredLocales
195229 if ( visible == null )
0 commit comments