@@ -19,7 +19,10 @@ import { createTranslationLoader } from './load-translations';
1919export interface I18nOptions {
2020 inlineLocales : Set < string > ;
2121 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+ > ;
2326 flatOutput ?: boolean ;
2427 readonly shouldInline : boolean ;
2528}
@@ -127,9 +130,16 @@ export async function configureI18nBuild<T extends BrowserBuilderSchema | Server
127130 }
128131
129132 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+
130141 // Load locales
131142 const loader = await createTranslationLoader ( ) ;
132- const projectRoot = path . join ( context . workspaceRoot , ( metadata . root as string ) || '' ) ;
133143 const usedFormats = new Set < string > ( ) ;
134144 for ( const [ locale , desc ] of Object . entries ( i18n . locales ) ) {
135145 if ( i18n . inlineLocales . has ( locale ) && desc . file ) {
@@ -145,19 +155,22 @@ export async function configureI18nBuild<T extends BrowserBuilderSchema | Server
145155
146156 desc . format = result . format ;
147157 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+ }
148167 }
149168 }
150169
151170 // Legacy message id's require the format of the translations
152171 if ( usedFormats . size > 0 ) {
153172 buildOptions . i18nFormat = [ ...usedFormats ] [ 0 ] ;
154173 }
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- }
161174 }
162175
163176 // If inlining store the output in a temporary location to facilitate post-processing
@@ -202,3 +215,30 @@ function mergeDeprecatedI18nOptions(
202215
203216 return i18n ;
204217}
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