Skip to content
This repository has been archived by the owner on Jan 2, 2024. It is now read-only.

devjiwonchoi/papago-sdk-js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

50 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SDK for Papago Translation API, supports multiple languages.

Prerequisites

This SDK requires Papago API Client ID and Secret.

For further guidance, see Client ID and Secret.

Note

Installation

pnpm add papago-sdk

Usage

Papago

Set up a client with your Papago Translation credentials.

// CJS
const { Papago } = require('papago-sdk')

// ESM
import { Papago } from 'papago-sdk'

const papago = new Papago({
  id: 'PAPAGO_CLIENT_ID',
  secret: 'PAPAGO_CLIENT_SECRET',
})

translate({ type: 'text' })

Translate the given text from one language to another.

const textTranslation = await papago.translate({
  from: 'en',
  to: 'ko',
  type: 'text',
  input: 'Hello, World!'
});

// Output:
{
  message: {
    result: {
      srcLangType: 'en',
      tarLangType: 'ko',
      translatedText: '안녕, 세상!'
    }
  }
}

textOnly: Boolean

Returns translated text only as translatedText.

const textOnly = await papago.translate({
  from: 'en',
  to: 'ko',
  type: 'text',
  text: 'Hello, World!',
  textOnly: true,
})

// Output:
{
  translatedText: '안녕, 세상!'
}

translate({ type: 'html' })

Translate an HTML string from one language to another as translatedHtml.

Note that the HTML structure will be preserved.

const htmlTranslation = await papago.translate({
  from: 'en',
  to: 'ko',
  type: 'html',
  input: '<div>Hello, world!</div>',
})

// Output:
{
  translatedHtml: '<div>안녕, 세상!</div>'
}

Good to know: For translate, when from is set to 'auto', the source language is detected automatically.

detect

Detect lang code of the given text.

const detection = await papago.detect({
  query: 'Hello World!',
})

// Output:
{
  langCode: 'en'
}

Language Support

Order by Accuracy & Cross-Language Support

  • 🇰🇷 한국어
  • 🇺🇸 English
  • 🇯🇵 日本語
  • 🇨🇳 简体中文
  • 🇹🇼 繁體中文
  • 🇻🇳 Tiếng Việt
  • 🇹🇭 ภาษาไทย
  • 🇮🇩 Indonésia
  • 🇫🇷 français
  • 🇪🇸 español
  • 🇷🇺 русский
  • 🇩🇪 Deutsch
  • 🇮🇹 italiàno

For more information, see Language Support.

Disclaimer

papago-sdk is an open source published by an individual.

The activities and announcements of papago-sdk are not affiliated with Naver Cloud, corp.