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

generaltranslation

v1.2.7

Published

A language toolkit for AI developers

Downloads

1,567

Readme

General Translation

generaltranslation.com

A language toolkit for AI developers.

Full documentation coming soon!

Getting Started

In your terminal:

npm i generaltranslation

In your code, import functions directly

import { getLanguageName } from 'generaltranslation'

or, to initialize a GT API client:

import GT from 'generaltranslation'

const gt = new GT()

Convert between languages and ISO-639 codes

getLanguageName(codes)

Returns a language name from a two or three-letter ISO-639 language code, or an array of codes.

const language = getLanguageName('en');
console.log(language) // 'English'

const languages = getLanguageName(['fr', 'es'])
console.log(languages) // ['French', 'Spanish']

getLanguageCode(languages)

Returns an ISO-639 code from a language name or an array of language names.

const code = getLanguageCode('English');
console.log(language) // 'en'

const codes = getLanguageCodes(['French', 'Spanish'])
console.log(codes) // ['fr', 'es']

Get a user's language

getUserLanguage()

Returns a user's default browser language. Meant for use in a web browser (i.e. on the client side).

const userLanguage = getUserLanguage();
console.log(userLanguage) // 'en'

Prompt Internationalization API

For this function, you need to sign up for an API key at generaltranslation.com.

There's a small, free allowance to let you test out the API without payment details.

Add the API key to your code like this:

import GT from 'generaltranslation'

const gt = new GT({
    apiKey: process.env.GT_API_KEY // looks like 'gtx-XXX'
});

async translatePrompt(prompt, language)

Translates prompt into the language represented by an ISO-639 language code. Designed for translating prompts into other languages, to internationalize responses from AI models.

Just wrap translatePrompt around your prompt and go.

All of the following are valid:

const translatedPrompt = await gt.translatePrompt('Tell me a story', 'es');
const first = 'Tell me a story ';
const second = 'about a cat'

const translatedPrompt = await gt.translatePrompt([
    first, second
], 'es');

To mark text that shouldn't be translated, wrap it in { text: "", translate: false }. Items marked as translate: false are never sent to our API. For example:

const prompt = 'Tell me a story about ';
const input = 'gatos con espadas'

const translatedPrompt = await gt.translatePrompt([
    prompt, { text: input, translate: false }
], 'es');

For type consistency, you can also make everything in the prompt parameter an object:

const prompt = 'Tell me a story about ';
const input = 'gatos con espadas'

const translatedPrompt = await gt.translatePrompt([
    { text: prompt }, 
    { text: input, translate: false }
], 'es');

This also works:

const translatedPrompt = await gt.translatePrompt({ text: 'Tell me a story' }, 'es');