Socket
Socket
Sign inDemoInstall

yandex-translate-v2-api

Package Overview
Dependencies
6
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    yandex-translate-v2-api

Node package to make work with yandex API easier


Version published
Weekly downloads
1
Maintainers
1
Install size
8.83 MB
Created
Weekly downloads
 

Readme

Source

yandex-translate-v2-api

You have to ways to use this module

  • With IAM_TOKEN buy running const t = Translator.Imt(<IAM_TOKEN>, <FOLDER_ID>, <targetLanguage>)
  • With API_KEY const t = Translator.Api(<API_KEY>, <FOLDER_ID>, <targetLanguage>)

targetLanguage is English by default. You can find the list of available languages and their codes here https://cloud.yandex.com/en-ru/docs/translate/concepts/supported-languages

Usage example

import { Translator } from "yandex-translate-v2-api";

const t = Translator.Api(API_KEY, FOLDER_ID, "ja"); // Language is optional. English by default
await t.createTranslatedFile(obj, path, "js"); // Type is optional "js" by default

Methods

async translate

async translate(texts: string[] | string): Promise<string[]>

The methods takes string array and returns string array with translated values

async detect

async detect(text: string): Promise<string>

The method takes string and returns language it's written in

getStringArrayFromObject

getStringArrayFromObject(
  obj: { [key: string]: string | object }
): string[]

The method takes JSON formatted object with strings to translate as values and returns all strings as 1 dimensional array

async translateStabilized

async translateStabilized(texts: string[] | string): Promise<string[]>

The same method as translate but for arrays with the total strings length more than 10_000 characters

async getTranslatedObject

async getTranslatedObject(
  obj: { [key: string]: string | object }
): Promise<{ [key: string]: string | object }>

The method takes JSON formatted object with strings to translate as values and returns object with translated values

async createTranslatedFile

async createTranslatedFile(
  obj: { [key: string]: string | object }, 
  filePath: string, 
  type: "js" | "json"
): Promise<void>
  • As a first argument method takes JSON formatted object with strings to translate as values.
  • Second argument is a string with a path to save translated file to.
  • (Optional) Third argument is the type of exported object. It can be exported as a plain JSON or with export default as a JS object

Keywords

FAQs

Last updated on 30 Aug 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc