Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DO NOT MERGE: AI translate prototype #52

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft

Conversation

myovchev
Copy link
Contributor

Summary

SHOULD NOT BE MERGED, it's only a prototype/demo.

A quick implementation, that showcases the translate API core architecture and a provider external module. In this PR:

  • @apostrophecms/translation represents a core module, integration point for AI translation providers (external module).
  • deepl-provider represents an external AI translation provider that integrates with the core translation API
  • @apostrophecms/doc-type enhances the core with the required event for page localization (should be core change)
  • @apostrophecms/module adds the public registration handler for providers
  • default-page adds debug field type to demonstrate what meta information will be available to the admin UI
  • adds some more utilities to handle the DeepL API secret as environment (see below)

What are the specific steps to test this change?

  • Install the dependencies via npm install
  • create .env file in the project root and add DEEPL_API_SECRET=xxx where xxx is the API secret as seen in your DeepL account
  • Create an admin user and run the app (npm run dev)

What happens?

  • On init, the DeepL module registers itself as a translation provider.
  • A user creates page of type "default-page" and localizes it (extend @apostrophecms/page settings with any language you'd like) to existing locale. The prototype doesn't include any UI configuration ("Translate with ...), it translates by default and if enabled.
  • The core translation module hooks via the beforeLocalized event, finds the (only) provider, extracts the translation meta data, sets the meta state to pending and executes the provider's translation handler.
  • The DeepL provider validates the REST availability of the service (quotas), detects if the languages involved are supported, adapts its predefined service configuration, makes a request, sets the meta state to translated and returns the translated data to the core.
  • The core translation routine sets the translated values in the draft document.
  • Edit the localized document, verify "Title", "Slug" and "Main" area rich text widgets translation. Navigate to tag Debug to inspect what information is available in the admin UI.
  • After Publishing the page, the translation module sets the meta state to finalized (once) and prevents the meta to be copied to the published doc. Edit and verify in the debug tab the new and final state. Inspect the published document directly in the mongo database - aposTranslationMeta property shouldn't be found.

@myovchev myovchev marked this pull request as draft December 18, 2023 14:29
@myovchev myovchev changed the title AI translate prototype DO NOT MERGE: AI translate prototype Jan 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant