Skip to content

Commit f865c76

Browse files
committed
PD-000 fix-print-view-translations-wont-get-deleted-when-not-use
1 parent 6d02c42 commit f865c76

5 files changed

Lines changed: 117 additions & 221 deletions

File tree

scripts/normalize-xlf.prebuild.ts

Lines changed: 45 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -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 = /:@@(printView\.[A-Za-z0-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-Z0-9_]+):/g, '{$$$1}')
41+
)
42+
units.push({ id, source })
43+
}
44+
return units
45+
}
46+
1047
function 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
})

src/locale/messages.lr.xlf

Lines changed: 19 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -21153,7 +21153,7 @@
2115321153
<target>LR</target>
2115421154
</trans-unit>
2115521155
<trans-unit id="printView.unnamedProfile" datatype="html" resname="printView.unnamedProfile">
21156-
<source>Unnamed ORCID profile</source>
21156+
<source>Name is private</source>
2115721157
<target>LR</target>
2115821158
</trans-unit>
2115921159
<trans-unit id="printView.orcidIdAlt" datatype="html" resname="printView.orcidIdAlt">
@@ -21264,22 +21264,6 @@
2126421264
<source>Identifier</source>
2126521265
<target>LR</target>
2126621266
</trans-unit>
21267-
<trans-unit id="printView.enterOrcidId" datatype="html" resname="printView.enterOrcidId">
21268-
<source>Enter an ORCID iD</source>
21269-
<target>LR</target>
21270-
</trans-unit>
21271-
<trans-unit id="printView.orcidIdHelp" datatype="html" resname="printView.orcidIdHelp">
21272-
<source>Add an ORCID iD to the URL or use the form below.</source>
21273-
<target>LR</target>
21274-
</trans-unit>
21275-
<trans-unit id="printView.loadProfile" datatype="html" resname="printView.loadProfile">
21276-
<source>Load profile</source>
21277-
<target>LR</target>
21278-
</trans-unit>
21279-
<trans-unit id="printView.invalidOrcidId" datatype="html" resname="printView.invalidOrcidId">
21280-
<source>Enter a valid ORCID iD (format: 0000-0000-0000-0000).</source>
21281-
<target>LR</target>
21282-
</trans-unit>
2128321267
<trans-unit id="printView.loadingRecord" datatype="html" resname="printView.loadingRecord">
2128421268
<source>Loading ORCID record...</source>
2128521269
<target>LR</target>
@@ -21292,20 +21276,8 @@
2129221276
<source>Redirecting to primary ORCID record…</source>
2129321277
<target>LR</target>
2129421278
</trans-unit>
21295-
<trans-unit id="printView.fetchFailed" datatype="html" resname="printView.fetchFailed">
21296-
<source>Failed to fetch ORCID record</source>
21297-
<target>LR</target>
21298-
</trans-unit>
21299-
<trans-unit id="printView.couldNotLoad" datatype="html" resname="printView.couldNotLoad">
21300-
<source>Could not load</source>
21301-
<target>LR</target>
21302-
</trans-unit>
21303-
<trans-unit id="printView.activityGroupHeading" datatype="html" resname="printView.activityGroupHeading">
21304-
<source>Activity group heading</source>
21305-
<target>LR</target>
21306-
</trans-unit>
21307-
<trans-unit id="printView.peerReviewHeading" datatype="html" resname="printView.peerReviewHeading">
21308-
<source>Peer review heading</source>
21279+
<trans-unit id="printView.orcidPrintView" datatype="html" resname="printView.orcidPrintView">
21280+
<source>ORCID Print view</source>
2130921281
<target>LR</target>
2131021282
</trans-unit>
2131121283
<trans-unit id="printView.printSaveAsPdf" datatype="html" resname="printView.printSaveAsPdf">
@@ -21332,6 +21304,22 @@
2133221304
<source>Funded by</source>
2133321305
<target>LR</target>
2133421306
</trans-unit>
21307+
<trans-unit id="printView.activityGroupHeading" datatype="html" resname="printView.activityGroupHeading">
21308+
<source>{$TITLE} ({$COUNT})</source>
21309+
<target>LR</target>
21310+
</trans-unit>
21311+
<trans-unit id="printView.peerReviewHeading" datatype="html" resname="printView.peerReviewHeading">
21312+
<source>Peer review ({$REVIEW_COUNT} reviews for {$PUBLICATION_COUNT} publications/grants)</source>
21313+
<target>LR</target>
21314+
</trans-unit>
21315+
<trans-unit id="printView.fetchFailed" datatype="html" resname="printView.fetchFailed">
21316+
<source>Failed to fetch ORCID record ({$STATUS}).</source>
21317+
<target>LR</target>
21318+
</trans-unit>
21319+
<trans-unit id="printView.couldNotLoad" datatype="html" resname="printView.couldNotLoad">
21320+
<source>Could not load {$ORCID_ID}.</source>
21321+
<target>LR</target>
21322+
</trans-unit>
2133521323
</body>
2133621324
</file>
2133721325
</xliff>

