Highlight components in ICU Book
This commit is contained in:
11
.github/workflows/icu-book.yml
vendored
11
.github/workflows/icu-book.yml
vendored
@@ -52,7 +52,16 @@ jobs:
|
|||||||
ARTIFACTS_DIR: stories/data
|
ARTIFACTS_DIR: stories/data
|
||||||
- run: pnpm run build:esbuild
|
- run: pnpm run build:esbuild
|
||||||
- run: node ts/scripts/compile-stories-icu-lookup.js stories
|
- run: node ts/scripts/compile-stories-icu-lookup.js stories
|
||||||
- name: Upload artifacts
|
|
||||||
|
- name: Upload test artifacts
|
||||||
|
if: github.event_name == 'workflow_dispatch'
|
||||||
|
uses: actions/upload-artifact@4cec3d8aa04e39d1a68397de0c4cd6fb9dce8ec1 # v4
|
||||||
|
with:
|
||||||
|
name: desktop-test-icu
|
||||||
|
path: stories
|
||||||
|
|
||||||
|
- name: Upload release artifacts
|
||||||
|
if: github.event_name != 'workflow_dispatch'
|
||||||
uses: actions/upload-artifact@4cec3d8aa04e39d1a68397de0c4cd6fb9dce8ec1 # v4
|
uses: actions/upload-artifact@4cec3d8aa04e39d1a68397de0c4cd6fb9dce8ec1 # v4
|
||||||
with:
|
with:
|
||||||
name: desktop-${{ github.ref_name }}-icu
|
name: desktop-${{ github.ref_name }}-icu
|
||||||
|
@@ -56,7 +56,8 @@
|
|||||||
story.appendChild(title);
|
story.appendChild(title);
|
||||||
|
|
||||||
const img = document.createElement('img');
|
const img = document.createElement('img');
|
||||||
img.src = `data/${encodeURIComponent(storyId)}/screenshot.png`;
|
img.src = `data/${encodeURIComponent(storyId)}/` +
|
||||||
|
`${encodeURIComponent(key.replace(/^icu:/, ''))}.jpg`;
|
||||||
img.loading = 'lazy';
|
img.loading = 'lazy';
|
||||||
story.appendChild(img);
|
story.appendChild(img);
|
||||||
}
|
}
|
||||||
|
@@ -8,6 +8,8 @@ import {
|
|||||||
waitForPageReady,
|
waitForPageReady,
|
||||||
} from '@storybook/test-runner';
|
} from '@storybook/test-runner';
|
||||||
|
|
||||||
|
const SECOND = 1000;
|
||||||
|
|
||||||
const { ARTIFACTS_DIR } = process.env;
|
const { ARTIFACTS_DIR } = process.env;
|
||||||
|
|
||||||
const config: TestRunnerConfig = {
|
const config: TestRunnerConfig = {
|
||||||
@@ -38,15 +40,44 @@ const config: TestRunnerConfig = {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const image = await page.screenshot({ fullPage: true });
|
|
||||||
|
|
||||||
const dir = join(ARTIFACTS_DIR, context.id);
|
const dir = join(ARTIFACTS_DIR, context.id);
|
||||||
await mkdir(dir, { recursive: true });
|
await mkdir(dir, { recursive: true });
|
||||||
|
|
||||||
await Promise.all([
|
for (const [key, value] of result) {
|
||||||
writeFile(join(dir, 'screenshot.png'), image),
|
const locator = page
|
||||||
writeFile(join(dir, 'strings.json'), JSON.stringify(result)),
|
.getByText(value)
|
||||||
]);
|
.or(page.getByTitle(value))
|
||||||
|
.or(page.getByLabel(value));
|
||||||
|
|
||||||
|
if (await locator.count()) {
|
||||||
|
const first = locator.first();
|
||||||
|
|
||||||
|
try {
|
||||||
|
await first.focus({ timeout: SECOND });
|
||||||
|
} catch {
|
||||||
|
// Opportunistic
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
if (await first.isVisible()) {
|
||||||
|
await first.scrollIntoViewIfNeeded({ timeout: SECOND });
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
// Opportunistic
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const image = await page.screenshot({
|
||||||
|
animations: 'disabled',
|
||||||
|
fullPage: true,
|
||||||
|
mask: [locator],
|
||||||
|
// Semi-transparent ultramarine
|
||||||
|
maskColor: 'rgba(44, 107, 273, 0.3)',
|
||||||
|
type: 'jpeg',
|
||||||
|
quality: 95,
|
||||||
|
});
|
||||||
|
|
||||||
|
await writeFile(join(dir, `${key.replace(/^icu:/, '')}.jpg`), image);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
export default config;
|
export default config;
|
||||||
|
@@ -1,22 +1,23 @@
|
|||||||
// Copyright 2025 Signal Messenger, LLC
|
// Copyright 2025 Signal Messenger, LLC
|
||||||
// SPDX-License-Identifier: AGPL-3.0-only
|
// SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
import { readdir, readFile, writeFile } from 'node:fs/promises';
|
import { readFile, writeFile } from 'node:fs/promises';
|
||||||
import { join } from 'node:path';
|
import { join, basename } from 'node:path';
|
||||||
import pMap from 'p-map';
|
import pMap from 'p-map';
|
||||||
import z from 'zod';
|
import fastGlob from 'fast-glob';
|
||||||
|
|
||||||
import { drop } from '../util/drop';
|
import { drop } from '../util/drop';
|
||||||
|
|
||||||
const jsonSchema = z.string().array();
|
|
||||||
|
|
||||||
async function main(): Promise<void> {
|
async function main(): Promise<void> {
|
||||||
const source = process.argv[2];
|
const source = process.argv[2];
|
||||||
if (!source) {
|
if (!source) {
|
||||||
throw new Error('Missing required source directory argument');
|
throw new Error('Missing required source directory argument');
|
||||||
}
|
}
|
||||||
|
|
||||||
const ids = await readdir(join(source, 'data'), { withFileTypes: true });
|
const dirEntries = await fastGlob('*/*.jpg', {
|
||||||
|
cwd: join(source, 'data'),
|
||||||
|
onlyFiles: true,
|
||||||
|
});
|
||||||
|
|
||||||
const enMessages = JSON.parse(
|
const enMessages = JSON.parse(
|
||||||
await readFile(
|
await readFile(
|
||||||
@@ -28,27 +29,18 @@ async function main(): Promise<void> {
|
|||||||
const icuToStory: Record<string, Array<string>> = Object.create(null);
|
const icuToStory: Record<string, Array<string>> = Object.create(null);
|
||||||
|
|
||||||
await pMap(
|
await pMap(
|
||||||
ids,
|
dirEntries,
|
||||||
async entity => {
|
async entry => {
|
||||||
if (!entity.isDirectory()) {
|
const [storyId, imageFile] = entry.split('/', 2);
|
||||||
return;
|
|
||||||
}
|
const icuId = `icu:${basename(imageFile, '.jpg')}`;
|
||||||
|
|
||||||
const storyId = entity.name;
|
let list = icuToStory[icuId];
|
||||||
const dir = join(source, 'data', storyId);
|
if (list == null) {
|
||||||
|
list = [];
|
||||||
const strings = jsonSchema.parse(
|
icuToStory[icuId] = list;
|
||||||
JSON.parse(await readFile(join(dir, 'strings.json'), 'utf8'))
|
|
||||||
);
|
|
||||||
|
|
||||||
for (const icuId of strings) {
|
|
||||||
let list = icuToStory[icuId];
|
|
||||||
if (list == null) {
|
|
||||||
list = [];
|
|
||||||
icuToStory[icuId] = list;
|
|
||||||
}
|
|
||||||
list.push(storyId);
|
|
||||||
}
|
}
|
||||||
|
list.push(storyId);
|
||||||
},
|
},
|
||||||
{ concurrency: 20 }
|
{ concurrency: 20 }
|
||||||
);
|
);
|
||||||
|
@@ -51,7 +51,7 @@ export type LocalizerType = {
|
|||||||
|
|
||||||
// Storybook
|
// Storybook
|
||||||
trackUsage(): void;
|
trackUsage(): void;
|
||||||
stopTrackingUsage(): Array<string>;
|
stopTrackingUsage(): Array<[string, string]>;
|
||||||
};
|
};
|
||||||
|
|
||||||
export enum SentMediaQualityType {
|
export enum SentMediaQualityType {
|
||||||
|
@@ -121,7 +121,7 @@ export function setupI18n(
|
|||||||
renderEmojify,
|
renderEmojify,
|
||||||
});
|
});
|
||||||
|
|
||||||
let usedStrings: Set<string> | undefined;
|
let usedStrings: Map<string, string> | undefined;
|
||||||
|
|
||||||
const localizer: LocalizerType = (<
|
const localizer: LocalizerType = (<
|
||||||
Key extends keyof ICUStringMessageParamsByKeyType,
|
Key extends keyof ICUStringMessageParamsByKeyType,
|
||||||
@@ -130,13 +130,13 @@ export function setupI18n(
|
|||||||
substitutions: ICUStringMessageParamsByKeyType[Key],
|
substitutions: ICUStringMessageParamsByKeyType[Key],
|
||||||
options?: LocalizerOptions
|
options?: LocalizerOptions
|
||||||
) => {
|
) => {
|
||||||
usedStrings?.add(key);
|
|
||||||
|
|
||||||
const result = intl.formatMessage(
|
const result = intl.formatMessage(
|
||||||
{ id: key },
|
{ id: key },
|
||||||
normalizeSubstitutions(substitutions, options)
|
normalizeSubstitutions(substitutions, options)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
usedStrings?.set(key, result);
|
||||||
|
|
||||||
strictAssert(result !== key, `i18n: missing translation for "${key}"`);
|
strictAssert(result !== key, `i18n: missing translation for "${key}"`);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
@@ -159,13 +159,13 @@ export function setupI18n(
|
|||||||
if (usedStrings !== undefined) {
|
if (usedStrings !== undefined) {
|
||||||
throw new Error('Already tracking usage');
|
throw new Error('Already tracking usage');
|
||||||
}
|
}
|
||||||
usedStrings = new Set();
|
usedStrings = new Map();
|
||||||
};
|
};
|
||||||
localizer.stopTrackingUsage = () => {
|
localizer.stopTrackingUsage = () => {
|
||||||
if (usedStrings === undefined) {
|
if (usedStrings === undefined) {
|
||||||
throw new Error('Not tracking usage');
|
throw new Error('Not tracking usage');
|
||||||
}
|
}
|
||||||
const result = Array.from(usedStrings);
|
const result = Array.from(usedStrings.entries());
|
||||||
usedStrings = undefined;
|
usedStrings = undefined;
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user