Send the remaining interface text through the catalog and audit it
Phase 4f. - scripts/i18nAudit.mjs runs in pnpm check. It fails for a key that the catalog does not have, a catalog key that the code does not use, and a row without all four languages. - message() marks a key that a variable carries to the translation call later: table formats, formula errors, and browser status messages. - 53 new rows with French, Japanese, and Simplified Chinese text for the status and error messages of the workbench, the tree, Settings, theme import, images, the built-in browser, and code blocks. The backlinks toggle now translates too. - 13 unused rows are gone. - Errors of the plugin API stay in English. docs/development.md has the rule in "Interface text". pnpm check, pnpm test (350 of 350), and the full smoke suite pass, except two tests that failed one time under load and passed on retry and 3 of 3 times alone.
This commit is contained in:
@@ -126,8 +126,8 @@
|
||||
<button onclick={() => themeInput.click()}>{$t("Install theme")}</button>
|
||||
<button disabled={exporting} onclick={() => void exportTemplate()}>{exporting ? $t('Exporting…') : $t('Export theme template')}</button>
|
||||
{#if appearance.theme.startsWith('custom:')}<IconButton icon="trash" label={$t("Remove custom theme")} onclick={() => {
|
||||
try { removeTheme(appearance.theme.slice(7)).catch(() => { error = 'Could not remove this theme.'; }); installed = customThemes(); change({ ...appearance, theme: 'default' }); }
|
||||
catch { error = 'Could not remove this theme.'; }
|
||||
try { removeTheme(appearance.theme.slice(7)).catch(() => { error = $t("Could not remove this theme."); }); installed = customThemes(); change({ ...appearance, theme: 'default' }); }
|
||||
catch { error = $t("Could not remove this theme."); }
|
||||
}} />{/if}
|
||||
</div>
|
||||
<p>{$t("Edit the exported JSON colors and fonts, then choose Install theme. The template contains one color palette and font families.")}</p>
|
||||
|
||||
@@ -8,7 +8,7 @@ function database(): Promise<IDBDatabase> {
|
||||
});
|
||||
}
|
||||
export async function saveBackgroundImage(file: Blob): Promise<string> {
|
||||
if (file.size > BACKGROUND_IMAGE_LIMIT) throw new Error('Choose an image of 50 MiB or less.');
|
||||
if (file.size > BACKGROUND_IMAGE_LIMIT) throw new Error(tr("Choose an image of 50 MiB or less."));
|
||||
const db = await database();
|
||||
const id = crypto.randomUUID();
|
||||
try {
|
||||
@@ -43,4 +43,5 @@ export async function removeBackgroundImage(id: string): Promise<void> {
|
||||
transaction.onabort = () => reject(transaction.error);
|
||||
});
|
||||
} finally { db.close(); }
|
||||
}
|
||||
}import { tr } from "../i18n/index.ts";
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { tr } from "../i18n/index.ts";
|
||||
import { readSection, writeSection } from '../settings/store.ts';
|
||||
|
||||
/** The old localStorage key. The customThemes section of the settings file replaces it. */
|
||||
@@ -10,31 +11,31 @@ export type CustomTheme = { schema: 2; id: string; name: string; colors: ThemeCo
|
||||
export type LegacyCustomTheme = { schema: 1; id: string; name: string; light: ThemeColors; dark: ThemeColors };
|
||||
|
||||
export function parseCustomTheme(input: unknown, legacyMode: "light" | "dark" = "dark"): CustomTheme {
|
||||
if (!input || typeof input !== "object") throw new Error("Choose a RuneStone theme JSON file.");
|
||||
if (!input || typeof input !== "object") throw new Error(tr("Choose a RuneStone theme JSON file."));
|
||||
const value = input as Record<string, unknown>;
|
||||
if ((value.schema !== 1 && value.schema !== 2) || typeof value.id !== "string" || !/^[a-z][a-z0-9-]{0,63}$/.test(value.id)
|
||||
|| typeof value.name !== "string" || !value.name.trim() || value.name.length > 80) throw new Error("The theme needs schema 2, an ID, and a name.");
|
||||
|| typeof value.name !== "string" || !value.name.trim() || value.name.length > 80) throw new Error(tr("The theme needs schema 2, an ID, and a name."));
|
||||
const colors = (mode: string): ThemeColors => {
|
||||
const source = value[mode];
|
||||
if (!source || typeof source !== "object" || Array.isArray(source)) throw new Error(`The theme needs ${mode} colors.`);
|
||||
if (!source || typeof source !== "object" || Array.isArray(source)) throw new Error(tr("The theme needs {mode} colors.", { mode }));
|
||||
const result: ThemeColors = {};
|
||||
for (const [key, color] of Object.entries(source)) {
|
||||
if (!(COLOR_TOKENS as readonly string[]).includes(key)) throw new Error(`Unknown theme color: ${key}`);
|
||||
if (typeof color !== "string" || !/^#(?:[0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})$/i.test(color)) throw new Error(`Use a hexadecimal color for ${key}.`);
|
||||
if (!(COLOR_TOKENS as readonly string[]).includes(key)) throw new Error(tr("Unknown theme color: {key}", { key }));
|
||||
if (typeof color !== "string" || !/^#(?:[0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})$/i.test(color)) throw new Error(tr("Use a hexadecimal color for {key}.", { key }));
|
||||
result[key as keyof ThemeColors] = color;
|
||||
}
|
||||
if (!result.bg || !result.text || !result.accent) throw new Error(`The ${mode} palette needs bg, text, and accent.`);
|
||||
if (!result.bg || !result.text || !result.accent) throw new Error(tr("The {mode} palette needs bg, text, and accent.", { mode }));
|
||||
return result;
|
||||
};
|
||||
if (value.schema === 1) { colors("light"); colors("dark"); }
|
||||
let fonts: ThemeFonts | undefined;
|
||||
if (value.fonts !== undefined) {
|
||||
if (!value.fonts || typeof value.fonts !== 'object' || Array.isArray(value.fonts)) throw new Error('Use an object for theme fonts.');
|
||||
if (!value.fonts || typeof value.fonts !== 'object' || Array.isArray(value.fonts)) throw new Error(tr("Use an object for theme fonts."));
|
||||
fonts = {};
|
||||
for (const [role, stack] of Object.entries(value.fonts)) {
|
||||
if (!(FONT_ROLES as readonly string[]).includes(role)) throw new Error(`Unknown theme font: ${role}`);
|
||||
if (!(FONT_ROLES as readonly string[]).includes(role)) throw new Error(tr("Unknown theme font: {role}", { role }));
|
||||
if (typeof stack !== 'string' || stack.length > 512 || !/^[\p{L}\p{N} _,'"-]+$/u.test(stack) || !stack.trim()
|
||||
|| stack.split(',').some(family => !/^(?:"[^"\n]+"|'[^'\n]+'|[\p{L}\p{N}_ -]+)$/u.test(family.trim()))) throw new Error(`Use a font family stack for ${role}.`);
|
||||
|| stack.split(',').some(family => !/^(?:"[^"\n]+"|'[^'\n]+'|[\p{L}\p{N}_ -]+)$/u.test(family.trim()))) throw new Error(tr("Use a font family stack for {role}.", { role }));
|
||||
fonts[role as keyof ThemeFonts] = stack.trim();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user