translate-core
v1.0.0
Published
A powerful language translation package that supports multiple languages using Google's Translator API. Easily translate text between various languages with this simple and efficient package.
Downloads
13
Maintainers
Readme
Translate-core
A simple package to translate languages
Installation
> npm install translate-core
> yarn add translate-core
Methords
supportedLanguages
: Returns an array containing all the languages supported by applicationgetTranslate
: Translates text from the application's current language to a specified target language
Parameters
langTo (string)
: The target language code to translate the text into. Examples include "en" (English), "es" (Spanish), "fr" (French), and so on. Ensure the language code is supported by your translation library.text (string)
: The text to be translated.
Returns
An object with two properties:
langTo (string):
The same target language code passed as input.translatedText (string):
The translated text in the specified target language.
Example Usage
You need to intialize the Translate
Class before acessing the methods inside it.
const { Translate } = require('translate-core');
(async () => {
const { getTranslate } = new Translate()
const text = await getTranslate('en', 'こんにちは!今日はどんなことをお話ししたいですか?')
console.log(text)
/*
Output:
{
langTo: 'en',
translatedText: 'Hello! What would you like to talk about today?'
}
*/
})()