@goenhance/strapi-plugins-translate 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +88 -0
  3. package/dist/_chunks/App-DvJ8tPer.js +674 -0
  4. package/dist/_chunks/App-uB_CPrcd.mjs +674 -0
  5. package/dist/_chunks/en-BOBGCAB6.mjs +65 -0
  6. package/dist/_chunks/en-BaJyCZ_c.js +65 -0
  7. package/dist/_chunks/index-B8MBOdIV.js +276 -0
  8. package/dist/_chunks/index-DkZZ45sW.mjs +277 -0
  9. package/dist/_chunks/zh-CtGwhmjc.mjs +65 -0
  10. package/dist/_chunks/zh-DUCnaWvE.js +65 -0
  11. package/dist/_chunks/zh-Hans-CJW3RUKL.js +65 -0
  12. package/dist/_chunks/zh-Hans-pTiPqgIS.mjs +65 -0
  13. package/dist/admin/index.js +3 -0
  14. package/dist/admin/index.mjs +4 -0
  15. package/dist/admin/src/components/Initializer.d.ts +5 -0
  16. package/dist/admin/src/components/LLMButton.d.ts +2 -0
  17. package/dist/admin/src/components/PluginIcon.d.ts +18 -0
  18. package/dist/admin/src/index.d.ts +11 -0
  19. package/dist/admin/src/pages/App.d.ts +2 -0
  20. package/dist/admin/src/pages/BatchTranslatePage.d.ts +2 -0
  21. package/dist/admin/src/pages/SettingsPage.d.ts +2 -0
  22. package/dist/admin/src/pluginId.d.ts +1 -0
  23. package/dist/admin/src/utils/constants.d.ts +4 -0
  24. package/dist/admin/src/utils/getLocaleFromUrl.d.ts +1 -0
  25. package/dist/admin/src/utils/getTranslation.d.ts +2 -0
  26. package/dist/server/index.js +754 -0
  27. package/dist/server/index.mjs +755 -0
  28. package/dist/server/src/bootstrap.d.ts +5 -0
  29. package/dist/server/src/config/constants.d.ts +7 -0
  30. package/dist/server/src/config/index.d.ts +11 -0
  31. package/dist/server/src/content-types/index.d.ts +2 -0
  32. package/dist/server/src/controllers/admin.controller.d.ts +21 -0
  33. package/dist/server/src/controllers/index.d.ts +43 -0
  34. package/dist/server/src/destroy.d.ts +5 -0
  35. package/dist/server/src/index.d.ts +2 -0
  36. package/dist/server/src/middlewares/index.d.ts +2 -0
  37. package/dist/server/src/policies/index.d.ts +2 -0
  38. package/dist/server/src/register.d.ts +5 -0
  39. package/dist/server/src/routes/admin.d.ts +9 -0
  40. package/dist/server/src/routes/index.d.ts +14 -0
  41. package/dist/server/src/services/index.d.ts +2 -0
  42. package/dist/server/src/services/llm-service.d.ts +6 -0
  43. package/dist/server/src/types/controllers.d.ts +22 -0
  44. package/dist/server/src/types/index.d.ts +53 -0
  45. package/dist/server/src/utils/json-utils.d.ts +4 -0
  46. package/package.json +88 -0
