Skip to content

Commit d4f254a

Browse files
authored
Merge pull request #2866 from ORCID/lmendoza/PD-0000-fix-print-view-translations-wont-get-deleted-when-not-use
PD-000 fix-print-view-translations-wont-get-deleted-when-not-use
2 parents 6d02c42 + 66589ce commit d4f254a

8 files changed

Lines changed: 131 additions & 739 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/app/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ export const ApplicationRoutesLabels = {
137137
[ApplicationRoutes.resetPasswordEmail]: $localize`:@@share.resetPasswordEmail:Reset password - ORCID`,
138138
[ApplicationRoutes.selfService]: $localize`:@@share.selfService:Self Service - ORCID`,
139139
[ApplicationRoutes.developerTools]: $localize`:@@share.developerTools:Developer tools - ORCID`,
140-
[ApplicationRoutes.smsPoc]: $localize`:@@share.smsPoc:SMS POC - ORCID`,
140+
[ApplicationRoutes.smsPoc]: 'SMS POC - ORCID',
141141
}
142142

143143
export const ApplicationDynamicRoutesLabels = {

src/app/sms-poc/pages/sms-poc/sms-poc.component.html

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
<mat-card class="sms-poc-card max-w-[560px] sm:p-10! p-6!">
2-
<h1 class="orc-font-heading-small font-normal mb-4" i18n="@@smsPoc.title">
2+
<h1 class="orc-font-heading-small font-normal mb-4">
33
SMS POC
44
</h1>
5-
<p
6-
class="sms-poc-description orc-font-body-small mb-4"
7-
i18n="@@smsPoc.description"
8-
>
5+
<p class="sms-poc-description orc-font-body-small mb-4">
96
Send a test SMS. Choose AWS or Twilio for each send.
107
</p>
118

129
<app-alert-message type="warning" role="note" class="mb-6 block">
1310
<div content>
14-
<span i18n="@@smsPoc.sandboxNotice">
11+
<span>
1512
This POC currently runs in SANDBOX mode. If you want to test actual SMS
1613
delivery to your phone, please reach out to Leo on Slack to add your
1714
phone number to our AWS SNS ORCID Friend Sandbox and the Twilio
@@ -22,21 +19,18 @@ <h1 class="orc-font-heading-small font-normal mb-4" i18n="@@smsPoc.title">
2219

2320
<form [formGroup]="smsForm" (ngSubmit)="onSubmit()" class="grid gap-4">
2421
<div class="provider-selection">
25-
<span
26-
class="orc-font-small-print leading-4.5 font-bold! block mb-2"
27-
i18n="@@smsPoc.provider"
28-
>
22+
<span class="orc-font-small-print leading-4.5 font-bold! block mb-2">
2923
Provider
3024
</span>
3125
<mat-radio-group
3226
formControlName="provider"
3327
color="primary"
3428
class="provider-group flex gap-4"
3529
>
36-
<mat-radio-button value="aws" i18n="@@smsPoc.providerAws">
30+
<mat-radio-button value="aws">
3731
AWS SNS
3832
</mat-radio-button>
39-
<mat-radio-button value="twilio" i18n="@@smsPoc.providerTwilio">
33+
<mat-radio-button value="twilio">
4034
Twilio
4135
</mat-radio-button>
4236
</mat-radio-group>
@@ -46,7 +40,6 @@ <h1 class="orc-font-heading-small font-normal mb-4" i18n="@@smsPoc.title">
4640
<label
4741
class="orc-font-small-print leading-4.5 font-bold! block mb-2"
4842
for="sms-poc-phone"
49-
i18n="@@smsPoc.phoneNumber"
5043
>
5144
Phone number
5245
</label>
@@ -66,7 +59,7 @@ <h1 class="orc-font-heading-small font-normal mb-4" i18n="@@smsPoc.title">
6659
</div>
6760

6861
<mat-form-field appearance="outline" [hideRequiredMarker]="true">
69-
<mat-label i18n="@@smsPoc.message">Message</mat-label>
62+
<mat-label>Message</mat-label>
7063
<textarea
7164
matInput
7265
formControlName="message"
@@ -75,9 +68,9 @@ <h1 class="orc-font-heading-small font-normal mb-4" i18n="@@smsPoc.title">
7568
></textarea>
7669
<mat-hint align="end">{{ message?.value?.length || 0 }}/1600</mat-hint>
7770
@if (message?.hasError('required') && message?.touched) {
78-
<mat-error i18n="@@smsPoc.messageRequired">Message is required</mat-error>
71+
<mat-error>Message is required</mat-error>
7972
} @if (message?.hasError('maxlength') && message?.touched) {
80-
<mat-error i18n="@@smsPoc.messageTooLong">
73+
<mat-error>
8174
Message must be 1600 characters or fewer
8275
</mat-error>
8376
}
@@ -90,7 +83,7 @@ <h1 class="orc-font-heading-small font-normal mb-4" i18n="@@smsPoc.title">
9083
} @if (response?.success) {
9184
<app-alert-message type="success" role="status" class="mb-2">
9285
<div content>
93-
<span i18n="@@smsPoc.sent">SMS sent.</span>
86+
<span>SMS sent.</span>
9487
<span>
9588
{{ response.provider }}:
9689
{{ response.providerMessageId || response.status }}
@@ -107,7 +100,6 @@ <h1 class="orc-font-heading-small font-normal mb-4" i18n="@@smsPoc.title">
107100
type="submit"
108101
[disabled]="loading"
109102
[ngClass]="{ 'button-loading': loading }"
110-
i18n="@@smsPoc.send"
111103
>
112104
Send SMS
113105
</button>

src/app/sms-poc/pages/sms-poc/sms-poc.component.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ export class SmsPocComponent implements OnInit {
4343
return null
4444
}
4545
if (this.phoneNumber.hasError('required')) {
46-
return $localize`:@@smsPoc.phoneRequired:Phone number is required`
46+
return 'Phone number is required'
4747
}
4848
if (this.phoneNumber.hasError('invalidPhone')) {
49-
return $localize`:@@smsPoc.phoneInvalid:Enter a valid phone number`
49+
return 'Enter a valid phone number'
5050
}
5151
return null
5252
}
@@ -73,7 +73,7 @@ export class SmsPocComponent implements OnInit {
7373
},
7474
error: () => {
7575
this.loading = false
76-
this.backendError = $localize`:@@smsPoc.sendFailed:SMS send failed`
76+
this.backendError = 'SMS send failed'
7777
},
7878
})
7979
}

0 commit comments

Comments
 (0)