@@ -6,43 +6,34 @@ const localizedPath = ['pluginOptions', 'i18n', 'localized']
66const translatePath = [ 'pluginOptions' , 'translate' , 'translate' ]
77
88const addTranslationToFields = ( attributes : Schema . ContentType [ 'attributes' ] ) =>
9- Object . keys ( attributes ) . reduce < Schema . ContentType [ 'attributes' ] > (
10- ( acc , current ) => {
11- const currentAttribute = attributes [ current ]
12-
13- const attributeIsLocalized = get ( currentAttribute , localizedPath , true )
14-
15- const attributeDefaultTranslated =
16- currentAttribute . type === 'relation' || attributeIsLocalized
17-
18- if (
19- attributeDefaultTranslated &&
20- TRANSLATABLE_FIELDS . includes ( currentAttribute . type )
21- ) {
22- const translate = {
23- translate : get (
24- currentAttribute ,
25- translatePath ,
26- attributeDefaultTranslated ? 'translate' : 'copy'
27- ) ,
28- }
29-
30- const pluginOptions = {
31- ...( currentAttribute . pluginOptions ?? { } ) ,
32- translate,
33- }
34-
35- acc [ current ] = { ...currentAttribute , pluginOptions }
36-
37- return acc
9+ Object . values ( attributes ) . map ( ( currentAttribute ) => {
10+ const attributeIsLocalized = get ( currentAttribute , localizedPath , true )
11+
12+ const attributeDefaultTranslated =
13+ currentAttribute . type === 'relation' || attributeIsLocalized
14+
15+ if (
16+ attributeDefaultTranslated &&
17+ TRANSLATABLE_FIELDS . includes ( currentAttribute . type )
18+ ) {
19+ const translate = {
20+ translate : get (
21+ currentAttribute ,
22+ translatePath ,
23+ attributeDefaultTranslated ? 'translate' : 'copy'
24+ ) ,
3825 }
3926
40- acc [ current ] = currentAttribute
27+ const pluginOptions = {
28+ ...( currentAttribute . pluginOptions ?? { } ) ,
29+ translate,
30+ }
31+
32+ return { ...currentAttribute , pluginOptions }
33+ }
4134
42- return acc
43- } ,
44- { }
45- )
35+ return currentAttribute
36+ } )
4637
4738type OmitByPath < T extends object , K extends string [ ] > = Pick <
4839 T ,
0 commit comments