@@ -19,7 +19,10 @@ import { createTranslationLoader } from './load-translations';
19
19
export interface I18nOptions {
20
20
inlineLocales : Set < string > ;
21
21
sourceLocale : string ;
22
- locales : Record < string , { file : string ; format ?: string ; translation ?: unknown } > ;
22
+ locales : Record <
23
+ string ,
24
+ { file : string ; format ?: string ; translation ?: unknown ; dataPath ?: string }
25
+ > ;
23
26
flatOutput ?: boolean ;
24
27
readonly shouldInline : boolean ;
25
28
}
@@ -127,9 +130,16 @@ export async function configureI18nBuild<T extends BrowserBuilderSchema | Server
127
130
}
128
131
129
132
if ( i18n . inlineLocales . size > 0 ) {
133
+ const projectRoot = path . join ( context . workspaceRoot , ( metadata . root as string ) || '' ) ;
134
+ const localeDataBasePath = findLocaleDataBasePath ( projectRoot ) ;
135
+ if ( ! localeDataBasePath ) {
136
+ throw new Error (
137
+ `Unable to find locale data within '@angular/common'. Please ensure '@angular/common' is installed.` ,
138
+ ) ;
139
+ }
140
+
130
141
// Load locales
131
142
const loader = await createTranslationLoader ( ) ;
132
- const projectRoot = path . join ( context . workspaceRoot , ( metadata . root as string ) || '' ) ;
133
143
const usedFormats = new Set < string > ( ) ;
134
144
for ( const [ locale , desc ] of Object . entries ( i18n . locales ) ) {
135
145
if ( i18n . inlineLocales . has ( locale ) && desc . file ) {
@@ -145,19 +155,22 @@ export async function configureI18nBuild<T extends BrowserBuilderSchema | Server
145
155
146
156
desc . format = result . format ;
147
157
desc . translation = result . translation ;
158
+
159
+ const localeDataPath = findLocaleDataPath ( locale , localeDataBasePath ) ;
160
+ if ( ! localeDataPath ) {
161
+ context . logger . warn (
162
+ `Locale data for '${ locale } ' cannot be found. No locale data will be included for this locale.` ,
163
+ ) ;
164
+ } else {
165
+ desc . dataPath = localeDataPath ;
166
+ }
148
167
}
149
168
}
150
169
151
170
// Legacy message id's require the format of the translations
152
171
if ( usedFormats . size > 0 ) {
153
172
buildOptions . i18nFormat = [ ...usedFormats ] [ 0 ] ;
154
173
}
155
-
156
- // If only one locale is specified set the deprecated option to enable the webpack plugin
157
- // transform to register the locale directly in the output bundle.
158
- if ( i18n . inlineLocales . size === 1 ) {
159
- buildOptions . i18nLocale = [ ...i18n . inlineLocales ] [ 0 ] ;
160
- }
161
174
}
162
175
163
176
// If inlining store the output in a temporary location to facilitate post-processing
@@ -202,3 +215,30 @@ function mergeDeprecatedI18nOptions(
202
215
203
216
return i18n ;
204
217
}
218
+
219
+ function findLocaleDataBasePath ( projectRoot : string ) : string | null {
220
+ try {
221
+ const commonPath = path . dirname (
222
+ require . resolve ( '@angular/common/package.json' , { paths : [ projectRoot ] } ) ,
223
+ ) ;
224
+ const localesPath = path . join ( commonPath , 'locales/global' ) ;
225
+
226
+ if ( ! fs . existsSync ( localesPath ) ) {
227
+ return null ;
228
+ }
229
+
230
+ return localesPath ;
231
+ } catch {
232
+ return null ;
233
+ }
234
+ }
235
+
236
+ function findLocaleDataPath ( locale : string , basePath : string ) : string | null {
237
+ const localeDataPath = path . join ( basePath , locale + '.js' ) ;
238
+
239
+ if ( ! fs . existsSync ( localeDataPath ) ) {
240
+ return null ;
241
+ }
242
+
243
+ return localeDataPath ;
244
+ }
0 commit comments