Skip to content

Commit 08a0746

Browse files
committed
PD-5670
1 parent 6502811 commit 08a0746

7 files changed

Lines changed: 394 additions & 56 deletions

File tree

SUPPORTED_BROWSERS.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
> This file is auto-generated from `.browserslistrc` during the prebuild step. Do not edit manually.
44
5-
| Browser | Minimum version |
6-
| ---------------- | --------------- |
7-
| Android WebView | 145 or newer |
8-
| Apple Safari | 17 or newer |
9-
| Google Chrome | 119 or newer |
10-
| Microsoft Edge | 119 or newer |
11-
| Mozilla Firefox | 119 or newer |
12-
| Opera | 105 or newer |
13-
| Opera Mobile | 80 or newer |
14-
| Samsung Internet | 25 or newer |
5+
| Browser | Minimum version |
6+
|---------|-----------------|
7+
| Android WebView | 145 or newer |
8+
| Apple Safari | 17.2 or newer |
9+
| Google Chrome | 120 or newer |
10+
| Microsoft Edge | 120 or newer |
11+
| Mozilla Firefox | 120 or newer |
12+
| Opera | 106 or newer |
13+
| Opera Mobile | 80 or newer |
14+
| Samsung Internet | 25 or newer |

angular.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@
123123
{
124124
"glob": "**/*",
125125
"input": "src/assets/print-view/",
126+
"ignore": ["fetch-orcid.js"],
126127
"output": "/print-view/"
127128
},
128129
{

scripts/postbuild.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { renameSync, readFileSync } from 'fs'
1010
import { createShareAssetsFolder } from './moveToShareFolder.postbuild'
1111
import { addOneTrustNotAutoBlockForAppScripts } from './onetrust.postbuild'
1212
import { newRelic } from './new-relic.postbuild'
13+
import { localizeAndWritePrintViewScript } from './print-view-localize.postbuild'
1314

1415
const glob = require('glob')
1516
// Run updates on index.html files across languages
@@ -38,6 +39,11 @@ glob.sync('./dist/*/*.js').forEach((file) => {
3839
replacedHash[hash] = true
3940
})
4041

42+
// Translate and write the print-view script for every locale using
43+
// @angular/localize/tools so $localize calls are replaced with the
44+
// correct locale's strings at build time.
45+
localizeAndWritePrintViewScript()
46+
4147
// Replace all the `runtime*.js` references to match updated JS values with language code
4248
glob.sync('./dist/*/runtime*.js').forEach((file) => {
4349
const options = getOptionsObjet(file)
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
/**
2+
* Translates src/assets/print-view/fetch-orcid.js for every locale produced by
3+
* `ng build --localize` and writes the result to dist/<locale>/print-view/fetch-orcid.js.
4+
*
5+
* This is required because Angular's `scripts` bundle entries do not run through
6+
* the @angular/localize inlining pass. Instead, we use Babel +
7+
* makeEs2015TranslatePlugin to perform the same substitution here.
8+
*
9+
* Special cases:
10+
* - `en` (source locale): $localize calls are replaced with their English source text.
11+
* - Locales whose XLF filename differs from the folder name (pl→pl_PL, tr→tr_TR,
12+
* zh-CN→zh_CN, zh-TW→zh_TW) are handled via XLF_LOCALE_MAP.
13+
*/
14+
15+
import { existsSync, readFileSync, writeFileSync } from 'fs'
16+
import {
17+
makeEs2015TranslatePlugin,
18+
Xliff1TranslationParser,
19+
Diagnostics,
20+
} from '@angular/localize/tools'
21+
22+
// eslint-disable-next-line @typescript-eslint/no-var-requires
23+
const babel = require('@babel/core')
24+
// eslint-disable-next-line @typescript-eslint/no-var-requires
25+
const glob = require('glob')
26+
27+
/** Maps Angular locale folder name → XLF filename suffix when they differ. */
28+
const XLF_LOCALE_MAP: Record<string, string> = {
29+
pl: 'pl_PL',
30+
tr: 'tr_TR',
31+
'zh-CN': 'zh_CN',
32+
'zh-TW': 'zh_TW',
33+
src: 'source',
34+
}
35+
36+
/** Source file (pre-translation). */
37+
const PRINT_VIEW_SOURCE = './src/assets/print-view/fetch-orcid.js'
38+
39+
function xlfFileForLocale(locale: string): string {
40+
const suffix = XLF_LOCALE_MAP[locale] ?? locale
41+
return `./src/locale/messages.${suffix}.xlf`
42+
}
43+
44+
function getTranslations(locale: string): Record<string, any> | null {
45+
const xlf = xlfFileForLocale(locale)
46+
if (!existsSync(xlf)) {
47+
return null
48+
}
49+
const content = readFileSync(xlf, 'utf8')
50+
const parser = new Xliff1TranslationParser()
51+
const analyzed = (parser as any).analyze(xlf, content) as { canParse: boolean; hint: any }
52+
if (!analyzed.canParse) {
53+
console.warn(`[print-view-localize] Could not parse XLF for locale "${locale}": ${xlf}`)
54+
return null
55+
}
56+
const { translations } = parser.parse(xlf, content, analyzed.hint)
57+
return translations
58+
}
59+
60+
export function localizeAndWritePrintViewScript(): void {
61+
const source = readFileSync(PRINT_VIEW_SOURCE, 'utf8')
62+
63+
// Process every dist locale folder (index.html is the canonical indicator
64+
// that the folder is a locale build output).
65+
const indexFiles: string[] = glob.sync('./dist/*/index.html')
66+
67+
for (const indexFile of indexFiles) {
68+
const localeFolderSegments = indexFile.split('/')
69+
// indexFile pattern: ./dist/<locale>/index.html
70+
const locale = localeFolderSegments[2]
71+
const localeFolder = localeFolderSegments.slice(0, 3).join('/')
72+
const destDir = `${localeFolder}/print-view`
73+
const destFile = `${destDir}/fetch-orcid.js`
74+
75+
let output: string
76+
77+
if (locale === 'share-assets') {
78+
// Not a locale folder — skip.
79+
continue
80+
}
81+
82+
const translations = getTranslations(locale)
83+
84+
if (!translations) {
85+
// No XLF for this locale (includes 'en' which is the source locale):
86+
// inline the source strings via Babel using an empty translation map and
87+
// missingTranslation:'ignore' so the source text is used as the fallback.
88+
const diagnostics = new Diagnostics()
89+
const result = babel.transformSync(source, {
90+
filename: PRINT_VIEW_SOURCE,
91+
plugins: [
92+
makeEs2015TranslatePlugin(diagnostics, {}, {
93+
missingTranslation: 'ignore',
94+
}),
95+
],
96+
configFile: false,
97+
babelrc: false,
98+
})
99+
output = result?.code ?? source
100+
} else {
101+
const diagnostics = new Diagnostics()
102+
const result = babel.transformSync(source, {
103+
filename: PRINT_VIEW_SOURCE,
104+
plugins: [
105+
makeEs2015TranslatePlugin(diagnostics, translations, {
106+
missingTranslation: 'warning',
107+
}),
108+
],
109+
configFile: false,
110+
babelrc: false,
111+
})
112+
113+
if (diagnostics.hasErrors) {
114+
console.warn(
115+
`[print-view-localize] Errors for locale "${locale}":`,
116+
diagnostics.messages,
117+
)
118+
}
119+
120+
output = result?.code ?? source
121+
}
122+
123+
writeFileSync(destFile, output, 'utf8')
124+
console.log(`[print-view-localize] ✓ ${destFile}`)
125+
}
126+
}

src/app/cdk/platform-info/supported-browsers.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
{
22
"chrome": {
3-
"major": 119,
3+
"major": 120,
44
"minor": 0
55
},
66
"firefox": {
7-
"major": 119,
7+
"major": 120,
88
"minor": 0
99
},
1010
"android": {
1111
"major": 145,
1212
"minor": 0
1313
},
1414
"edge": {
15-
"major": 119,
15+
"major": 120,
1616
"minor": 0
1717
},
1818
"safari": {
1919
"major": 17,
20-
"minor": 0
20+
"minor": 2
2121
},
2222
"op_mob": {
2323
"major": 80,
2424
"minor": 0
2525
},
2626
"opera": {
27-
"major": 105,
27+
"major": 106,
2828
"minor": 0
2929
},
3030
"samsung": {

0 commit comments

Comments
 (0)