@@ -56,20 +56,20 @@ const makeJSON = (rows, locale, separator = ".") => {
56
56
if ( ! str ) return ;
57
57
58
58
if ( keys . length === 1 ) {
59
- json [ ` ${ key } ` ] = str ;
59
+ json [ prune ( key ) ] = prune ( str ) ;
60
60
} else {
61
61
let nested = json ;
62
62
const lastIndex = keys . length - 1 ;
63
63
64
64
for ( let i = 0 ; i < keys . length - 1 ; i ++ ) {
65
- const currentKey = keys [ i ] ;
65
+ const currentKey = prune ( keys [ i ] ) ;
66
66
67
67
if ( ! nested [ currentKey ] ) {
68
68
nested [ currentKey ] = { } ;
69
69
}
70
70
nested = nested [ currentKey ] ;
71
71
}
72
- nested [ keys [ lastIndex ] ] = str ;
72
+ nested [ prune ( keys [ lastIndex ] ) ] = prune ( str ) ;
73
73
}
74
74
} ) ;
75
75
@@ -93,6 +93,13 @@ const writeJSON = (source, path) => {
93
93
) ;
94
94
} ;
95
95
96
+ /**
97
+ * @description Remove invalid strings generated during encoding
98
+ */
99
+ const prune = ( string ) => {
100
+ return string . replaceAll ( "\\n" , "\n" ) ;
101
+ } ;
102
+
96
103
const generate = async (
97
104
doc ,
98
105
locales ,
@@ -103,12 +110,9 @@ const generate = async (
103
110
locales . forEach ( async ( locale ) => {
104
111
const sheetRows = await readSheet ( doc , sheetTitle ) ;
105
112
const json = makeJSON ( sheetRows , locale , depthSeparator ) ;
113
+ const source = JSON . stringify ( json , null , 2 ) ;
106
114
107
- writeJSON (
108
- JSON . stringify ( json , null , 2 ) ,
109
- `${ output } /${ locale } .json` ,
110
- locale
111
- ) ;
115
+ writeJSON ( source , `${ output } /${ locale } .json` , locale ) ;
112
116
} ) ;
113
117
} ;
114
118
0 commit comments