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:
@@ -59,10 +59,10 @@ describe('pythonApiContractV1', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('exposes analyzeMediaImage and detectPostLanguage from chat namespace', () => {
|
||||
it('exposes one-shot translation from chat namespace', () => {
|
||||
const methodNames = listPythonApiMethodNames();
|
||||
const chatMethods = methodNames.filter((m) => m.startsWith('chat.'));
|
||||
expect(chatMethods).toEqual(['chat.analyzeMediaImage', 'chat.detectPostLanguage', 'chat.analyzePost']);
|
||||
expect(chatMethods).toEqual(['chat.analyzeMediaImage', 'chat.detectPostLanguage', 'chat.analyzePost', 'chat.translatePost', 'chat.detectMediaLanguage', 'chat.translateMediaMetadata']);
|
||||
});
|
||||
|
||||
it('documents chat.analyzeMediaImage contract with mediaId and language params', () => {
|
||||
@@ -77,9 +77,21 @@ describe('pythonApiContractV1', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('documents chat.translatePost contract with postId and targetLanguage params', () => {
|
||||
expect(getPythonApiMethodContract('chat.translatePost')).toEqual({
|
||||
method: 'chat.translatePost',
|
||||
description: 'Translate a post into a target language and save it as a translation draft.',
|
||||
params: [
|
||||
{ name: 'postId', type: 'string', required: true },
|
||||
{ name: 'targetLanguage', type: 'string', required: true },
|
||||
],
|
||||
returns: 'PostTranslationResult',
|
||||
});
|
||||
});
|
||||
|
||||
it('contains semantic version metadata for compatibility checks', () => {
|
||||
expect(BDS_PYTHON_API_CONTRACT_V1).toMatchObject({
|
||||
version: '1.13.0',
|
||||
version: '1.15.0',
|
||||
generatedAt: expect.any(String),
|
||||
});
|
||||
});
|
||||
@@ -116,6 +128,7 @@ describe('generatePythonApiModuleV1', () => {
|
||||
expect(moduleCode).toContain('class ChatApi:');
|
||||
expect(moduleCode).toContain('async def analyze_media_image(self, media_id, language=None):');
|
||||
expect(moduleCode).toContain('async def detect_post_language(self, title, content):');
|
||||
expect(moduleCode).toContain('async def translate_post(self, post_id, target_language):');
|
||||
});
|
||||
|
||||
it('escapes python keyword method names to valid identifiers', () => {
|
||||
|
||||
@@ -55,6 +55,27 @@ describe('invokePythonApiMethodV1', () => {
|
||||
expect(getProjectMetadata).toHaveBeenCalledWith();
|
||||
});
|
||||
|
||||
it('invokes chat.translatePost via electronAPI with validated args', async () => {
|
||||
const translatePost = vi.fn().mockResolvedValue({
|
||||
success: true,
|
||||
translation: { id: 'tr-1', language: 'de' },
|
||||
});
|
||||
|
||||
vi.stubGlobal('window', {
|
||||
electronAPI: {
|
||||
chat: {
|
||||
translatePost,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
await expect(invokePythonApiMethodV1('chat.translatePost', { postId: 'p1', targetLanguage: 'de' })).resolves.toEqual({
|
||||
success: true,
|
||||
translation: { id: 'tr-1', language: 'de' },
|
||||
});
|
||||
expect(translatePost).toHaveBeenCalledWith('p1', 'de');
|
||||
});
|
||||
|
||||
it('rejects unknown methods and malformed args', async () => {
|
||||
vi.stubGlobal('window', {
|
||||
electronAPI: {
|
||||
|
||||
Reference in New Issue
Block a user