From dfcc30bb0bcada29ce7f19121f2632126c72fd0f Mon Sep 17 00:00:00 2001 From: Alex Rudenko Date: Wed, 19 Nov 2025 10:28:52 +0100 Subject: [PATCH] chore: remove i18n mocks --- scripts/post-build.ts | 75 ++++++---------------------- src/DevtoolsUtils.ts | 11 ++++ tests/trace-processing/parse.test.ts | 2 + tsconfig.json | 8 +-- 4 files changed, 31 insertions(+), 65 deletions(-) diff --git a/scripts/post-build.ts b/scripts/post-build.ts index b520d6a07..0010e22ef 100644 --- a/scripts/post-build.ts +++ b/scripts/post-build.ts @@ -53,69 +53,22 @@ function main(): void { // Create i18n mock const i18nDir = path.join(BUILD_DIR, devtoolsFrontEndCorePath, 'i18n'); - fs.mkdirSync(i18nDir, {recursive: true}); - const i18nFile = path.join(i18nDir, 'i18n.js'); - const i18nContent = ` -export const i18n = { - registerUIStrings: () => {}, - getLocalizedString: (_, str) => { - // So that the string passed in gets output verbatim. - return str; - }, - lockedLazyString: () => {}, - getLazilyComputedLocalizedString: () => ()=>{}, -}; - -// TODO(jacktfranklin): once the DocumentLatency insight does not depend on -// this method, we can remove this stub. -export const TimeUtilities = { - millisToString(x) { - const separator = '\xA0'; - const formatter = new Intl.NumberFormat('en-US', { - style: 'unit', - unitDisplay: 'narrow', - minimumFractionDigits: 0, - maximumFractionDigits: 1, - unit: 'millisecond', - }); - - const parts = formatter.formatToParts(x); - for (const part of parts) { - if (part.type === 'literal') { - if (part.value === ' ') { - part.value = separator; - } - } - } + const localesFile = path.join(i18nDir, 'locales.js'); + const localesContent = ` +export const LOCALES = [ + 'en-US', +]; - return parts.map(part => part.value).join(''); - } -}; - -// TODO(jacktfranklin): once the ImageDelivery insight does not depend on this method, we can remove this stub. -export const ByteUtilities = { - bytesToString(x) { - const separator = '\xA0'; - const formatter = new Intl.NumberFormat('en-US', { - style: 'unit', - unit: 'kilobyte', - unitDisplay: 'narrow', - minimumFractionDigits: 1, - maximumFractionDigits: 1, - }); - const parts = formatter.formatToParts(x / 1000); - for (const part of parts) { - if (part.type === 'literal') { - if (part.value === ' ') { - part.value = separator; - } - } - } +export const BUNDLED_LOCALES = [ + 'en-US', +]; - return parts.map(part => part.value).join(''); - } -};`; - writeFile(i18nFile, i18nContent); +export const DEFAULT_LOCALE = 'en-US'; + +export const REMOTE_FETCH_PATTERN = '@HOST@/remote/serve_file/@VERSION@/core/i18n/locales/@LOCALE@.json'; + +export const LOCAL_FETCH_PATTERN = './locales/@LOCALE@.json';`; + writeFile(localesFile, localesContent); // Create codemirror.next mock. const codeMirrorDir = path.join( diff --git a/src/DevtoolsUtils.ts b/src/DevtoolsUtils.ts index 27067ec0b..997cb86a3 100644 --- a/src/DevtoolsUtils.ts +++ b/src/DevtoolsUtils.ts @@ -8,6 +8,7 @@ import { type Issue, type IssuesManagerEventTypes, Common, + I18n, } from '../node_modules/chrome-devtools-frontend/mcp/mcp.js'; export function extractUrlLikeFromDevToolsTitle( @@ -67,3 +68,13 @@ export class FakeIssuesManager extends Common.ObjectWrapper return []; } } + +I18n.DevToolsLocale.DevToolsLocale.instance({ + create: true, + data: { + navigatorLanguage: 'en-US', + settingLanguage: 'en-US', + lookupClosestDevToolsLocale: l => l, + }, +}); +I18n.i18n.registerLocaleDataForTest('en-US', {}); diff --git a/tests/trace-processing/parse.test.ts b/tests/trace-processing/parse.test.ts index d329e29b8..79b4ecb57 100644 --- a/tests/trace-processing/parse.test.ts +++ b/tests/trace-processing/parse.test.ts @@ -11,6 +11,8 @@ import { parseRawTraceBuffer, } from '../../src/trace-processing/parse.js'; +import '../../src/DevtoolsUtils.js'; + import {loadTraceAsBuffer} from './fixtures/load.js'; describe('Trace parsing', async () => { diff --git a/tsconfig.json b/tsconfig.json index d4e0eaf4f..241806784 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -28,6 +28,7 @@ "tests/**/*.ts", "node_modules/chrome-devtools-frontend/front_end/core/common", "node_modules/chrome-devtools-frontend/front_end/core/host", + "node_modules/chrome-devtools-frontend/front_end/core/i18n", "node_modules/chrome-devtools-frontend/front_end/core/platform", "node_modules/chrome-devtools-frontend/front_end/core/protocol_client", "node_modules/chrome-devtools-frontend/front_end/core/root", @@ -57,14 +58,13 @@ "node_modules/chrome-devtools-frontend/front_end/models/trace", "node_modules/chrome-devtools-frontend/front_end/models/workspace", "node_modules/chrome-devtools-frontend/front_end/panels/issues/IssueAggregator.ts", + "node_modules/chrome-devtools-frontend/front_end/third_party/i18n", + "node_modules/chrome-devtools-frontend/front_end/third_party/intl-messageformat", "node_modules/chrome-devtools-frontend/front_end/third_party/legacy-javascript", "node_modules/chrome-devtools-frontend/front_end/third_party/marked", "node_modules/chrome-devtools-frontend/front_end/third_party/source-map-scopes-codec", "node_modules/chrome-devtools-frontend/front_end/third_party/third-party-web", - "node_modules/chrome-devtools-frontend/mcp/mcp.ts", - "node_modules/chrome-devtools-frontend/front_end/models/issues_manager", - "node_modules/chrome-devtools-frontend/front_end/third_party/marked", - "node_modules/chrome-devtools-frontend/front_end/panels/issues/IssueAggregator.ts" + "node_modules/chrome-devtools-frontend/mcp/mcp.ts" ], "exclude": ["node_modules/chrome-devtools-frontend/**/*.test.ts"] }