File tree Expand file tree Collapse file tree 2 files changed +8
-0
lines changed Expand file tree Collapse file tree 2 files changed +8
-0
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ const cli = meow(
1515 -f, --format json | yaml [default: json]
1616 -d, --default-locale default locale
1717 --flat json [default: true] | yaml [default: false]
18+ --sort-when-not-flat keys are sorted even when flat option is false [default: false]
1819
1920 Example
2021 $ extract-messages --locales=ja,en --output app/translations 'app/**/*.js'
@@ -25,6 +26,9 @@ const cli = meow(
2526 flat : {
2627 type : 'boolean'
2728 } ,
29+ 'sort-when-not-flat' : {
30+ type : 'boolean'
31+ } ,
2832 output : {
2933 type : 'string' ,
3034 alias : 'o'
Original file line number Diff line number Diff line change @@ -61,6 +61,7 @@ type Opts = {
6161 defaultLocale : string
6262 format ?: string
6363 flat ?: boolean
64+ sortWhenNotFlat ?: boolean
6465 [ key : string ] : unknown
6566}
6667
@@ -72,6 +73,7 @@ const extractMessage = async (
7273 {
7374 format = 'json' ,
7475 flat = isJson ( format ) ,
76+ sortWhenNotFlat = false ,
7577 defaultLocale = 'en' ,
7678 ...opts
7779 } : Opts = {
@@ -121,6 +123,8 @@ const extractMessage = async (
121123
122124 const fomattedLocaleMap : object = flat
123125 ? sortKeys ( localeMap , { deep : true } )
126+ : sortWhenNotFlat
127+ ? sortKeys ( unflatten ( localeMap , { object : true } ) , { deep : true } )
124128 : unflatten ( sortKeys ( localeMap ) , { object : true } )
125129
126130 const fn = isJson ( format ) ? writeJson : writeYaml
You can’t perform that action at this time.
0 commit comments