@terai/translator 0.0.0-dev-20240101200600 → 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,CAC9B,WAAAC,EACA,cAAAC,EACA,OAAAC,EACA,WAAAC,CACF,EAA0C,CACxC,OAAOA,EAAW,CAChB,WAAAH,EACA,cAAAC,EACA,OAAAC,CACF,CAAC,CACH","sourcesContent":["// Types\nimport type { Config, Locale, Dictionary } from '@terai/types'\n\nexport type TranslateOptions = Pick<Config, 'translator' | 'projectLocale'> & {\n dictionary: Dictionary\n locale: Locale\n}\n\nexport async function translate({\n dictionary,\n projectLocale,\n locale,\n translator\n}: TranslateOptions): Promise<Dictionary> {\n return translator({\n dictionary,\n projectLocale,\n locale\n })\n}\n"]}
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"]}
@@ -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 dictionary: Dictionary\n locale: Locale\n}\n\nexport async function translate({\n dictionary,\n projectLocale,\n locale,\n translator\n}: TranslateOptions): Promise<Dictionary> {\n return translator({\n dictionary,\n projectLocale,\n locale\n })\n}\n"],"mappings":"AAQA,eAAsBA,EAAU,CAC9B,WAAAC,EACA,cAAAC,EACA,OAAAC,EACA,WAAAC,CACF,EAA0C,CACxC,OAAOA,EAAW,CAChB,WAAAH,EACA,cAAAC,EACA,OAAAC,CACF,CAAC,CACH","names":["translate","dictionary","projectLocale","locale","translator"]}
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,CACvE,IAAMC,EAAS,IAAIH,EAAOE,CAAa,EAmCvC,MAjC+B,OAAO,CACpC,WAAAE,EACA,cAAAC,EACA,OAAAC,CACF,IAAM,CACJ,IAAMC,EAAe,KAAK,UAAUH,CAAU,EAExCI,EAAW,MAAML,EAAO,KAAK,YAAY,OAAO,CACpD,MAAO,gBACP,SAAU,CACR,CACE,KAAM,SACN,QAAS,CACP,qCAAqCE,CAAa,gBAAgBC,CAAM,GACxE,wCACA,iDACF,EAAE,KAAK;AAAA,CAAK,CACd,EACA,CACE,KAAM,OACN,QAASC,CACX,CACF,EACA,YAAa,GACb,kBAAmB,GACnB,iBAAkB,EACpB,CAAC,EAED,OAAO,KAAK,MACVC,GAAU,UAAU,CAAC,GAAG,SAAS,SAAW,IAC9C,CACF,CAGF,EC1CA,OAAS,MAAAC,MAAU,0BAKZ,IAAMC,EAA+BC,GAAgC,CAC1E,IAAMC,EAAY,IAAIH,EAAG,UAAUE,CAAO,EAkB1C,MAhB+B,OAAO,CAAE,WAAAP,EAAY,OAAAE,CAAO,IAAM,CAC/D,IAAMO,EAA+B,CAAC,EAEtC,aAAM,QAAQ,IACZ,OAAO,KAAKT,CAAU,EAAE,IAAI,MAAMU,GAAO,CACvC,IAAMC,EAAQX,EAAWU,CAAG,EAEtB,CAACE,CAAW,EAAI,MAAMJ,EAAU,UAAUG,EAAOT,CAAM,EAE7DO,EAAiBC,CAAG,EAAIE,CAC1B,CAAC,CACH,EAEOH,CACT,CAGF","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 const openai = new OpenAI(openaiOptions)\n\n const translator: Translator = async ({\n dictionary,\n projectLocale,\n locale\n }) => {\n const messagesJson = JSON.stringify(dictionary)\n\n const response = await openai.chat.completions.create({\n model: 'gpt-3.5-turbo',\n messages: [\n {\n role: 'system',\n content: [\n `Translate this JSON (from locale: ${projectLocale}} to locale: ${locale}`,\n 'Do not translate the keys of the json',\n 'Do not translate ${var}, just leave it as it is'\n ].join('.\\n')\n },\n {\n role: 'user',\n content: messagesJson\n }\n ],\n temperature: 0.4,\n frequency_penalty: -2.0,\n presence_penalty: -2.0\n })\n\n return JSON.parse(\n response?.choices?.[0]?.message?.content || '{}'\n ) as Dictionary\n }\n\n return 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 const translate = new v2.Translate(options)\n\n const translator: Translator = async ({ dictionary, locale }) => {\n const translatedOutput: Dictionary = {}\n\n await Promise.all(\n Object.keys(dictionary).map(async key => {\n const value = dictionary[key]\n\n const [translation] = await translate.translate(value, locale)\n\n translatedOutput[key] = translation\n })\n )\n\n return translatedOutput\n }\n\n return translator\n}\n"]}
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 const openai = new OpenAI(openaiOptions)\n\n const translator: Translator = async ({\n dictionary,\n projectLocale,\n locale\n }) => {\n const messagesJson = JSON.stringify(dictionary)\n\n const response = await openai.chat.completions.create({\n model: 'gpt-3.5-turbo',\n messages: [\n {\n role: 'system',\n content: [\n `Translate this JSON (from locale: ${projectLocale}} to locale: ${locale}`,\n 'Do not translate the keys of the json',\n 'Do not translate ${var}, just leave it as it is'\n ].join('.\\n')\n },\n {\n role: 'user',\n content: messagesJson\n }\n ],\n temperature: 0.4,\n frequency_penalty: -2.0,\n presence_penalty: -2.0\n })\n\n return JSON.parse(\n response?.choices?.[0]?.message?.content || '{}'\n ) as Dictionary\n }\n\n return 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 const translate = new v2.Translate(options)\n\n const translator: Translator = async ({ dictionary, locale }) => {\n const translatedOutput: Dictionary = {}\n\n await Promise.all(\n Object.keys(dictionary).map(async key => {\n const value = dictionary[key]\n\n const [translation] = await translate.translate(value, locale)\n\n translatedOutput[key] = translation\n })\n )\n\n return translatedOutput\n }\n\n return translator\n}\n"],"mappings":"AACA,OAAOA,MAAoC,SAKpC,IAAMC,EAA2BC,GAAiC,CACvE,IAAMC,EAAS,IAAIH,EAAOE,CAAa,EAmCvC,MAjC+B,OAAO,CACpC,WAAAE,EACA,cAAAC,EACA,OAAAC,CACF,IAAM,CACJ,IAAMC,EAAe,KAAK,UAAUH,CAAU,EAExCI,EAAW,MAAML,EAAO,KAAK,YAAY,OAAO,CACpD,MAAO,gBACP,SAAU,CACR,CACE,KAAM,SACN,QAAS,CACP,qCAAqCE,CAAa,gBAAgBC,CAAM,GACxE,wCACA,iDACF,EAAE,KAAK;AAAA,CAAK,CACd,EACA,CACE,KAAM,OACN,QAASC,CACX,CACF,EACA,YAAa,GACb,kBAAmB,GACnB,iBAAkB,EACpB,CAAC,EAED,OAAO,KAAK,MACVC,GAAU,UAAU,CAAC,GAAG,SAAS,SAAW,IAC9C,CACF,CAGF,EC1CA,OAAS,MAAAC,MAAU,0BAKZ,IAAMC,EAA+BC,GAAgC,CAC1E,IAAMC,EAAY,IAAIH,EAAG,UAAUE,CAAO,EAkB1C,MAhB+B,OAAO,CAAE,WAAAE,EAAY,OAAAC,CAAO,IAAM,CAC/D,IAAMC,EAA+B,CAAC,EAEtC,aAAM,QAAQ,IACZ,OAAO,KAAKF,CAAU,EAAE,IAAI,MAAMG,GAAO,CACvC,IAAMC,EAAQJ,EAAWG,CAAG,EAEtB,CAACE,CAAW,EAAI,MAAMN,EAAU,UAAUK,EAAOH,CAAM,EAE7DC,EAAiBC,CAAG,EAAIE,CAC1B,CAAC,CACH,EAEOH,CACT,CAGF","names":["OpenAI","createChatGptTranslator","openaiOptions","openai","dictionary","projectLocale","locale","messagesJson","response","v2","createGoogleCloudTranslator","options","translate","dictionary","locale","translatedOutput","key","value","translation"]}
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-20240101200600",
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-20240101200600",
34
- "@terai/types": "0.0.0-dev-20240101200600",
35
- "@terai/utils": "0.0.0-dev-20240101200600"
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",