Skip to content
Merged

PD-5670 #2850

Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions SUPPORTED_BROWSERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

> This file is auto-generated from `.browserslistrc` during the prebuild step. Do not edit manually.

| Browser | Minimum version |
| ---------------- | --------------- |
| Android WebView | 145 or newer |
| Apple Safari | 17 or newer |
| Google Chrome | 119 or newer |
| Microsoft Edge | 119 or newer |
| Mozilla Firefox | 119 or newer |
| Opera | 105 or newer |
| Opera Mobile | 80 or newer |
| Samsung Internet | 25 or newer |
| Browser | Minimum version |
|---------|-----------------|
| Android WebView | 145 or newer |
| Apple Safari | 17.2 or newer |
| Google Chrome | 120 or newer |
| Microsoft Edge | 120 or newer |
| Mozilla Firefox | 120 or newer |
| Opera | 106 or newer |
| Opera Mobile | 80 or newer |
| Samsung Internet | 25 or newer |
1 change: 1 addition & 0 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@
{
"glob": "**/*",
"input": "src/assets/print-view/",
"ignore": ["fetch-orcid.js"],
"output": "/print-view/"
},
{
Expand Down
6 changes: 6 additions & 0 deletions scripts/postbuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { renameSync, readFileSync } from 'fs'
import { createShareAssetsFolder } from './moveToShareFolder.postbuild'
import { addOneTrustNotAutoBlockForAppScripts } from './onetrust.postbuild'
import { newRelic } from './new-relic.postbuild'
import { localizeAndWritePrintViewScript } from './print-view-localize.postbuild'

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

// Translate and write the print-view script for every locale using
// @angular/localize/tools so $localize calls are replaced with the
// correct locale's strings at build time.
localizeAndWritePrintViewScript()

// Replace all the `runtime*.js` references to match updated JS values with language code
glob.sync('./dist/*/runtime*.js').forEach((file) => {
const options = getOptionsObjet(file)
Expand Down
126 changes: 126 additions & 0 deletions scripts/print-view-localize.postbuild.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
/**
* Translates src/assets/print-view/fetch-orcid.js for every locale produced by
* `ng build --localize` and writes the result to dist/<locale>/print-view/fetch-orcid.js.
*
* This is required because Angular's `scripts` bundle entries do not run through
* the @angular/localize inlining pass. Instead, we use Babel +
* makeEs2015TranslatePlugin to perform the same substitution here.
*
* Special cases:
* - `en` (source locale): $localize calls are replaced with their English source text.
* - Locales whose XLF filename differs from the folder name (pl→pl_PL, tr→tr_TR,
* zh-CN→zh_CN, zh-TW→zh_TW) are handled via XLF_LOCALE_MAP.
*/

import { existsSync, readFileSync, writeFileSync } from 'fs'
import {
makeEs2015TranslatePlugin,
Xliff1TranslationParser,
Diagnostics,
} from '@angular/localize/tools'

// eslint-disable-next-line @typescript-eslint/no-var-requires
const babel = require('@babel/core')
// eslint-disable-next-line @typescript-eslint/no-var-requires
const glob = require('glob')

/** Maps Angular locale folder name → XLF filename suffix when they differ. */
const XLF_LOCALE_MAP: Record<string, string> = {
pl: 'pl_PL',
tr: 'tr_TR',
'zh-CN': 'zh_CN',
'zh-TW': 'zh_TW',
src: 'source',
}

/** Source file (pre-translation). */
const PRINT_VIEW_SOURCE = './src/assets/print-view/fetch-orcid.js'

function xlfFileForLocale(locale: string): string {
const suffix = XLF_LOCALE_MAP[locale] ?? locale
return `./src/locale/messages.${suffix}.xlf`
}

function getTranslations(locale: string): Record<string, any> | null {
const xlf = xlfFileForLocale(locale)
if (!existsSync(xlf)) {
return null
}
const content = readFileSync(xlf, 'utf8')
const parser = new Xliff1TranslationParser()
const analyzed = (parser as any).analyze(xlf, content) as { canParse: boolean; hint: any }
if (!analyzed.canParse) {
console.warn(`[print-view-localize] Could not parse XLF for locale "${locale}": ${xlf}`)
return null
}
const { translations } = parser.parse(xlf, content, analyzed.hint)
return translations
}

export function localizeAndWritePrintViewScript(): void {
const source = readFileSync(PRINT_VIEW_SOURCE, 'utf8')

// Process every dist locale folder (index.html is the canonical indicator
// that the folder is a locale build output).
const indexFiles: string[] = glob.sync('./dist/*/index.html')

for (const indexFile of indexFiles) {
const localeFolderSegments = indexFile.split('/')
// indexFile pattern: ./dist/<locale>/index.html
const locale = localeFolderSegments[2]
const localeFolder = localeFolderSegments.slice(0, 3).join('/')
const destDir = `${localeFolder}/print-view`
const destFile = `${destDir}/fetch-orcid.js`

let output: string

if (locale === 'share-assets') {
// Not a locale folder — skip.
continue
}

const translations = getTranslations(locale)

if (!translations) {
// No XLF for this locale (includes 'en' which is the source locale):
// inline the source strings via Babel using an empty translation map and
// missingTranslation:'ignore' so the source text is used as the fallback.
const diagnostics = new Diagnostics()
const result = babel.transformSync(source, {
filename: PRINT_VIEW_SOURCE,
plugins: [
makeEs2015TranslatePlugin(diagnostics, {}, {
missingTranslation: 'ignore',
}),
],
configFile: false,
babelrc: false,
})
output = result?.code ?? source
} else {
const diagnostics = new Diagnostics()
const result = babel.transformSync(source, {
filename: PRINT_VIEW_SOURCE,
plugins: [
makeEs2015TranslatePlugin(diagnostics, translations, {
missingTranslation: 'warning',
}),
],
configFile: false,
babelrc: false,
})

if (diagnostics.hasErrors) {
console.warn(
`[print-view-localize] Errors for locale "${locale}":`,
diagnostics.messages,
)
}

output = result?.code ?? source
}

writeFileSync(destFile, output, 'utf8')
console.log(`[print-view-localize] ✓ ${destFile}`)
}
}
10 changes: 5 additions & 5 deletions src/app/cdk/platform-info/supported-browsers.json
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
{
"chrome": {
"major": 119,
"major": 120,
"minor": 0
},
"firefox": {
"major": 119,
"major": 120,
"minor": 0
},
"android": {
"major": 145,
"minor": 0
},
"edge": {
"major": 119,
"major": 120,
"minor": 0
},
"safari": {
"major": 17,
"minor": 0
"minor": 2
},
"op_mob": {
"major": 80,
"minor": 0
},
"opera": {
"major": 105,
"major": 106,
"minor": 0
},
"samsung": {
Expand Down
Loading
Loading