Files
bDS/tests/engine/normalizeTranslatedMarkdownBody.test.ts
Georg Bauer b855d61524 Feature/post media translations (#42)
* chore: updated todo with translation ideas

* feat: first take at the implementation of translations

* fix: small addition for the translation feature

* feat: support language switching in the editor and preview

* feat: better handling of long bodies by not running them through a json envelope

* fix: unknown macros have better fallback

* feat: api for python to get translations

* fix: strip dumb prefix of content in translation

* feat: extend meta diff for translations

* feat: hook up translations to rebuild-from-disk

* feat: generation of the website prefers project language, falling back to canonical language

* fix: crashes during rendering

* feat: translation validation report

* fix: made the translation validation actually work

* chore: reorganization of menu

* fix: some topics cleanup

* chore: updated doc

* feat: translations for media

* feat: more aligned in UI/UX

* feat: edit translations possible

* chore: added full multi-language todo

* chore: updated todo for clarity

* feat: implementation of full multi-linguality

* fix: page creation creates pages

* fix: flags on every page

* fix: better prompt

* feat: made MCP server aware of language content

* feat: python tools for translations

* fix: better fill-in-translations

* fix: better prompt for translation. maybe.

* fix: losing posts from search due to translation process

* fix: translation validation handles in-db content and fill-in of missing translations fixed to flush

* fix: faster scanning for infilling of missing translations

* chore: updated agent instructions

* feat: calendar and tag cloud respect current language now

* fix: retries going up

* fix: got metadata-diff and rebuild into sync

* fix: extended meta-diff for timestamps

* fix: made website validation look at translated content, too

* fix: multi-lingual search

* chore: refactor Editor.tsx into two separate editors

* feat: do language detection when no explicit language given

---------

Co-authored-by: hugo <hugoms@me.com>
2026-03-09 14:43:18 +01:00

67 lines
2.2 KiB
TypeScript

import { describe, it, expect } from 'vitest';
import { normalizeTranslatedMarkdownBody } from '../../src/main/engine/ai/tasks';
describe('normalizeTranslatedMarkdownBody', () => {
const sourceContent = '# Hello\n\nThis is the source content.';
it('strips English "content:" prefix', () => {
const input = 'content:\n\n# Hallo\n\nDies ist der Inhalt.';
expect(normalizeTranslatedMarkdownBody(input, sourceContent)).toBe(
'# Hallo\n\nDies ist der Inhalt.',
);
});
it('strips German "inhalt:" prefix', () => {
const input = 'Inhalt:\n\nDer Inhalt hier.';
expect(normalizeTranslatedMarkdownBody(input, sourceContent)).toBe(
'Der Inhalt hier.',
);
});
it('strips French "contenu:" prefix', () => {
const input = 'Contenu:\n\nLe contenu ici.';
expect(normalizeTranslatedMarkdownBody(input, sourceContent)).toBe(
'Le contenu ici.',
);
});
it('strips Italian "contenuto:" prefix', () => {
const input = 'Contenuto:\n\nIl contenuto qui.';
expect(normalizeTranslatedMarkdownBody(input, sourceContent)).toBe(
'Il contenuto qui.',
);
});
it('strips Spanish "contenido:" prefix', () => {
const input = 'Contenido:\n\nEl contenido aqui.';
expect(normalizeTranslatedMarkdownBody(input, sourceContent)).toBe(
'El contenido aqui.',
);
});
it('is case-insensitive', () => {
const input = 'CONTENT:\n\nBody text.';
expect(normalizeTranslatedMarkdownBody(input, sourceContent)).toBe(
'Body text.',
);
});
it('preserves content when source also has the prefix', () => {
const sourceWithPrefix = 'content:\n\nSource body.';
const input = 'Inhalt:\n\nTranslated body.';
expect(normalizeTranslatedMarkdownBody(input, sourceWithPrefix)).toBe(
'Inhalt:\n\nTranslated body.',
);
});
it('returns empty string for empty/whitespace input', () => {
expect(normalizeTranslatedMarkdownBody('', sourceContent)).toBe('');
expect(normalizeTranslatedMarkdownBody(' \n ', sourceContent)).toBe('');
});
it('returns content unchanged when no prefix is present', () => {
const input = '# Normal markdown\n\nBody text.';
expect(normalizeTranslatedMarkdownBody(input, sourceContent)).toBe(input);
});
});