mirror of
https://github.com/Ku6epXBOCTuK/easy-png-tools.git
synced 2026-11-13 17:08:20 +00:00
feat: separate i18n dict pages
This commit is contained in:
@@ -16,9 +16,14 @@ export function isLocale(value: unknown): value is Locale {
|
||||
);
|
||||
}
|
||||
|
||||
export type ToolStrings = {
|
||||
/** Тексты страницы (`pages.<slug>`): адрес, имя файла и иконка — по slug. */
|
||||
export type PageStrings = {
|
||||
title?: string;
|
||||
description?: string;
|
||||
};
|
||||
|
||||
/** Тексты инструмента (`tools.<id>`): подписи полей, verdict-ключи. */
|
||||
export type ToolStrings = {
|
||||
/** Подписи параметров по их id. */
|
||||
params?: Record<string, string>;
|
||||
/** Подписи опций select: paramId -> value -> label. */
|
||||
@@ -54,6 +59,8 @@ export type Dict = {
|
||||
search: Record<string, string>;
|
||||
ui: Record<string, string>;
|
||||
errors: Record<string, string>;
|
||||
/** Заголовки и описания страниц; в базовой локали их нет — берётся EN из реестра. */
|
||||
pages?: Record<string, PageStrings>;
|
||||
tools: Record<string, ToolStrings>;
|
||||
/** Действия панели результата/генерации (Generate, Open image…). */
|
||||
actions?: Record<string, string>;
|
||||
|
||||
@@ -334,6 +334,9 @@ export const en: Dict = {
|
||||
tile: "Tile",
|
||||
watermark: "Watermark",
|
||||
},
|
||||
// Заголовки и описания страниц в базовой локали не дублируются: их берёт
|
||||
// EN-строка из реестра страниц (`web/src/lib/registry/pages/`).
|
||||
pages: {},
|
||||
tools: {
|
||||
"png-file-size": {
|
||||
results: {
|
||||
|
||||
+527
-314
File diff suppressed because it is too large
Load Diff
@@ -13,11 +13,11 @@ function labelOf(id: string): string {
|
||||
}
|
||||
|
||||
export function pageTitle(page: Page): string {
|
||||
return getMergedDict().tools[page.slug]?.title ?? page.title;
|
||||
return getMergedDict().pages?.[page.slug]?.title ?? page.title;
|
||||
}
|
||||
|
||||
export function pageDescription(page: Page): string {
|
||||
return getMergedDict().tools[page.slug]?.description ?? page.description;
|
||||
return getMergedDict().pages?.[page.slug]?.description ?? page.description;
|
||||
}
|
||||
|
||||
export function fieldLabel(field: Field<unknown>, id: string): string {
|
||||
@@ -65,17 +65,17 @@ function dedupe(values: string[]): string[] {
|
||||
}
|
||||
|
||||
export function pageSearchDoc(page: Page): SearchDoc {
|
||||
const active = getMergedDict().tools[page.slug];
|
||||
const active = getMergedDict().pages?.[page.slug];
|
||||
return {
|
||||
id: page.slug,
|
||||
titles: dedupe([
|
||||
active?.title ?? "",
|
||||
ru.tools[page.slug]?.title ?? "",
|
||||
ru.pages?.[page.slug]?.title ?? "",
|
||||
page.title,
|
||||
]),
|
||||
descriptions: dedupe([
|
||||
active?.description ?? "",
|
||||
ru.tools[page.slug]?.description ?? "",
|
||||
ru.pages?.[page.slug]?.description ?? "",
|
||||
page.description,
|
||||
]),
|
||||
};
|
||||
|
||||
@@ -34,7 +34,7 @@ function selectOptions(
|
||||
describe("полнота словарей для нового registry", () => {
|
||||
it("у каждой страницы есть перевод ru с непустыми title/description", () => {
|
||||
for (const page of PAGES) {
|
||||
const strings = ru.tools[page.slug];
|
||||
const strings = ru.pages?.[page.slug];
|
||||
expect(strings, `нет перевода ru для ${page.slug}`).toBeDefined();
|
||||
expect(strings?.title, `${page.slug}: title`).toBeTruthy();
|
||||
expect(strings?.description, `${page.slug}: description`).toBeTruthy();
|
||||
@@ -75,6 +75,20 @@ describe("полнота словарей для нового registry", () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("в секции pages нет лишних страниц", () => {
|
||||
const slugs = new Set(PAGES.map((page) => page.slug));
|
||||
for (const [locale, dict] of [
|
||||
["ru", ru],
|
||||
["en", en],
|
||||
] as const) {
|
||||
for (const key of Object.keys(dict.pages ?? {})) {
|
||||
expect(slugs.has(key), `лишняя страница в ${locale}: ${key}`).toBe(
|
||||
true,
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
it("в словарях нет ключей без записи в реестре", () => {
|
||||
const known = new Set([
|
||||
...TOOLS.map((tool) => tool.id),
|
||||
|
||||
Reference in New Issue
Block a user