@@ -15,7 +15,7 @@ import {
15
15
removePropertyInAstObject ,
16
16
} from '../../utility/json-utils' ;
17
17
import { Builders } from '../../utility/workspace-models' ;
18
- import { getAllOptions , getTargets , getWorkspace , isIvyEnabled } from './utils' ;
18
+ import { getAllOptions , getProjectTarget , getTargets , getWorkspace , isIvyEnabled } from './utils' ;
19
19
20
20
export const ANY_COMPONENT_STYLE_BUDGET = {
21
21
type : 'anyComponentStyle' ,
@@ -33,6 +33,7 @@ export function updateWorkspaceConfig(): Rule {
33
33
updateStyleOrScriptOption ( 'scripts' , recorder , target ) ;
34
34
addAnyComponentStyleBudget ( recorder , target ) ;
35
35
updateAotOption ( tree , recorder , target ) ;
36
+ addBuilderI18NOptions ( recorder , target ) ;
36
37
}
37
38
38
39
for ( const { target } of getTargets ( workspace , 'test' , Builders . Karma ) ) {
@@ -42,6 +43,11 @@ export function updateWorkspaceConfig(): Rule {
42
43
43
44
for ( const { target } of getTargets ( workspace , 'server' , Builders . Server ) ) {
44
45
updateOptimizationOption ( recorder , target ) ;
46
+ addBuilderI18NOptions ( recorder , target ) ;
47
+ }
48
+
49
+ for ( const { target, project } of getTargets ( workspace , 'extract-i18n' , Builders . ExtractI18n ) ) {
50
+ addProjectI18NOptions ( recorder , target , project ) ;
45
51
}
46
52
47
53
tree . commitUpdate ( recorder ) ;
@@ -50,6 +56,72 @@ export function updateWorkspaceConfig(): Rule {
50
56
} ;
51
57
}
52
58
59
+ function addProjectI18NOptions ( recorder : UpdateRecorder , builderConfig : JsonAstObject , projectConfig : JsonAstObject ) {
60
+ const browserConfig = getProjectTarget ( projectConfig , 'build' , Builders . Browser ) ;
61
+ if ( ! browserConfig || browserConfig . kind !== 'object' ) {
62
+ return ;
63
+ }
64
+
65
+ // browser builder options
66
+ let locales : Record < string , string > | undefined ;
67
+ const options = getAllOptions ( browserConfig ) ;
68
+ for ( const option of options ) {
69
+ const localeId = findPropertyInAstObject ( option , 'i18nLocale' ) ;
70
+ if ( ! localeId || localeId . kind !== 'string' ) {
71
+ continue ;
72
+ }
73
+
74
+ const localeFile = findPropertyInAstObject ( option , 'i18nFile' ) ;
75
+ if ( ! localeFile || localeFile . kind !== 'string' ) {
76
+ continue ;
77
+ }
78
+
79
+ const localIdValue = localeId . value ;
80
+ const localeFileValue = localeFile . value ;
81
+
82
+ if ( ! locales ) {
83
+ locales = {
84
+ [ localIdValue ] : localeFileValue ,
85
+ } ;
86
+ } else {
87
+ locales [ localIdValue ] = localeFileValue ;
88
+ }
89
+ }
90
+
91
+ if ( locales ) {
92
+ // Get sourceLocale from extract-i18n builder
93
+ const i18nOptions = getAllOptions ( builderConfig ) ;
94
+ const sourceLocale = i18nOptions
95
+ . map ( o => {
96
+ const sourceLocale = findPropertyInAstObject ( o , 'i18nLocale' ) ;
97
+
98
+ return sourceLocale && sourceLocale . value ;
99
+ } )
100
+ . find ( x => ! ! x ) ;
101
+
102
+ // Add i18n project configuration
103
+ insertPropertyInAstObjectInOrder ( recorder , projectConfig , 'i18n' , {
104
+ locales,
105
+ // tslint:disable-next-line: no-any
106
+ sourceLocale : sourceLocale as any ,
107
+ } , 6 ) ;
108
+ }
109
+ }
110
+
111
+ function addBuilderI18NOptions ( recorder : UpdateRecorder , builderConfig : JsonAstObject ) {
112
+ const options = getAllOptions ( builderConfig ) ;
113
+
114
+ for ( const option of options ) {
115
+ const localeId = findPropertyInAstObject ( option , 'i18nLocale' ) ;
116
+ if ( ! localeId || localeId . kind !== 'string' ) {
117
+ continue ;
118
+ }
119
+
120
+ // add new localize option
121
+ insertPropertyInAstObjectInOrder ( recorder , option , 'localize' , [ localeId . value ] , 12 ) ;
122
+ }
123
+ }
124
+
53
125
function updateAotOption ( tree : Tree , recorder : UpdateRecorder , builderConfig : JsonAstObject ) {
54
126
const options = findPropertyInAstObject ( builderConfig , 'options' ) ;
55
127
if ( ! options || options . kind !== 'object' ) {
0 commit comments