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>
This commit is contained in:
Georg Bauer
2026-03-09 14:43:18 +01:00
committed by GitHub
parent f1c9038803
commit b855d61524
116 changed files with 19954 additions and 2094 deletions

View File

@@ -21,6 +21,7 @@ function makePost(overrides: Partial<PostData> = {}): PostData {
content: overrides.content ?? `# ${title}\n\nBody`,
status: overrides.status ?? 'published',
author: overrides.author,
language: overrides.language,
createdAt,
updatedAt,
publishedAt: overrides.publishedAt,
@@ -50,8 +51,8 @@ function makeEngine(posts: PostData[], snapshotsById: Record<string, PostData |
result = result.filter((post) => filter.categories!.some((category) => post.categories.includes(category)));
}
if ((filter as any).excludeCategories && (filter as any).excludeCategories.length > 0) {
result = result.filter((post) => !(filter as any).excludeCategories.some((category: string) => post.categories.includes(category)));
if (filter.excludeCategories && filter.excludeCategories.length > 0) {
result = result.filter((post) => !filter.excludeCategories!.some((category: string) => post.categories.includes(category)));
}
if (filter.year !== undefined) {
@@ -116,6 +117,118 @@ describe('SharedSnapshotService', () => {
expect(result?.id).toBe('draft-1');
});
it('returns a translated draft variant when preview language is provided', async () => {
const draft = makePost({ id: 'draft-1', slug: 'my-post', status: 'draft', language: 'en', title: 'Canonical title', content: 'Canonical body', createdAt: new Date('2025-03-21T10:00:00.000Z') });
const engine = {
...makeEngine([draft]),
async getPostTranslation(postId: string, language: string) {
if (postId === 'draft-1' && language === 'fr') {
return {
id: 'translation-1',
translationFor: 'draft-1',
language: 'fr',
title: 'Titre traduit',
excerpt: 'Resume traduit',
content: 'Contenu traduit',
status: 'draft',
createdAt: new Date('2025-03-21T10:00:00.000Z'),
updatedAt: new Date('2025-03-21T11:00:00.000Z'),
publishedAt: null,
filePath: 'posts/my-post.fr.md',
};
}
return null;
},
} as SharedSnapshotPostEngine & {
getPostTranslation: (postId: string, language: string) => Promise<any>;
};
const result = await findSinglePostBySlug(
engine,
'my-post',
{ useDraftContent: true, draftPostId: 'draft-1', lang: 'fr' },
{ year: 2025, month: 3, day: 21 },
);
expect(result).toMatchObject({
id: 'translation-1',
slug: 'my-post.fr',
language: 'fr',
title: 'Titre traduit',
excerpt: 'Resume traduit',
content: 'Contenu traduit',
});
});
it('prefers project main language content and falls back to canonical language when no translation exists', async () => {
const published = makePost({
id: 'post-1',
slug: 'my-post',
status: 'published',
language: 'en',
title: 'Canonical title',
content: 'Canonical body',
createdAt: new Date('2025-03-21T10:00:00.000Z'),
});
const getPostTranslation = vi.fn(async (postId: string, language: string) => {
if (postId === 'post-1' && language === 'fr') {
return {
id: 'translation-1',
projectId: 'default',
translationFor: 'post-1',
language: 'fr',
title: 'Titre principal',
excerpt: 'Resume principal',
content: 'Contenu principal',
status: 'published',
createdAt: new Date('2025-03-21T10:00:00.000Z'),
updatedAt: new Date('2025-03-21T11:00:00.000Z'),
publishedAt: new Date('2025-03-21T11:00:00.000Z'),
filePath: 'posts/my-post.fr.md',
};
}
return null;
});
const engine = {
...makeEngine([published]),
getPostTranslation,
} as SharedSnapshotPostEngine & {
getPostTranslation: (postId: string, language: string) => Promise<any>;
};
const translated = await findSinglePostBySlug(
engine,
'my-post',
{ preferredLanguage: 'fr' },
{ year: 2025, month: 3, day: 21 },
);
expect(translated).toMatchObject({
id: 'translation-1',
slug: 'my-post.fr',
language: 'fr',
title: 'Titre principal',
content: 'Contenu principal',
});
const fallback = await findSinglePostBySlug(
engine,
'my-post',
{ preferredLanguage: 'de' },
{ year: 2025, month: 3, day: 21 },
);
expect(fallback).toMatchObject({
id: 'post-1',
slug: 'my-post',
language: 'en',
title: 'Canonical title',
content: 'Canonical body',
});
expect(getPostTranslation).toHaveBeenNthCalledWith(1, 'post-1', 'fr');
expect(getPostTranslation).toHaveBeenNthCalledWith(2, 'post-1', 'de');
});
it('uses findPublishedBySlug shortcut when present', async () => {
const post = makePost({ id: 'x1', slug: 'shortcut', status: 'published' });
const engine = makeEngine([post]);