npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

lost-in-translation

v1.0.1

Published

This package allows you to translate a given string through multiple translations to receive a somewhat interesting result.

Downloads

3

Readme

LostInTranslation.js

You know that thing where people were translating lyrics and such through multiple translations and then singing the lyrics back in English? Yeah that's what I was thinking of when I wrote this. A Node.js module that allows you to translate a string multiple times through multiple languages. I've had some fun with it, and maybe you will to.

greyscale

Installation

To install:

npm install lost-in-translation 

Usage

Setup:

You must pass two objects to the constructor. The first is your translation parameters, and the second contains authentication information for the Google Cloud Translation API.

const Translator = require('lost-in-translation');

var translator = new Translator({
    languageSteps: 3,
    targetLanguage: 'en',
    startingLanguage: 'en',
    inputString: 'This is my totally rad input string'
}, {
    projectId: 'your projectId',
    keyFilename: 'path to keyfile'
})

The first object passed to the constructor should have the following structure:

//All parameters are required.
{
    //languageSteps can be either a number or an array of languages e.g. ['az','eu','be','bn']
    languageSteps: 3,
    //the final language returned
    targetLanguage: 'en',
    //the language we are starting with
    startingLanguage: 'en',
    //the string to be translated
    inputString: 'This is my totally rad input string'
}

getTranslation:

translator.getTranslation().then((data)=>{
    console.log("The text became: " + data[data.length - 1].translation);
})

// Logged: The text became: This is the absolute line input line.

The getTranslation method returns a promise that resolves to an array of objects, each representing a translation step. For example, if you specify 3 languages to translate through then the returned object will have 5 elements. The element at data[0] is the first step, so it is the input and input language. And the last item in the array is the completed translation and output language.

The objects in the array have the followin signature:

{
    code: 'This will be the 2 letter language code',
    translation: 'This will be the inputString translated into the language represented in the code parameter'
}

setTranslationParams

This function lets you provide new translation parameters to the translator.

translator.setTranslationParams({
    languageSteps: ['az','eu','be','bn'],
    targetLanguage: 'en',
    startingLanguage: 'en',
    inputString: 'This is a new string that is totally more awesome than the last one.'
})
.then(()=>{
    return translator.getTranslation();
})
.then((data)=>{
    console.log("The text became: " + data[data.length - 1].translation);
})

//Logged: The text became: Secondly, more beautiful than circuits is not completely new.

setLanguageList

LostInTranslation.js includes an internal array of supported language codes. This is done so that you don't have to rely on language detection at the expense of perhaps not being up to date at all times. If you find yourself needing to alter the list of language codes, you may replace the existing array using setLanguageList.

var list = ['ps', 'fa', 'pl'];
translator.setLanguageList(list);

//Now the internal list will only contain the languages specified: 'ps', 'fa', 'pl'