diff --git a/components/translate_com/.gitignore b/components/translate_com/.gitignore deleted file mode 100644 index ec761ccab7595..0000000000000 --- a/components/translate_com/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -*.js -*.mjs -dist \ No newline at end of file diff --git a/components/translate_com/actions/translate-text/translate-text.mjs b/components/translate_com/actions/translate-text/translate-text.mjs new file mode 100644 index 0000000000000..edf64b5f3424c --- /dev/null +++ b/components/translate_com/actions/translate-text/translate-text.mjs @@ -0,0 +1,50 @@ +import app from "../../translate_com.app.mjs"; + +export default { + name: "Translate Text", + version: "0.0.1", + key: "translate_com-translate-text", + description: "Translante a text using machine. [See the documentation](https://translation-api.translate.com/api/documentation?_gl=1*1qes1da*_ga*MTMwNzkzMTg3OC4xNjk1NDE3MDIy*_ga_T51KL347BB*MTY5NTQxNzAyMS4xLjAuMTY5NTQxNzAyMS42MC4wLjA.#/Machine Translation)", + type: "action", + props: { + app, + sourceLanguage: { + label: "Source language", + description: "The language of the source text", + propDefinition: [ + app, + "language", + ], + }, + translationLanguage: { + type: "string", + label: "Translation language", + description: "The translation language", + propDefinition: [ + app, + "language", + ], + }, + text: { + type: "string", + label: "Text", + description: "Text to be translated", + }, + }, + async run({ $ }) { + const response = await this.app.translateText({ + $, + data: { + source_language: this.sourceLanguage, + translation_language: this.translationLanguage, + text: this.text, + }, + }); + + if (response) { + $.export("$summary", "Successfully translated text"); + } + + return response; + }, +}; diff --git a/components/translate_com/app/translate_com.app.ts b/components/translate_com/app/translate_com.app.ts deleted file mode 100644 index ae5c1565ba146..0000000000000 --- a/components/translate_com/app/translate_com.app.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { defineApp } from "@pipedream/types"; - -export default defineApp({ - type: "app", - app: "translate_com", - propDefinitions: {}, - methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); - }, - }, -}); \ No newline at end of file diff --git a/components/translate_com/package.json b/components/translate_com/package.json index 08681f6771b18..a39a86c143fc5 100644 --- a/components/translate_com/package.json +++ b/components/translate_com/package.json @@ -1,16 +1,15 @@ { "name": "@pipedream/translate_com", - "version": "0.0.1", + "version": "0.1.0", "description": "Pipedream Translate.com Components", - "main": "dist/app/translate_com.app.mjs", + "main": "translate_com.app.mjs", "keywords": [ "pipedream", "translate_com" ], - "files": ["dist"], "homepage": "https://pipedream.com/apps/translate_com", "author": "Pipedream (https://pipedream.com/)", "publishConfig": { "access": "public" } -} \ No newline at end of file +} diff --git a/components/translate_com/translate_com.app.mjs b/components/translate_com/translate_com.app.mjs new file mode 100644 index 0000000000000..5157f5cd1838d --- /dev/null +++ b/components/translate_com/translate_com.app.mjs @@ -0,0 +1,54 @@ +import { axios } from "@pipedream/platform"; + +export default { + type: "app", + app: "translate_com", + propDefinitions: { + language: { + type: "string", + label: "Language", + description: "A language", + async options() { + const languages = await this.getLanguages(); + + return languages.map((language) => ({ + value: language.code, + label: language.name, + })); + }, + }, + }, + methods: { + _apiKey() { + return this.$auth.api_key; + }, + _apiUrl() { + return "https://translation-api.translate.com/translate/v1"; + }, + async _makeRequest({ + $ = this, path, ...args + }) { + return axios($, { + url: `${this._apiUrl()}${path}`, + ...args, + headers: { + ...args.headers, + "x-api-key": this._apiKey(), + }, + }); + }, + translateText(args = {}) { + return this._makeRequest({ + path: "/mt", + method: "post", + ...args, + }); + }, + getLanguages(args = {}) { + return this._makeRequest({ + path: "/mt-langs", + ...args, + }); + }, + }, +};