@terai/translator 0.0.0-dev-20240103164648 → 0.0.0-dev-20240302092932
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.
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/translate.ts"],"names":["translate","dictionary","projectLocale","locale","translator"],"mappings":"AAQA,eAAsBA,EAAU,
|
|
1
|
+
{"version":3,"sources":["../src/translate.ts"],"names":["translate","dictionary","projectLocale","locale","translator"],"mappings":"AAQA,eAAsBA,EAAU,CAC/B,WAAAC,EACA,cAAAC,EACA,OAAAC,EACA,WAAAC,CACD,EAA0C,CACzC,OAAOA,EAAW,CACjB,WAAAH,EACA,cAAAC,EACA,OAAAC,CACD,CAAC,CACF","sourcesContent":["// Types\nimport type { Config, Locale, Dictionary } from '@terai/types'\n\nexport type TranslateOptions = Pick<Config, 'translator' | 'projectLocale'> & {\n\tdictionary: Dictionary\n\tlocale: Locale\n}\n\nexport async function translate({\n\tdictionary,\n\tprojectLocale,\n\tlocale,\n\ttranslator\n}: TranslateOptions): Promise<Dictionary> {\n\treturn translator({\n\t\tdictionary,\n\t\tprojectLocale,\n\t\tlocale\n\t})\n}\n"]}
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/translate.ts"],"sourcesContent":["// Types\nimport type { Config, Locale, Dictionary } from '@terai/types'\n\nexport type TranslateOptions = Pick<Config, 'translator' | 'projectLocale'> & {\n
|
|
1
|
+
{"version":3,"sources":["../src/translate.ts"],"sourcesContent":["// Types\nimport type { Config, Locale, Dictionary } from '@terai/types'\n\nexport type TranslateOptions = Pick<Config, 'translator' | 'projectLocale'> & {\n\tdictionary: Dictionary\n\tlocale: Locale\n}\n\nexport async function translate({\n\tdictionary,\n\tprojectLocale,\n\tlocale,\n\ttranslator\n}: TranslateOptions): Promise<Dictionary> {\n\treturn translator({\n\t\tdictionary,\n\t\tprojectLocale,\n\t\tlocale\n\t})\n}\n"],"mappings":"AAQA,eAAsBA,EAAU,CAC/B,WAAAC,EACA,cAAAC,EACA,OAAAC,EACA,WAAAC,CACD,EAA0C,CACzC,OAAOA,EAAW,CACjB,WAAAH,EACA,cAAAC,EACA,OAAAC,CACD,CAAC,CACF","names":["translate","dictionary","projectLocale","locale","translator"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/translators/chat-gpt.ts","../../src/translators/google-cloud.ts"],"names":["OpenAI","createChatGptTranslator","openaiOptions","openai","dictionary","projectLocale","locale","messagesJson","response","v2","createGoogleCloudTranslator","options","translate","translatedOutput","key","value","translation"],"mappings":"AACA,OAAOA,MAAoC,SAKpC,IAAMC,EAA2BC,GAAiC,
|
|
1
|
+
{"version":3,"sources":["../../src/translators/chat-gpt.ts","../../src/translators/google-cloud.ts"],"names":["OpenAI","createChatGptTranslator","openaiOptions","openai","dictionary","projectLocale","locale","messagesJson","response","v2","createGoogleCloudTranslator","options","translate","translatedOutput","key","value","translation"],"mappings":"AACA,OAAOA,MAAoC,SAKpC,IAAMC,EAA2BC,GAAiC,CACxE,IAAMC,EAAS,IAAIH,EAAOE,CAAa,EAmCvC,MAjC+B,OAAO,CACrC,WAAAE,EACA,cAAAC,EACA,OAAAC,CACD,IAAM,CACL,IAAMC,EAAe,KAAK,UAAUH,CAAU,EAExCI,EAAW,MAAML,EAAO,KAAK,YAAY,OAAO,CACrD,MAAO,gBACP,SAAU,CACT,CACC,KAAM,SACN,QAAS,CACR,qCAAqCE,CAAa,gBAAgBC,CAAM,GACxE,wCACA,iDACD,EAAE,KAAK;AAAA,CAAK,CACb,EACA,CACC,KAAM,OACN,QAASC,CACV,CACD,EACA,YAAa,GACb,kBAAmB,GACnB,iBAAkB,EACnB,CAAC,EAED,OAAO,KAAK,MACXC,GAAU,UAAU,CAAC,GAAG,SAAS,SAAW,IAC7C,CACD,CAGD,EC1CA,OAAS,MAAAC,MAAU,0BAKZ,IAAMC,EAA+BC,GAAgC,CAC3E,IAAMC,EAAY,IAAIH,EAAG,UAAUE,CAAO,EAkB1C,MAhB+B,OAAO,CAAE,WAAAP,EAAY,OAAAE,CAAO,IAAM,CAChE,IAAMO,EAA+B,CAAC,EAEtC,aAAM,QAAQ,IACb,OAAO,KAAKT,CAAU,EAAE,IAAI,MAAOU,GAAQ,CAC1C,IAAMC,EAAQX,EAAWU,CAAG,EAEtB,CAACE,CAAW,EAAI,MAAMJ,EAAU,UAAUG,EAAOT,CAAM,EAE7DO,EAAiBC,CAAG,EAAIE,CACzB,CAAC,CACF,EAEOH,CACR,CAGD","sourcesContent":["// Dependencies\nimport OpenAI, { type ClientOptions } from 'openai'\n\n// Types\nimport type { Dictionary, Translator } from '@terai/types'\n\nexport const createChatGptTranslator = (openaiOptions: ClientOptions) => {\n\tconst openai = new OpenAI(openaiOptions)\n\n\tconst translator: Translator = async ({\n\t\tdictionary,\n\t\tprojectLocale,\n\t\tlocale\n\t}) => {\n\t\tconst messagesJson = JSON.stringify(dictionary)\n\n\t\tconst response = await openai.chat.completions.create({\n\t\t\tmodel: 'gpt-3.5-turbo',\n\t\t\tmessages: [\n\t\t\t\t{\n\t\t\t\t\trole: 'system',\n\t\t\t\t\tcontent: [\n\t\t\t\t\t\t`Translate this JSON (from locale: ${projectLocale}} to locale: ${locale}`,\n\t\t\t\t\t\t'Do not translate the keys of the json',\n\t\t\t\t\t\t'Do not translate ${var}, just leave it as it is'\n\t\t\t\t\t].join('.\\n')\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\trole: 'user',\n\t\t\t\t\tcontent: messagesJson\n\t\t\t\t}\n\t\t\t],\n\t\t\ttemperature: 0.4,\n\t\t\tfrequency_penalty: -2.0,\n\t\t\tpresence_penalty: -2.0\n\t\t})\n\n\t\treturn JSON.parse(\n\t\t\tresponse?.choices?.[0]?.message?.content || '{}'\n\t\t) as Dictionary\n\t}\n\n\treturn translator\n}\n","// Dependencies\nimport { v2 } from '@google-cloud/translate'\n\n// Types\nimport type { Dictionary, Translator } from '@terai/types'\n\nexport const createGoogleCloudTranslator = (options: v2.TranslateConfig) => {\n\tconst translate = new v2.Translate(options)\n\n\tconst translator: Translator = async ({ dictionary, locale }) => {\n\t\tconst translatedOutput: Dictionary = {}\n\n\t\tawait Promise.all(\n\t\t\tObject.keys(dictionary).map(async (key) => {\n\t\t\t\tconst value = dictionary[key]\n\n\t\t\t\tconst [translation] = await translate.translate(value, locale)\n\n\t\t\t\ttranslatedOutput[key] = translation\n\t\t\t})\n\t\t)\n\n\t\treturn translatedOutput\n\t}\n\n\treturn translator\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/translators/chat-gpt.ts","../../src/translators/google-cloud.ts"],"sourcesContent":["// Dependencies\nimport OpenAI, { type ClientOptions } from 'openai'\n\n// Types\nimport type { Dictionary, Translator } from '@terai/types'\n\nexport const createChatGptTranslator = (openaiOptions: ClientOptions) => {\n
|
|
1
|
+
{"version":3,"sources":["../../src/translators/chat-gpt.ts","../../src/translators/google-cloud.ts"],"sourcesContent":["// Dependencies\nimport OpenAI, { type ClientOptions } from 'openai'\n\n// Types\nimport type { Dictionary, Translator } from '@terai/types'\n\nexport const createChatGptTranslator = (openaiOptions: ClientOptions) => {\n\tconst openai = new OpenAI(openaiOptions)\n\n\tconst translator: Translator = async ({\n\t\tdictionary,\n\t\tprojectLocale,\n\t\tlocale\n\t}) => {\n\t\tconst messagesJson = JSON.stringify(dictionary)\n\n\t\tconst response = await openai.chat.completions.create({\n\t\t\tmodel: 'gpt-3.5-turbo',\n\t\t\tmessages: [\n\t\t\t\t{\n\t\t\t\t\trole: 'system',\n\t\t\t\t\tcontent: [\n\t\t\t\t\t\t`Translate this JSON (from locale: ${projectLocale}} to locale: ${locale}`,\n\t\t\t\t\t\t'Do not translate the keys of the json',\n\t\t\t\t\t\t'Do not translate ${var}, just leave it as it is'\n\t\t\t\t\t].join('.\\n')\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\trole: 'user',\n\t\t\t\t\tcontent: messagesJson\n\t\t\t\t}\n\t\t\t],\n\t\t\ttemperature: 0.4,\n\t\t\tfrequency_penalty: -2.0,\n\t\t\tpresence_penalty: -2.0\n\t\t})\n\n\t\treturn JSON.parse(\n\t\t\tresponse?.choices?.[0]?.message?.content || '{}'\n\t\t) as Dictionary\n\t}\n\n\treturn translator\n}\n","// Dependencies\nimport { v2 } from '@google-cloud/translate'\n\n// Types\nimport type { Dictionary, Translator } from '@terai/types'\n\nexport const createGoogleCloudTranslator = (options: v2.TranslateConfig) => {\n\tconst translate = new v2.Translate(options)\n\n\tconst translator: Translator = async ({ dictionary, locale }) => {\n\t\tconst translatedOutput: Dictionary = {}\n\n\t\tawait Promise.all(\n\t\t\tObject.keys(dictionary).map(async (key) => {\n\t\t\t\tconst value = dictionary[key]\n\n\t\t\t\tconst [translation] = await translate.translate(value, locale)\n\n\t\t\t\ttranslatedOutput[key] = translation\n\t\t\t})\n\t\t)\n\n\t\treturn translatedOutput\n\t}\n\n\treturn translator\n}\n"],"mappings":"AACA,OAAOA,MAAoC,SAKpC,IAAMC,EAA2BC,GAAiC,CACxE,IAAMC,EAAS,IAAIH,EAAOE,CAAa,EAmCvC,MAjC+B,OAAO,CACrC,WAAAE,EACA,cAAAC,EACA,OAAAC,CACD,IAAM,CACL,IAAMC,EAAe,KAAK,UAAUH,CAAU,EAExCI,EAAW,MAAML,EAAO,KAAK,YAAY,OAAO,CACrD,MAAO,gBACP,SAAU,CACT,CACC,KAAM,SACN,QAAS,CACR,qCAAqCE,CAAa,gBAAgBC,CAAM,GACxE,wCACA,iDACD,EAAE,KAAK;AAAA,CAAK,CACb,EACA,CACC,KAAM,OACN,QAASC,CACV,CACD,EACA,YAAa,GACb,kBAAmB,GACnB,iBAAkB,EACnB,CAAC,EAED,OAAO,KAAK,MACXC,GAAU,UAAU,CAAC,GAAG,SAAS,SAAW,IAC7C,CACD,CAGD,EC1CA,OAAS,MAAAC,MAAU,0BAKZ,IAAMC,EAA+BC,GAAgC,CAC3E,IAAMC,EAAY,IAAIH,EAAG,UAAUE,CAAO,EAkB1C,MAhB+B,OAAO,CAAE,WAAAE,EAAY,OAAAC,CAAO,IAAM,CAChE,IAAMC,EAA+B,CAAC,EAEtC,aAAM,QAAQ,IACb,OAAO,KAAKF,CAAU,EAAE,IAAI,MAAOG,GAAQ,CAC1C,IAAMC,EAAQJ,EAAWG,CAAG,EAEtB,CAACE,CAAW,EAAI,MAAMN,EAAU,UAAUK,EAAOH,CAAM,EAE7DC,EAAiBC,CAAG,EAAIE,CACzB,CAAC,CACF,EAEOH,CACR,CAGD","names":["OpenAI","createChatGptTranslator","openaiOptions","openai","dictionary","projectLocale","locale","messagesJson","response","v2","createGoogleCloudTranslator","options","translate","dictionary","locale","translatedOutput","key","value","translation"]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@terai/translator",
|
|
3
3
|
"description": "terai core translator",
|
|
4
|
-
"version": "0.0.0-dev-
|
|
4
|
+
"version": "0.0.0-dev-20240302092932",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -30,9 +30,9 @@
|
|
|
30
30
|
"openai": "^4"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@terai/runtime": "0.0.0-dev-
|
|
34
|
-
"@terai/types": "0.0.0-dev-
|
|
35
|
-
"@terai/utils": "0.0.0-dev-
|
|
33
|
+
"@terai/runtime": "0.0.0-dev-20240302092932",
|
|
34
|
+
"@terai/types": "0.0.0-dev-20240302092932",
|
|
35
|
+
"@terai/utils": "0.0.0-dev-20240302092932"
|
|
36
36
|
},
|
|
37
37
|
"scripts": {
|
|
38
38
|
"dev": "tsup --format=esm,cjs --no-dts --watch",
|