diff --git a/src/locales/en.json b/src/locales/en.json index ae775af..e0541f3 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -4275,6 +4275,9 @@ "language": "Content language", "content": "Content", "contentPlaceholder": "HTML page content...", + "charCount": "Characters: {{count}}", + "botSplitEstimate_one": "⚠️ The bot will show it split into ~{{count}} message", + "botSplitEstimate_other": "⚠️ The bot will show it split into ~{{count}} messages", "save": "Save", "saving": "Saving...", "saveError": "Failed to save. Please try again.", diff --git a/src/locales/ru.json b/src/locales/ru.json index 134b156..3415f79 100644 --- a/src/locales/ru.json +++ b/src/locales/ru.json @@ -4820,6 +4820,10 @@ "language": "Язык контента", "content": "Текст", "contentPlaceholder": "HTML-текст страницы...", + "charCount": "Символов: {{count}}", + "botSplitEstimate_one": "⚠️ В боте будет показано по частям: ~{{count}} сообщение", + "botSplitEstimate_few": "⚠️ В боте будет показано по частям: ~{{count}} сообщения", + "botSplitEstimate_many": "⚠️ В боте будет показано по частям: ~{{count}} сообщений", "save": "Сохранить", "saving": "Сохранение...", "saveError": "Не удалось сохранить. Попробуйте ещё раз.", diff --git a/src/pages/AdminLegalPages.tsx b/src/pages/AdminLegalPages.tsx index d2c8508..0549a13 100644 --- a/src/pages/AdminLegalPages.tsx +++ b/src/pages/AdminLegalPages.tsx @@ -20,6 +20,62 @@ const DISPLAY_MODES: LegalDisplayMode[] = ['bot', 'web', 'both']; type DocumentKind = 'privacy-policy' | 'public-offer' | 'recurrent-payments'; +// Bot chunk/page size (split_telegram_text max_length): longer texts are +// delivered by the bot in several messages / paginated pages +const TELEGRAM_SPLIT_THRESHOLD = 3500; + +// Mirrors the bot's split_telegram_text greedy paragraph packing to estimate +// how many messages/pages the bot will produce for this text +function estimateTelegramParts(text: string): number { + const normalized = text.replace(/\r\n/g, '\n').trim(); + if (!normalized) return 0; + if (normalized.length <= TELEGRAM_SPLIT_THRESHOLD) return 1; + const paragraphs = normalized.split('\n\n').filter((p) => p.trim()); + let parts = 0; + let current = ''; + for (const paragraph of paragraphs) { + const candidate = current ? `${current}\n\n${paragraph}` : paragraph; + if (candidate.length <= TELEGRAM_SPLIT_THRESHOLD) { + current = candidate; + continue; + } + if (current) { + parts += 1; + current = ''; + } + if (paragraph.length <= TELEGRAM_SPLIT_THRESHOLD) { + current = paragraph; + } else { + parts += Math.ceil(paragraph.length / TELEGRAM_SPLIT_THRESHOLD); + } + } + if (current) parts += 1; + return parts; +} + +function ContentLengthMeta({ text, botVisible }: { text: string; botVisible: boolean }) { + const { t } = useTranslation(); + const parts = botVisible ? estimateTelegramParts(text) : 0; + return ( +
{saveError}
}