diff --git a/src/locales/en.json b/src/locales/en.json index 801f63c..972b711 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -4196,6 +4196,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 92b5149..16b33d0 100644 --- a/src/locales/ru.json +++ b/src/locales/ru.json @@ -4741,6 +4741,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 ( +
+ + {t('admin.legalPages.charCount', { + count: text.length, + defaultValue: 'Characters: {{count}}', + })} + + {parts > 1 && ( + + {t('admin.legalPages.botSplitEstimate', { + count: parts, + defaultValue: '⚠️ The bot will show it split into ~{{count}} messages', + })} + + )} +
+ ); +} + const DOCUMENT_API: Record< DocumentKind, { @@ -236,6 +292,10 @@ function DocumentEditor({ className="input min-h-[320px] w-full font-mono text-sm" placeholder={t('admin.legalPages.contentPlaceholder')} /> + {saveError &&

{saveError}

}