src/locale/messages.rl.xlf

Lines changed: 19 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -21153,7 +21153,7 @@
2115321153
<target>RL</target>
2115421154
</trans-unit>
2115521155
<trans-unit id="printView.unnamedProfile" datatype="html" resname="printView.unnamedProfile">
21156-
<source>Unnamed ORCID profile</source>
21156+
<source>Name is private</source>
2115721157
<target>RL</target>
2115821158
</trans-unit>
2115921159
<trans-unit id="printView.orcidIdAlt" datatype="html" resname="printView.orcidIdAlt">
@@ -21264,22 +21264,6 @@
2126421264
<source>Identifier</source>
2126521265
<target>RL</target>
2126621266
</trans-unit>
21267-
<trans-unit id="printView.enterOrcidId" datatype="html" resname="printView.enterOrcidId">
21268-
<source>Enter an ORCID iD</source>
21269-
<target>RL</target>
21270-
</trans-unit>
21271-
<trans-unit id="printView.orcidIdHelp" datatype="html" resname="printView.orcidIdHelp">
21272-
<source>Add an ORCID iD to the URL or use the form below.</source>
21273-
<target>RL</target>
21274-
</trans-unit>
21275-
<trans-unit id="printView.loadProfile" datatype="html" resname="printView.loadProfile">
21276-
<source>Load profile</source>
21277-
<target>RL</target>
21278-
</trans-unit>
21279-
<trans-unit id="printView.invalidOrcidId" datatype="html" resname="printView.invalidOrcidId">
21280-
<source>Enter a valid ORCID iD (format: 0000-0000-0000-0000).</source>
21281-
<target>RL</target>
21282-
</trans-unit>
2128321267
<trans-unit id="printView.loadingRecord" datatype="html" resname="printView.loadingRecord">
2128421268
<source>Loading ORCID record...</source>
2128521269
<target>RL</target>
@@ -21292,20 +21276,8 @@
2129221276
<source>Redirecting to primary ORCID record…</source>
2129321277
<target>RL</target>
2129421278
</trans-unit>
21295-
<trans-unit id="printView.fetchFailed" datatype="html" resname="printView.fetchFailed">
21296-
<source>Failed to fetch ORCID record</source>
21297-
<target>RL</target>
21298-
</trans-unit>
21299-
<trans-unit id="printView.couldNotLoad" datatype="html" resname="printView.couldNotLoad">
21300-
<source>Could not load</source>
21301-
<target>RL</target>
21302-
</trans-unit>
21303-
<trans-unit id="printView.activityGroupHeading" datatype="html" resname="printView.activityGroupHeading">
21304-
<source>Activity group heading</source>
21305-
<target>RL</target>
21306-
</trans-unit>
21307-
<trans-unit id="printView.peerReviewHeading" datatype="html" resname="printView.peerReviewHeading">
21308-
<source>Peer review heading</source>
21279+
<trans-unit id="printView.orcidPrintView" datatype="html" resname="printView.orcidPrintView">
21280+
<source>ORCID Print view</source>
2130921281
<target>RL</target>
2131021282
</trans-unit>
2131121283
<trans-unit id="printView.printSaveAsPdf" datatype="html" resname="printView.printSaveAsPdf">
@@ -21332,6 +21304,22 @@
2133221304
<source>Funded by</source>
2133321305
<target>RL</target>
2133421306
</trans-unit>
21307+
<trans-unit id="printView.activityGroupHeading" datatype="html" resname="printView.activityGroupHeading">
21308+
<source>{$TITLE} ({$COUNT})</source>
21309+
<target>RL</target>
21310+
</trans-unit>
21311+
<trans-unit id="printView.peerReviewHeading" datatype="html" resname="printView.peerReviewHeading">
21312+
<source>Peer review ({$REVIEW_COUNT} reviews for {$PUBLICATION_COUNT} publications/grants)</source>
21313+
<target>RL</target>
21314+
</trans-unit>
21315+
<trans-unit id="printView.fetchFailed" datatype="html" resname="printView.fetchFailed">
21316+
<source>Failed to fetch ORCID record ({$STATUS}).</source>
21317+
<target>RL</target>
21318+
</trans-unit>
21319+
<trans-unit id="printView.couldNotLoad" datatype="html" resname="printView.couldNotLoad">
21320+
<source>Could not load {$ORCID_ID}.</source>
21321+
<target>RL</target>
21322+
</trans-unit>
2133521323
</body>
2133621324
</file>
2133721325
</xliff>