@@ -0,0 +1,5 @@
1
+ import type { Core } from '@strapi/strapi';
2
+ declare const bootstrap: ({ strapi }: {
3
+ strapi: Core.Strapi;
4
+ }) => void;
5
+ export default bootstrap;
@@ -0,0 +1,7 @@
1
+ export declare const DEFAULT_SYSTEM_PROMPT = "You are a professional translator. Your task is to translate the provided content accurately while preserving the original meaning and tone.";
2
+ export declare const SYSTEM_PROMPT_APPENDIX = "The user asks you to translate the text to a specific language, the language is provided via short code like \"en\", \"fr\", \"de\", etc.";
3
+ export declare const DEFAULT_LLM_TEMPERATURE = 0.3;
4
+ export declare const DEFAULT_LLM_MODEL = "gpt-4o";
5
+ export declare const DEFAULT_LLM_BASE_URL = "https://api.openai.com/v1";
6
+ export declare const SYSTEM_PROMPT_FIX = "You are a JSON correction assistant. Only return valid, corrected JSON.";
7
+ export declare const USER_PROMPT_FIX_PREFIX = "Fix this invalid JSON and return ONLY the corrected JSON. No explanations allowed. The JSON is:";
@@ -0,0 +1,11 @@
1
+ declare const _default: {
2
+ default: ({ env }: {
3
+ env: any;
4
+ }) => {
5
+ llmApiKey: any;
6
+ llmEndpoint: any;
7
+ llmModel: any;
8
+ };
9
+ validator(config: any): void;
10
+ };
11
+ export default _default;
@@ -0,0 +1,2 @@
1
+ declare const _default: {};
2
+ export default _default;
@@ -0,0 +1,21 @@
1
+ import { BatchTranslateRequestBody, GenerateRequestBody, RequestContext, StrapiContext } from 'src/types';
2
+ declare const controllers: ({ strapi }: StrapiContext) => {
3
+ generate(ctx: RequestContext & {
4
+ request: {
5
+ body: GenerateRequestBody;
6
+ };
7
+ }): Promise<void>;
8
+ getConfig(ctx: RequestContext): Promise<void>;
9
+ setConfig(ctx: RequestContext): Promise<void>;
10
+ getContentTypes(ctx: RequestContext): Promise<void>;
11
+ getLocales(ctx: RequestContext): Promise<void>;
12
+ getEntries(ctx: RequestContext<object, {
13
+ contentType: string;
14
+ }>): Promise<void>;
15
+ batchTranslate(ctx: RequestContext & {
16
+ request: {
17
+ body: BatchTranslateRequestBody;
18
+ };
19
+ }): Promise<void>;
20
+ };
21
+ export default controllers;
@@ -0,0 +1,43 @@
1
+ /// <reference types="koa" />
2
+ declare const _default: {
3
+ admin: ({ strapi }: import("../types").StrapiContext) => {
4
+ generate(ctx: Omit<import("koa").Context, "body" | "query" | "request"> & {
5
+ body: object;
6
+ query: object;
7
+ params: object;
8
+ request: Omit<import("koa").Request, "body"> & {
9
+ body: object;
10
+ };
11
+ state: {
12
+ user?: import("../types").AdminUser;
13
+ };
14
+ } & {
15
+ request: {
16
+ body: import("../types").GenerateRequestBody;
17
+ };
18
+ }): Promise<void>;
19
+ getConfig(ctx: import("../types").RequestContext): Promise<void>;
20
+ setConfig(ctx: import("../types").RequestContext): Promise<void>;
21
+ getContentTypes(ctx: import("../types").RequestContext): Promise<void>;
22
+ getLocales(ctx: import("../types").RequestContext): Promise<void>;
23
+ getEntries(ctx: import("../types").RequestContext<object, {
24
+ contentType: string;
25
+ }>): Promise<void>;
26
+ batchTranslate(ctx: Omit<import("koa").Context, "body" | "query" | "request"> & {
27
+ body: object;
28
+ query: object;
29
+ params: object;
30
+ request: Omit<import("koa").Request, "body"> & {
31
+ body: object;
32
+ };
33
+ state: {
34
+ user?: import("../types").AdminUser;
35
+ };
36
+ } & {
37
+ request: {
38
+ body: import("../types").BatchTranslateRequestBody;
39
+ };
40
+ }): Promise<void>;
41
+ };
42
+ };
43
+ export default _default;
@@ -0,0 +1,5 @@
1
+ import type { Core } from '@strapi/strapi';
2
+ declare const destroy: ({ strapi }: {
3
+ strapi: Core.Strapi;
4
+ }) => void;
5
+ export default destroy;
@@ -0,0 +1,2 @@
1
+ declare const plugin: Record<string, unknown>;
2
+ export default plugin;
@@ -0,0 +1,2 @@
1
+ declare const _default: {};
2
+ export default _default;
@@ -0,0 +1,2 @@
1
+ declare const _default: {};
2
+ export default _default;
@@ -0,0 +1,5 @@
1
+ import type { Core } from '@strapi/strapi';
2
+ declare const register: ({ strapi }: {
3
+ strapi: Core.Strapi;
4
+ }) => void;
5
+ export default register;
@@ -0,0 +1,9 @@
1
+ declare const _default: {
2
+ method: string;
3
+ path: string;
4
+ handler: string;
5
+ config: {
6
+ policies: any[];
7
+ };
8
+ }[];
9
+ export default _default;
@@ -0,0 +1,14 @@
1
+ declare const routes: {
2
+ admin: {
3
+ type: string;
4
+ routes: {
5
+ method: string;
6
+ path: string;
7
+ handler: string;
8
+ config: {
9
+ policies: any[];
10
+ };
11
+ }[];
12
+ };
13
+ };
14
+ export default routes;
@@ -0,0 +1,2 @@
1
+ declare const services: Record<string, unknown>;
2
+ export default services;
@@ -0,0 +1,6 @@
1
+ import type { Core } from '@strapi/strapi';
2
+ import { LLMServiceType } from '../../src/types';
3
+ declare const llmService: ({ strapi }: {
4
+ strapi: Core.Strapi;
5
+ }) => LLMServiceType;
6
+ export default llmService;
@@ -0,0 +1,22 @@
1
+ import { Context } from 'koa';
2
+ export type AdminUser = {
3
+ id: string | number;
4
+ email: string;
5
+ username: string;
6
+ avatar?: string;
7
+ };
8
+ export type RequestContext<Body = object, PathParams = object, QueryParams = object> = Omit<Context, 'body' | 'query' | 'request'> & {
9
+ body: Body;
10
+ query: QueryParams;
11
+ params: PathParams;
12
+ request: Omit<Context['request'], 'body'> & {
13
+ body: Body;
14
+ };
15
+ state: {
16
+ user?: AdminUser;
17
+ };
18
+ };
19
+ export interface PluginUserConfig {
20
+ systemPrompt: string;
21
+ temperature: number;
22
+ }
@@ -0,0 +1,53 @@
1
+ import type { Core } from '@strapi/strapi';
2
+ export * from './controllers';
3
+ export type CoreStrapi = Omit<Core.Strapi, 'query' | 'plugin'> & {
4
+ plugin: (pluginName: string) => Omit<Core.Plugin, 'contentTypes'> & {
5
+ contentTypes: Record<string, Core.Plugin['contentTypes'][string] & {
6
+ uid: string;
7
+ }>;
8
+ };
9
+ };
10
+ export type StrapiContext = {
11
+ readonly strapi: CoreStrapi;
12
+ };
13
+ export interface TranslationResponse {
14
+ data: Record<string, any>;
15
+ meta: {
16
+ ok: boolean;
17
+ status: number;
18
+ message?: string;
19
+ };
20
+ }
21
+ export interface TranslationConfig {
22
+ targetLanguage: string;
23
+ }
24
+ export interface LLMServiceType {
25
+ generateWithLLM(contentType: Record<string, any>, fields: Record<string, any>, components: Record<string, any>, config: TranslationConfig): Promise<Record<string, any>>;
26
+ }
27
+ export interface GenerateRequestBody {
28
+ contentType: string;
29
+ fields: any;
30
+ components: any;
31
+ targetLanguage: string;
32
+ }
33
+ export interface TranslatableField {
34
+ path: string[];
35
+ value: any;
36
+ originalPath: string[];
37
+ }
38
+ export interface UIDField {
39
+ fieldName: string;
40
+ targetField: string;
41
+ }
42
+ export interface LLMConfigType {
43
+ llmEndpoint: string;
44
+ llmApiKey: string;
45
+ llmModel: string;
46
+ }
47
+ export interface BatchTranslateRequestBody {
48
+ contentType: string;
49
+ entries: string[];
50
+ sourceLocale: string;
51
+ targetLocales: string[];
52
+ publish?: boolean;
53
+ }
@@ -0,0 +1,4 @@
1
+ export declare const cleanJSONString: (content: string) => string;
2
+ export declare const balanceJSONBraces: (content: string) => string;
3
+ export declare const extractJSONObject: (content: string) => string;
4
+ export declare const safeJSONParse: (content: string) => Record<string, any>;
package/package.json ADDED
@@ -0,0 +1,88 @@
1
+ {
2
+ "version": "0.11.0",
3
+ "keywords": [
4
+ "strapi",
5
+ "plugin",
6
+ "translation",
7
+ "ai",
8
+ "llm",
9
+ "batch-translation"
10
+ ],
11
+ "type": "commonjs",
12
+ "exports": {
13
+ "./package.json": "./package.json",
14
+ "./strapi-admin": {
15
+ "types": "./dist/admin/src/index.d.ts",
16
+ "source": "./admin/src/index.ts",
17
+ "import": "./dist/admin/index.mjs",
18
+ "require": "./dist/admin/index.js",
19
+ "default": "./dist/admin/index.js"
20
+ },
21
+ "./strapi-server": {
22
+ "types": "./dist/server/src/index.d.ts",
23
+ "source": "./server/src/index.ts",
24
+ "import": "./dist/server/index.mjs",
25
+ "require": "./dist/server/index.js",
26
+ "default": "./dist/server/index.js"
27
+ }
28
+ },
29
+ "files": [
30
+ "dist",
31
+ "README.md",
32
+ "LICENSE"
33
+ ],
34
+ "scripts": {
35
+ "build": "strapi-plugin build",
36
+ "watch": "strapi-plugin watch",
37
+ "watch:link": "strapi-plugin watch:link",
38
+ "verify": "strapi-plugin verify",
39
+ "test:ts:front": "run -T tsc -p admin/tsconfig.json",
40
+ "test:ts:back": "run -T tsc -p server/tsconfig.json"
41
+ },
42
+ "dependencies": {
43
+ "@strapi/design-system": "^2.0.1",
44
+ "@strapi/icons": "^2.0.1",
45
+ "openai": "^5.3.0",
46
+ "react-intl": "^7.1.11"
47
+ },
48
+ "devDependencies": {
49
+ "@strapi/sdk-plugin": "^5.3.2",
50
+ "@strapi/strapi": "^5.31.3",
51
+ "@strapi/typescript-utils": "^5.31.3",
52
+ "@types/koa": "^3.0.1",
53
+ "@types/react": "^19.1.8",
54
+ "@types/react-dom": "^19.1.6",
55
+ "prettier": "^3.5.3",
56
+ "react": "^19.1.0",
57
+ "react-dom": "^19.1.0",
58
+ "react-router-dom": "^7.6.2",
59
+ "styled-components": "^6.1.18",
60
+ "typescript": "^5.8.3"
61
+ },
62
+ "peerDependencies": {
63
+ "@strapi/sdk-plugin": "^5.3.2",
64
+ "@strapi/strapi": ">=5.31.3",
65
+ "react": "^18.3.1",
66
+ "react-dom": "^18.3.1",
67
+ "react-router-dom": "^6.30.0",
68
+ "styled-components": "^6.1.17"
69
+ },
70
+ "strapi": {
71
+ "kind": "plugin",
72
+ "name": "strapi-plugins-translate",
73
+ "displayName": "LLM Translator",
74
+ "description": "AI-Powered Content Translation for Strapi with Batch Translation Support"
75
+ },
76
+ "name": "@goenhance/strapi-plugins-translate",
77
+ "description": "AI-Powered Content Translation for Strapi with Batch Translation Support. Forked from strapi-llm-translator by grenzbotin.",
78
+ "license": "MIT",
79
+ "author": "MewX (forked from grenzbotin <franziska@vulpis.dev>)",
80
+ "repository": {
81
+ "type": "git",
82
+ "url": "https://github.com/goenhance/strapi-plugins-translate.git"
83
+ },
84
+ "bugs": {
85
+ "url": "https://github.com/goenhance/strapi-plugins-translate/issues"
86
+ },
87
+ "homepage": "https://github.com/goenhance/strapi-plugins-translate#readme"
88
+ }