@@ -7,6 +7,43 @@ const TEST_LANGUAGES = [
77 { code : 'rl' , target : 'RL' } ,
88]
99
10+ // Path to the standalone print-view script. Its $localize strings are NOT
11+ // picked up by `ng extract-i18n` (the file is a plain asset, not part of the
12+ // Angular compilation), so we parse them out here and inject them into the
13+ // XLF. Parsing the file directly keeps fetch-orcid.js as the single source of
14+ // truth: strings added/removed there propagate automatically, with no
15+ // hardcoded list to drift out of sync.
16+ const PRINT_VIEW_SOURCE_FILE = './src/assets/print-view/fetch-orcid.js'
17+
18+ interface PrintViewUnit {
19+ id : string
20+ source : string
21+ }
22+
23+ function parsePrintViewUnits ( path : string ) : PrintViewUnit [ ] {
24+ const js = fs . readFileSync ( path , 'utf8' )
25+ // Matches $localize tagged templates of the form `:@@printView.someId:Source text`
26+ const re = / : @ @ ( p r i n t V i e w \. [ A - Z a - z 0 - 9 _ ] + ) : ( [ ^ ` ] * ) ` / g
27+ const units : PrintViewUnit [ ] = [ ]
28+ const seen = new Set < string > ( )
29+ let match : RegExpExecArray | null
30+ while ( ( match = re . exec ( js ) ) !== null ) {
31+ const [ , id , rawSource ] = match
32+ if ( seen . has ( id ) ) {
33+ continue
34+ }
35+ seen . add ( id )
36+ // Convert $localize template placeholders `${expression}:NAME:` into the
37+ // canonical $localize message form `{$NAME}` so the XLF source matches the
38+ // runtime message and stays stable regardless of the JS expression.
39+ const source = normalizeText (
40+ rawSource . replace ( / \$ \{ [ ^ } ] * \} : ( [ A - Z 0 - 9 _ ] + ) : / g, '{$$$1}' )
41+ )
42+ units . push ( { id, source } )
43+ }
44+ return units
45+ }
46+
1047function normalizeText ( input : string ) : string {
1148 return input
1249 . replace ( / \r / g, '' )
@@ -85,115 +122,19 @@ function normalizeXlf12Sources(path: string) {
85122 }
86123 } )
87124
88- // Inject @@printView .* source-only trans-units so the test-language
89- // generator (generateTestingLanguages) will also stamp X / LR / RL for
90- // these strings, and so Transifex can discover them for real locales.
91- // We use a stable @@-prefixed id so $localize can match by explicit id.
92- const PRINT_VIEW_UNITS = [
93- 'printView.unnamedProfile' ,
94- 'printView.orcidIdAlt' ,
95- 'printView.biography' ,
96- 'printView.personalInformation' ,
97- 'printView.emails' ,
98- 'printView.websitesSocialLinks' ,
99- 'printView.otherIds' ,
100- 'printView.keywords' ,
101- 'printView.countries' ,
102- 'printView.activities' ,
103- 'printView.employments' ,
104- 'printView.educationAndQualifications' ,
105- 'printView.professionalActivities' ,
106- 'printView.fundings' ,
107- 'printView.researchResources' ,
108- 'printView.works' ,
109- 'printView.organization' ,
110- 'printView.organizationAddress' ,
111- 'printView.startDate' ,
112- 'printView.endDate' ,
113- 'printView.publicationDate' ,
114- 'printView.journal' ,
115- 'printView.roleTitle' ,
116- 'printView.department' ,
117- 'printView.type' ,
118- 'printView.url' ,
119- 'printView.untitled' ,
120- 'printView.identifier' ,
121- 'printView.enterOrcidId' ,
122- 'printView.orcidIdHelp' ,
123- 'printView.loadProfile' ,
124- 'printView.invalidOrcidId' ,
125- 'printView.loadingRecord' ,
126- 'printView.recordNotFound' ,
127- 'printView.redirectingToPrimary' ,
128- 'printView.fetchFailed' ,
129- 'printView.couldNotLoad' ,
130- 'printView.activityGroupHeading' ,
131- 'printView.peerReviewHeading' ,
132- 'printView.printSaveAsPdf' ,
133- 'printView.printThisOrcidProfile' ,
134- 'printView.relSelf' ,
135- 'printView.relPartOf' ,
136- 'printView.relVersionOf' ,
137- 'printView.relFundedBy' ,
138- ]
139- const PRINT_VIEW_SOURCES : Record < string , string > = {
140- 'printView.unnamedProfile' : 'Unnamed ORCID profile' ,
141- 'printView.orcidIdAlt' : 'ORCID iD' ,
142- 'printView.biography' : 'Biography' ,
143- 'printView.personalInformation' : 'Personal information' ,
144- 'printView.emails' : 'Emails' ,
145- 'printView.websitesSocialLinks' : 'Websites & social links' ,
146- 'printView.otherIds' : 'Other IDs' ,
147- 'printView.keywords' : 'Keywords' ,
148- 'printView.countries' : 'Countries' ,
149- 'printView.activities' : 'Activities' ,
150- 'printView.employments' : 'Employments' ,
151- 'printView.educationAndQualifications' : 'Education and qualifications' ,
152- 'printView.professionalActivities' : 'Professional activities' ,
153- 'printView.fundings' : 'Fundings' ,
154- 'printView.researchResources' : 'Research Resources' ,
155- 'printView.works' : 'Works' ,
156- 'printView.organization' : 'Organization' ,
157- 'printView.organizationAddress' : 'Organization address' ,
158- 'printView.startDate' : 'Start date' ,
159- 'printView.endDate' : 'End date' ,
160- 'printView.publicationDate' : 'Publication date' ,
161- 'printView.journal' : 'Journal' ,
162- 'printView.roleTitle' : 'Role title' ,
163- 'printView.department' : 'Department' ,
164- 'printView.type' : 'Type' ,
165- 'printView.url' : 'URL' ,
166- 'printView.untitled' : 'Untitled' ,
167- 'printView.identifier' : 'Identifier' ,
168- 'printView.enterOrcidId' : 'Enter an ORCID iD' ,
169- 'printView.orcidIdHelp' :
170- 'Add an ORCID iD to the URL or use the form below.' ,
171- 'printView.loadProfile' : 'Load profile' ,
172- 'printView.invalidOrcidId' :
173- 'Enter a valid ORCID iD (format: 0000-0000-0000-0000).' ,
174- 'printView.loadingRecord' : 'Loading ORCID record...' ,
175- 'printView.recordNotFound' :
176- 'Record data was not found in ORCID response.' ,
177- 'printView.redirectingToPrimary' :
178- 'Redirecting to primary ORCID record\u2026' ,
179- 'printView.fetchFailed' : 'Failed to fetch ORCID record' ,
180- 'printView.couldNotLoad' : 'Could not load' ,
181- 'printView.activityGroupHeading' : 'Activity group heading' ,
182- 'printView.peerReviewHeading' : 'Peer review heading' ,
183- 'printView.printSaveAsPdf' : 'Print / Save as PDF' ,
184- 'printView.printThisOrcidProfile' : 'Print this ORCID profile' ,
185- 'printView.relSelf' : 'Self' ,
186- 'printView.relPartOf' : 'Part of' ,
187- 'printView.relVersionOf' : 'Version of' ,
188- 'printView.relFundedBy' : 'Funded by' ,
189- }
125+ // Inject @@printView .* source-only trans-units parsed from the standalone
126+ // print-view script so the test-language generator (generateTestingLanguages)
127+ // will also stamp X / LR / RL for these strings, and so Transifex can
128+ // discover them for real locales. We use a stable @@-prefixed id so
129+ // $localize can match by explicit id.
130+ const printViewUnits = parsePrintViewUnits ( PRINT_VIEW_SOURCE_FILE )
190131 const existingIds = new Set ( transUnits . map ( ( tu : any ) => tu ?. $ ?. id ) )
191132 const printViewBody = fileNode ?. body ?. [ 0 ]
192- PRINT_VIEW_UNITS . forEach ( ( id ) => {
133+ printViewUnits . forEach ( ( { id , source } ) => {
193134 if ( ! existingIds . has ( id ) ) {
194135 printViewBody [ 'trans-unit' ] . push ( {
195136 $ : { id, datatype : 'html' , resname : id } ,
196- source : [ PRINT_VIEW_SOURCES [ id ] ?? id ] ,
137+ source : [ source ] ,
197138 } )
198139 }
199140 } )
0 commit comments