src/locale/messages.xlf

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18909,7 +18909,7 @@
1890918909
</context-group>
1891018910
</trans-unit>
1891118911
<trans-unit id="printView.unnamedProfile" datatype="html" resname="printView.unnamedProfile">
18912-
<source>Unnamed ORCID profile</source>
18912+
<source>Name is private</source>
1891318913
</trans-unit>
1891418914
<trans-unit id="printView.orcidIdAlt" datatype="html" resname="printView.orcidIdAlt">
1891518915
<source>ORCID iD</source>
@@ -18992,18 +18992,6 @@
1899218992
<trans-unit id="printView.identifier" datatype="html" resname="printView.identifier">
1899318993
<source>Identifier</source>
1899418994
</trans-unit>
18995-
<trans-unit id="printView.enterOrcidId" datatype="html" resname="printView.enterOrcidId">
18996-
<source>Enter an ORCID iD</source>
18997-
</trans-unit>
18998-
<trans-unit id="printView.orcidIdHelp" datatype="html" resname="printView.orcidIdHelp">
18999-
<source>Add an ORCID iD to the URL or use the form below.</source>
19000-
</trans-unit>
19001-
<trans-unit id="printView.loadProfile" datatype="html" resname="printView.loadProfile">
19002-
<source>Load profile</source>
19003-
</trans-unit>
19004-
<trans-unit id="printView.invalidOrcidId" datatype="html" resname="printView.invalidOrcidId">
19005-
<source>Enter a valid ORCID iD (format: 0000-0000-0000-0000).</source>
19006-
</trans-unit>
1900718995
<trans-unit id="printView.loadingRecord" datatype="html" resname="printView.loadingRecord">
1900818996
<source>Loading ORCID record...</source>
1900918997
</trans-unit>
@@ -19013,17 +19001,8 @@
1901319001
<trans-unit id="printView.redirectingToPrimary" datatype="html" resname="printView.redirectingToPrimary">
1901419002
<source>Redirecting to primary ORCID record…</source>
1901519003
</trans-unit>
19016-
<trans-unit id="printView.fetchFailed" datatype="html" resname="printView.fetchFailed">
19017-
<source>Failed to fetch ORCID record</source>
19018-
</trans-unit>
19019-
<trans-unit id="printView.couldNotLoad" datatype="html" resname="printView.couldNotLoad">
19020-
<source>Could not load</source>
19021-
</trans-unit>
19022-
<trans-unit id="printView.activityGroupHeading" datatype="html" resname="printView.activityGroupHeading">
19023-
<source>Activity group heading</source>
19024-
</trans-unit>
19025-
<trans-unit id="printView.peerReviewHeading" datatype="html" resname="printView.peerReviewHeading">
19026-
<source>Peer review heading</source>
19004+
<trans-unit id="printView.orcidPrintView" datatype="html" resname="printView.orcidPrintView">
19005+
<source>ORCID Print view</source>
1902719006
</trans-unit>
1902819007
<trans-unit id="printView.printSaveAsPdf" datatype="html" resname="printView.printSaveAsPdf">
1902919008
<source>Print / Save as PDF</source>
@@ -19043,6 +19022,18 @@
1904319022
<trans-unit id="printView.relFundedBy" datatype="html" resname="printView.relFundedBy">
1904419023
<source>Funded by</source>
1904519024
</trans-unit>
19025+
<trans-unit id="printView.activityGroupHeading" datatype="html" resname="printView.activityGroupHeading">
19026+
<source>{$TITLE} ({$COUNT})</source>
19027+
</trans-unit>
19028+
<trans-unit id="printView.peerReviewHeading" datatype="html" resname="printView.peerReviewHeading">
19029+
<source>Peer review ({$REVIEW_COUNT} reviews for {$PUBLICATION_COUNT} publications/grants)</source>
19030+
</trans-unit>
19031+
<trans-unit id="printView.fetchFailed" datatype="html" resname="printView.fetchFailed">
19032+
<source>Failed to fetch ORCID record ({$STATUS}).</source>
19033+
</trans-unit>
19034+
<trans-unit id="printView.couldNotLoad" datatype="html" resname="printView.couldNotLoad">
19035+
<source>Could not load {$ORCID_ID}.</source>
19036+
</trans-unit>
1904619037
</body>
1904719038
</file>
1904819039
</xliff>

0 commit comments

Comments
 (0)