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

i18n-openai

v1.1.2

Published

The i18n-openai NPM package simplifies and accelerates the translation of i18n JSON files using the power of OpenAI's language capabilities. With this package, developers can effortlessly bridge the language gap and provide multilingual experiences to use

Downloads

21

Readme

🚀 i18n-openai

npm version PRs Welcome Github Actions License: MIT Coverage

Table of contents

Getting started

Installation

There is two variants of installing a package. Either install it for a certain project to dev dependencies or install it globally.

Installing to dev dependencies:

Install using yarn:

yarn add i18n-openai -D

Install using npm:

npm i i18n-openai --save-dev

Create config file (optional)

You can add your custom config by creating i18n-openai.config.json. If no config file would be provided, default config would be used 👇

module.exports = {
    skipLocales: [], // (optional)
    mainLocale: 'en', // (optional)
    pathToLocalesFolders: 'public/locales', // (optional)
    customPrompt:
    'Return content translated to {0}. Keep all sequences /n. Keep all special characters. Do not return any additional information, return only translated text.', // (optional)
}

If config file is provided, but some of the variables from config are not provided, then default values would be used.

Add OpenaAI API key to .env

In order to use OpenAI translation, the key must be provided in .env file.

OPENAI_API_KEY=<your_api_key>

Translate

If you have installed package in dev dependencies, then run:

npx i18n-openai 

:warning: If no arguments are provided. i18n-openai will translate all files for all locales, except mainLocale provided in config.

Possible arguments

Locales

Use -locales to specify locales for translation. The separator is ,:

npx i18n-openai -locales ar,cs,de
npx i18n-openai -locales de

Files

Use -files to specify files for translation(files are being taken from main locale folder). The separator is ,:

npx i18n-openai -files firstFile.json,secondFile.json
npx i18n-openai -files test.json

To see list of all available arguments in terminal use -h

npx i18n-openai -h

Arguments can be combined (order of arguments does not matter):

npx i18n-openai -files firstFile.json,secondFile.json -locales ar,de

Configuration Options

| property | description | type | | --------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------ | | skipLocales(optional) | Locales which will not be translated(Default: []) | string[] | | mainLocale (optional) | From what locale translation would be. (Default: en) | string | | pathToLocalesFolders (optional) | Relative path to locales folder (Default: public/locales) | string | | customPrompt(optional) | see section custom prompt | string |

Custom prompt

You can specify your custom prompt to use with OpenAI for translation. Custom prompt should contain {0} sequence. Language is being replaced by {0} once request to OpenaAI is being made.

Default custom prompt: Return content translated to {0}. Keep all sequences /n. Keep all special characters. Do not return any additional information, return only translated text.

Contribution

All PRs are welcome :)