@@ -10,18 +10,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
1010 return ( mod && mod . __esModule ) ? mod : { "default" : mod } ;
1111} ;
1212Object . defineProperty ( exports , "__esModule" , { value : true } ) ;
13- exports . loadTranslations = exports . configureI18nBuild = exports . createI18nOptions = void 0 ;
14- const node_fs_1 = __importDefault ( require ( "node:fs" ) ) ;
15- const node_module_1 = require ( "node:module" ) ;
16- const node_os_1 = __importDefault ( require ( "node:os" ) ) ;
13+ exports . loadTranslations = exports . createI18nOptions = void 0 ;
1714const node_path_1 = __importDefault ( require ( "node:path" ) ) ;
18- const schema_1 = require ( "../builders/browser/schema" ) ;
19- const read_tsconfig_1 = require ( "../utils/read-tsconfig" ) ;
20- const load_translations_1 = require ( "./load-translations" ) ;
21- /**
22- * The base module location used to search for locale specific data.
23- */
24- const LOCALE_DATA_BASE_MODULE = '@angular/common/locales/global' ;
2515function normalizeTranslationFileOption ( option , locale , expectObjectInError ) {
2616 if ( typeof option === 'string' ) {
2717 return [ option ] ;
@@ -123,89 +113,6 @@ function createI18nOptions(projectMetadata, inline) {
123113 return i18n ;
124114}
125115exports . createI18nOptions = createI18nOptions ;
126- async function configureI18nBuild ( context , options ) {
127- if ( ! context . target ) {
128- throw new Error ( 'The builder requires a target.' ) ;
129- }
130- const buildOptions = { ...options } ;
131- const tsConfig = await ( 0 , read_tsconfig_1 . readTsconfig ) ( buildOptions . tsConfig , context . workspaceRoot ) ;
132- const metadata = await context . getProjectMetadata ( context . target ) ;
133- const i18n = createI18nOptions ( metadata , buildOptions . localize ) ;
134- // No additional processing needed if no inlining requested and no source locale defined.
135- if ( ! i18n . shouldInline && ! i18n . hasDefinedSourceLocale ) {
136- return { buildOptions, i18n } ;
137- }
138- const projectRoot = node_path_1 . default . join ( context . workspaceRoot , metadata . root || '' ) ;
139- // The trailing slash is required to signal that the path is a directory and not a file.
140- const projectRequire = ( 0 , node_module_1 . createRequire ) ( projectRoot + '/' ) ;
141- const localeResolver = ( locale ) => projectRequire . resolve ( node_path_1 . default . join ( LOCALE_DATA_BASE_MODULE , locale ) ) ;
142- // Load locale data and translations (if present)
143- let loader ;
144- const usedFormats = new Set ( ) ;
145- for ( const [ locale , desc ] of Object . entries ( i18n . locales ) ) {
146- if ( ! i18n . inlineLocales . has ( locale ) && locale !== i18n . sourceLocale ) {
147- continue ;
148- }
149- let localeDataPath = findLocaleDataPath ( locale , localeResolver ) ;
150- if ( ! localeDataPath ) {
151- const [ first ] = locale . split ( '-' ) ;
152- if ( first ) {
153- localeDataPath = findLocaleDataPath ( first . toLowerCase ( ) , localeResolver ) ;
154- if ( localeDataPath ) {
155- context . logger . warn ( `Locale data for '${ locale } ' cannot be found. Using locale data for '${ first } '.` ) ;
156- }
157- }
158- }
159- if ( ! localeDataPath ) {
160- context . logger . warn ( `Locale data for '${ locale } ' cannot be found. No locale data will be included for this locale.` ) ;
161- }
162- else {
163- desc . dataPath = localeDataPath ;
164- }
165- if ( ! desc . files . length ) {
166- continue ;
167- }
168- loader ??= await ( 0 , load_translations_1 . createTranslationLoader ) ( ) ;
169- loadTranslations ( locale , desc , context . workspaceRoot , loader , {
170- warn ( message ) {
171- context . logger . warn ( message ) ;
172- } ,
173- error ( message ) {
174- throw new Error ( message ) ;
175- } ,
176- } , usedFormats , buildOptions . i18nDuplicateTranslation ) ;
177- if ( usedFormats . size > 1 && tsConfig . options . enableI18nLegacyMessageIdFormat !== false ) {
178- // This limitation is only for legacy message id support (defaults to true as of 9.0)
179- throw new Error ( 'Localization currently only supports using one type of translation file format for the entire application.' ) ;
180- }
181- }
182- // If inlining store the output in a temporary location to facilitate post-processing
183- if ( i18n . shouldInline ) {
184- // TODO: we should likely save these in the .angular directory in the next major version.
185- // We'd need to do a migration to add the temp directory to gitignore.
186- const tempPath = node_fs_1 . default . mkdtempSync ( node_path_1 . default . join ( node_fs_1 . default . realpathSync ( node_os_1 . default . tmpdir ( ) ) , 'angular-cli-i18n-' ) ) ;
187- buildOptions . outputPath = tempPath ;
188- process . on ( 'exit' , ( ) => {
189- try {
190- node_fs_1 . default . rmSync ( tempPath , { force : true , recursive : true , maxRetries : 3 } ) ;
191- }
192- catch { }
193- } ) ;
194- }
195- return { buildOptions, i18n } ;
196- }
197- exports . configureI18nBuild = configureI18nBuild ;
198- function findLocaleDataPath ( locale , resolver ) {
199- // Remove private use subtags
200- const scrubbedLocale = locale . replace ( / - x ( - [ a - z A - Z 0 - 9 ] { 1 , 8 } ) + $ / , '' ) ;
201- try {
202- return resolver ( scrubbedLocale ) ;
203- }
204- catch {
205- // fallback to known existing en-US locale data as of 14.0
206- return scrubbedLocale === 'en-US' ? findLocaleDataPath ( 'en' , resolver ) : null ;
207- }
208- }
209116function loadTranslations ( locale , desc , workspaceRoot , loader , logger , usedFormats , duplicateTranslation ) {
210117 let translations = undefined ;
211118 for ( const file of desc . files ) {
@@ -230,12 +137,12 @@ function loadTranslations(locale, desc, workspaceRoot, loader, logger, usedForma
230137 if ( translations [ id ] !== undefined ) {
231138 const duplicateTranslationMessage = `[${ file . path } ]: Duplicate translations for message '${ id } ' when merging.` ;
232139 switch ( duplicateTranslation ) {
233- case schema_1 . I18NTranslation . Ignore :
140+ case 'ignore' :
234141 break ;
235- case schema_1 . I18NTranslation . Error :
142+ case 'error' :
236143 logger . error ( `ERROR ${ duplicateTranslationMessage } ` ) ;
237144 break ;
238- case schema_1 . I18NTranslation . Warning :
145+ case 'warning' :
239146 default :
240147 logger . warn ( `WARNING ${ duplicateTranslationMessage } ` ) ;
241148 break ;
0 commit comments