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

json-ai-translation

v0.0.9

Published

Automatically translate JSON files of strings into multiple locales simultaneously using AI.

Downloads

565

Readme

JSON AI Translation

This package makes it simple to keep a project's translation files up to date using AI. It is ideal for the use case where you do all your language edits in a single locale file, e.g. en, then want OpenAI to automatically translate just the changed or new strings into all the other locales. You can then either check these in, or open a pull request to send these suggestions to human translaters.

Note that for this tool to detect which strings have changed in your main locale file, you should run this before committing that file to git.

Getting Started

Install the package from NPM

npm install -g json-ai-translation

JSON AI Translation

CLI Usage

The package assumes that you keep all your files to be translated in a single folder, with each non-nested sub-folder being named after the locale it represents. E.g.

public/locales/en/common.json
public/locales/de/common.json
public/locales/es/common.json
public/locales/ko/common.json

You must tell the script which locale is the authoritive one from which all other locales are translated. The example below assumes that your OpenAI API key is in the OPENAI_API_KEY environment variable.

json-ai-translation --dir public/locales --main en --openaitoken \"$OPENAI_API_KEY\"

Alternatively, to use Anthropic, assuming your API key is in the ANTHROPIC_API_KEY environment variable

json-ai-translation --dir public/locales --main en --anthropicaitoken \"$ANTHROPIC_API_KEY\"

This will cause all other locale files in the public/locales folder to be updated, using OpenAI/Anthropic to translate from the authoritive locale into all the others.

Only values that have changed in the main locale will be updated, so if you have manually edited values in the locale files previously, those will remain unchanged.

Adding a new locale

To add a new locale, simply create a new folder with that locale code, e.g. Portuguese

public/locales/pt

and run the json-ai-translation command again. All the files in the main locale will be created in the new locale, fully translated by AI.

Building to another folder

If you want to the leave the source files unchanged, set the --dest argument to the path to another folder, e.g.

json-ai-translation --dir public/locales --dest build/locales --main en --openaitoken \"$OPENAI_API_KEY\"

Parameters

| Parameter | Description | Type | | | :----------------- | :----------------------------------------------------------------------------------------------------------------------------------- | :------ | :-------- | | --dir | The folder in which the locale files are stored | String | Required | | --main | The primary locale code, e.g. --main en | String | Required | | --openaitoken | Your OpenAI token, required unless an Anthropic token is provided | String | Required? | | --anthropicaitoken | Your AnthropicAI token, required unless an OpenAI token is provided | String | Required? | | --dest | The folder in which the translated locale files written. Defaults to the same as --dir | String | Optional | | --aimodel | Override the default AI model for either OpenAI or Anthropic | String | Optional | | --notranslate | A list of strings that should not be translated. For example, product names. E.g. --notranslate "My Cool App" "My Company Name" | Boolean | Optional | | --quiet | Do not log anything to the console when running | Boolean | Optional | | --force | Force the translation of all strings in the main locale files, even if they have not changed. This will be slower and more expensive | Boolean | Optional |

License

MIT