mirror of
https://github.com/nexu-io/openmotion.git
synced 2026-12-02 02:10:07 +08:00
* feat(explore): add Black Friday Explore hero, spotlight, and curated model hubs Port the scheduled Black Friday Explore presentation and curated Seedance 2.5 and GPT Image 2.0 model hubs onto main, keeping Cloud Model Gateway wiring, guest/MCP flows, and P1 feature gates intact: - Add scheduled ExploreBlackFridayHero (2026-11-25 20:00 +08:00 to 2026-12-05 00:00 +08:00) using curated HD corridor covers (excluding torn-portrait tile #28 and keeping foreground ring 6 center-left as a clean model logo tile) and ExploreBlackFridaySpotlight cards, synced with a 12-hour rolling countdown and shared WorkspaceFrame banner takeover state. - Add curated Seedance 2.5 (70 templates) and GPT Image 2.0 (35 templates) ModelHub showcases with staggered masonry layout, hover-only video playback, opaque portal lightbox, X-hosted no-referrer video iframe with Escape bridge, and StudioIdeas remix handoff. - Bundle offline Instrument Serif font + OFL/NOTICES tokens, upgrade local posters to AVIF, and add .avif MIME support in src/entrypoints/api.ts. - Address review feedback from the source PR: preserve _blank Pricing links with checkout-return refresh hooks, replace translucent backdrop-filter chrome with solid design-system surfaces, rewrite clipped/reference-dependent showcase prompts into complete self-contained prompts, backfill all 10 non-English locales in model-hub-ui.json (removing it from LEGACY_PARTIAL_UI_FILES), and keep WorkspaceBreadcrumb decoupled from heavy hub media via modelHubMeta.ts. Backport-of: #931, #1057 (partial, from commits40dee17b7and17d6301d8) * feat(studio): preselect hub and template models when served by gateway Carry and default-select the originating model when jumping from a ModelHub remix/CTA, Explore model story, or Cinema template into a Studio creation page, strictly guarded by the live backend catalog: - Centralize lightweight hub model matchers and preference ranking in modelHubMeta.ts (preferring exact GPT Image 2 / 2.0 over 2.6 variants and standard Seedance 2.5 over Flash) without pulling heavy hub assets into main.tsx. - Add selectModelForHub() and enhance creationModels() so template/hub preferredModel hints match composite id, raw modelId, or soft hub:<id> hints against both available and compatible catalog lists, while falling back cleanly to the normal default when the backend does not return the model. - Wire ModelHub showcase remix cards, lightbox remix, and hero primary CTAs (plus Explore model stories and WorkspaceFrame draft preservation) to resolve live catalog models when loaded or pass a soft hub hint while loading, never pinning an absent model. --------- Co-authored-by: 罗高 <luogao@users.noreply.github.com>
206 lines
7.7 KiB
TypeScript
206 lines
7.7 KiB
TypeScript
import assert from 'node:assert/strict';
|
|
import { readFile, readdir } from 'node:fs/promises';
|
|
import path from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
import { isMain } from '../shared/entry.ts';
|
|
import {
|
|
I18N_EXTENSION_SOURCES,
|
|
NON_ENGLISH_LOCALES,
|
|
type Message,
|
|
type NonEnglishLocale,
|
|
} from '../studio/src/i18n/manifest.ts';
|
|
|
|
const root = fileURLToPath(new URL('../', import.meta.url));
|
|
|
|
/**
|
|
* Legacy multi-locale UI JSON files that predate the strict 10-locale
|
|
* completeness requirement. Any new `*-ui.json` file must provide all 10
|
|
* non-English locales with identical key sets; remove files from this list
|
|
* once their remaining translations are backfilled.
|
|
*/
|
|
const LEGACY_PARTIAL_UI_FILES = new Set<string>([
|
|
'studio/src/i18n/assets-ui.json',
|
|
'studio/src/i18n/brand-kit-ui.json',
|
|
'studio/src/i18n/design-ui.json',
|
|
'studio/src/i18n/mcp-ui.json',
|
|
'studio/src/i18n/platform-export-ui.json',
|
|
'studio/src/i18n/settings-ui.json',
|
|
'studio/src/i18n/template-ui.json',
|
|
'studio/src/i18n/transcript-ui.json',
|
|
]);
|
|
|
|
/**
|
|
* Legacy zh-CN keys whose values already differed across multiple `*-ui.json`
|
|
* modules before the cross-file conflict gate was added. New keys must never
|
|
* silently redefine an existing key with a different translation.
|
|
*/
|
|
const LEGACY_CONFLICTING_ZH_KEYS = new Set<string>([
|
|
'Adapt the full video',
|
|
'All categories',
|
|
'Aspect ratio',
|
|
'Coming soon',
|
|
'Copy command',
|
|
'Create',
|
|
'Explainers',
|
|
'In progress',
|
|
'Model default',
|
|
'Move to trash',
|
|
'No matching models',
|
|
'No matching providers',
|
|
'Off',
|
|
'On',
|
|
'Reload preview',
|
|
'Save version',
|
|
'Sign in',
|
|
'Tension riser',
|
|
'{count} generating',
|
|
]);
|
|
|
|
function extractPlaceholders(text: string): string {
|
|
return [...text.matchAll(/\{(\w+)\}/g)].map(match => match[1]).sort().join(',');
|
|
}
|
|
|
|
function validateEntries(file: string, locale: string, entries: Record<string, Message>): void {
|
|
for (const [source, value] of Object.entries(entries)) {
|
|
const texts = typeof value === 'string' ? [value] : Object.values(value ?? {});
|
|
assert.ok(texts.length > 0, `${file} [${locale}] "${source}" has no translation values`);
|
|
const expectedPlaceholders = extractPlaceholders(source);
|
|
for (const text of texts) {
|
|
assert.equal(typeof text, 'string', `${file} [${locale}] "${source}" must be a string`);
|
|
assert.ok(text.trim().length > 0, `${file} [${locale}] "${source}" cannot be empty`);
|
|
assert.equal(
|
|
extractPlaceholders(text),
|
|
expectedPlaceholders,
|
|
`${file} [${locale}] "${source}" has mismatched {var} placeholders in "${text}"`,
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
async function readJson<T>(relativePath: string): Promise<T> {
|
|
const fullPath = path.resolve(root, relativePath);
|
|
return JSON.parse(await readFile(fullPath, 'utf8')) as T;
|
|
}
|
|
|
|
export async function checkI18n(): Promise<void> {
|
|
const supported = new Set<string>(NON_ENGLISH_LOCALES);
|
|
|
|
// 1. Manifest <-> disk file parity for studio/src/i18n/*.json and skill-library/*.json
|
|
const registeredPaths = new Set<string>(NON_ENGLISH_LOCALES.map(locale => `studio/src/i18n/${locale}.json`));
|
|
for (const source of I18N_EXTENSION_SOURCES) {
|
|
if (source.kind === 'multi-locale-json') {
|
|
registeredPaths.add(source.path);
|
|
} else if (source.kind === 'mvp-split') {
|
|
registeredPaths.add(source.zhPath);
|
|
registeredPaths.add(source.othersPath);
|
|
} else if (source.kind === 'per-locale-dir') {
|
|
for (const locale of NON_ENGLISH_LOCALES) registeredPaths.add(`${source.dir}/${locale}.json`);
|
|
}
|
|
}
|
|
|
|
for (const entry of await readdir(path.join(root, 'studio/src/i18n'))) {
|
|
if (!entry.endsWith('.json')) continue;
|
|
const rel = `studio/src/i18n/${entry}`;
|
|
assert.ok(
|
|
registeredPaths.has(rel),
|
|
`Unregistered i18n JSON file "${rel}". Add it to I18N_EXTENSION_SOURCES in studio/src/i18n/manifest.ts.`,
|
|
);
|
|
}
|
|
for (const entry of await readdir(path.join(root, 'studio/src/i18n/skill-library'))) {
|
|
if (!entry.endsWith('.json')) continue;
|
|
const rel = `studio/src/i18n/skill-library/${entry}`;
|
|
assert.ok(
|
|
registeredPaths.has(rel),
|
|
`Unregistered skill-library locale file "${rel}".`,
|
|
);
|
|
}
|
|
|
|
// 2. Validate per-locale base dictionaries and skill-library dictionaries (strict 10-locale parity)
|
|
for (const dir of ['studio/src/i18n', 'studio/src/i18n/skill-library']) {
|
|
const zhRef = await readJson<Record<string, Message>>(`${dir}/zh-CN.json`);
|
|
const refKeys = Object.keys(zhRef).sort();
|
|
for (const locale of NON_ENGLISH_LOCALES) {
|
|
const file = `${dir}/${locale}.json`;
|
|
const entries = await readJson<Record<string, Message>>(file);
|
|
const keys = Object.keys(entries).sort();
|
|
assert.deepEqual(keys, refKeys, `${file} keys diverge from ${dir}/zh-CN.json`);
|
|
validateEntries(file, locale, entries);
|
|
}
|
|
}
|
|
|
|
// 3. Validate all extension sources, placeholder parity, 10-locale ratchet, and cross-file conflicts
|
|
const zhKeyOrigins = new Map<string, Map<string, string>>();
|
|
|
|
for (const source of I18N_EXTENSION_SOURCES) {
|
|
if (source.kind === 'per-locale-dir') continue;
|
|
|
|
if (source.kind === 'mvp-split') {
|
|
const zhEntries = await readJson<Record<string, Message>>(source.zhPath);
|
|
validateEntries(source.zhPath, 'zh-CN', zhEntries);
|
|
const others = await readJson<Record<string, Record<string, Message>>>(source.othersPath);
|
|
const expectedLocales = NON_ENGLISH_LOCALES.filter(locale => locale !== 'zh-CN');
|
|
assert.deepEqual(Object.keys(others).sort(), [...expectedLocales].sort(), `${source.othersPath} locales mismatch`);
|
|
const refKeys = Object.keys(others[expectedLocales[0]]).sort();
|
|
for (const locale of expectedLocales) {
|
|
assert.deepEqual(Object.keys(others[locale]).sort(), refKeys, `${source.othersPath} [${locale}] keys mismatch`);
|
|
validateEntries(source.othersPath, locale, others[locale]);
|
|
}
|
|
continue;
|
|
}
|
|
|
|
const file = source.path;
|
|
const data = await readJson<Record<string, Record<string, Message>>>(file);
|
|
const allowEn = file === 'shared/asset-name-ui.json';
|
|
for (const locale of Object.keys(data)) {
|
|
if (allowEn && locale === 'en') continue;
|
|
assert.ok(supported.has(locale), `${file} contains unsupported locale key "${locale}"`);
|
|
validateEntries(file, locale, data[locale]);
|
|
}
|
|
|
|
const isLegacyPartial = LEGACY_PARTIAL_UI_FILES.has(file);
|
|
if (!isLegacyPartial) {
|
|
for (const locale of NON_ENGLISH_LOCALES) {
|
|
assert.ok(Object.hasOwn(data, locale), `${file} is missing required locale "${locale}"`);
|
|
}
|
|
const refKeys = Object.keys(data['zh-CN']).sort();
|
|
for (const locale of NON_ENGLISH_LOCALES) {
|
|
assert.deepEqual(
|
|
Object.keys(data[locale]).sort(),
|
|
refKeys,
|
|
`${file} [${locale}] keys must match zh-CN keys`,
|
|
);
|
|
}
|
|
}
|
|
|
|
const zhEntries = data['zh-CN'];
|
|
if (zhEntries) {
|
|
for (const [key, value] of Object.entries(zhEntries)) {
|
|
const serialized = JSON.stringify(value);
|
|
let origins = zhKeyOrigins.get(key);
|
|
if (!origins) {
|
|
origins = new Map();
|
|
zhKeyOrigins.set(key, origins);
|
|
}
|
|
origins.set(file, serialized);
|
|
}
|
|
}
|
|
}
|
|
|
|
for (const [key, origins] of zhKeyOrigins) {
|
|
if (origins.size <= 1) continue;
|
|
const distinctValues = new Set(origins.values());
|
|
if (distinctValues.size > 1 && !LEGACY_CONFLICTING_ZH_KEYS.has(key)) {
|
|
const files = [...origins.keys()].join(', ');
|
|
assert.fail(
|
|
`Conflicting zh-CN translations for key "${key}" across multiple UI JSON files (${files}). ` +
|
|
`Consolidate the shared key into one module or align the translation.`,
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
if (isMain(import.meta.url)) {
|
|
await checkI18n();
|
|
console.log('Studio i18n manifest, completeness, placeholder parity and conflict checks passed.');
|
|
}
|