feat(libretranslate): add translate text action

This commit is contained in:
Rıdvan Akca
2024-06-03 12:03:38 +02:00
parent e6540b5b7e
commit 9d449a2a39
8 changed files with 135 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
import translateText from './translate-text/index.js';
export default [translateText];

View File

@@ -0,0 +1,86 @@
import defineAction from '../../../../helpers/define-action.js';
export default defineAction({
name: 'Translate text',
key: 'translateText',
description: 'Translate a text.',
arguments: [
{
label: 'Text',
key: 'text',
type: 'string',
required: true,
description: 'The text to translate.',
variables: true,
},
{
label: 'Source Language',
key: 'sourceLanguage',
type: 'dropdown',
required: true,
description: '',
variables: true,
source: {
type: 'query',
name: 'getDynamicData',
arguments: [
{
name: 'key',
value: 'listLanguages',
},
],
},
},
{
label: 'Target Language',
key: 'targetLanguage',
type: 'dropdown',
required: true,
description: '',
variables: true,
source: {
type: 'query',
name: 'getDynamicData',
arguments: [
{
name: 'key',
value: 'listLanguages',
},
],
},
},
{
label: 'Format',
key: 'format',
type: 'dropdown',
description: '',
required: false,
variables: true,
options: [
{
label: 'Text',
value: 'text',
},
{
label: 'HTML',
value: 'html',
},
],
},
],
async run($) {
const { text, sourceLanguage, targetLanguage, format } = $.step.parameters;
const body = {
q: text,
source: sourceLanguage,
target: targetLanguage,
format,
};
const response = await $.http.post('/translate', body);
$.setActionItem({ raw: response.data });
},
});

View File

@@ -0,0 +1,3 @@
import listLanguages from './list-languages/index.js';
export default [listLanguages];

View File

@@ -0,0 +1,25 @@
export default {
name: 'List languages',
key: 'listLanguages',
async run($) {
const languages = {
data: [],
};
const { data } = await $.http.get('/languages');
if (!data?.length) {
return;
}
for (const language of data) {
languages.data.push({
value: language.code,
name: language.name,
});
}
return languages;
},
};

View File

@@ -2,6 +2,8 @@ import defineApp from '../../helpers/define-app.js';
import auth from './auth/index.js';
import addApiKey from './common/add-api-key.js';
import setBaseUrl from './common/set-base-url.js';
import actions from './actions/index.js';
import dynamicData from './dynamic-data/index.js';
export default defineApp({
name: 'LibreTranslate',
@@ -14,4 +16,6 @@ export default defineApp({
primaryColor: 'ffffff',
beforeRequest: [setBaseUrl, addApiKey],
auth,
actions,
dynamicData,
});

View File

@@ -248,6 +248,7 @@ export default defineConfig({
collapsible: true,
collapsed: true,
items: [
{ text: 'Actions', link: '/apps/libretranslate/actions' },
{ text: 'Connection', link: '/apps/libretranslate/connection' },
],
},

View File

@@ -0,0 +1,12 @@
---
favicon: /favicons/libretranslate.svg
items:
- name: Translate text
desc: Translate a text.
---
<script setup>
import CustomListing from '../../components/CustomListing.vue'
</script>
<CustomListing />

View File

@@ -25,6 +25,7 @@ The following integrations are currently supported by Automatisch.
- [HTTP Request](/apps/http-request/actions)
- [HubSpot](/apps/hubspot/actions)
- [Invoice Ninja](/apps/invoice-ninja/triggers)
- [LibreTranslate](/apps/libretranslate/actions)
- [Mattermost](/apps/mattermost/actions)
- [Miro](/apps/miro/actions)
- [Notion](/apps/notion/triggers)