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

openai-translation-updater

v1.2.1

Published

Automatically update translation files on commit using OpenAI.

Downloads

37

Readme

Translation Hook Assistant

An npm package that automates the process of updating translation files on every git commit using OpenAI.

Overview

When working on projects that support multiple languages, keeping track of updated translations can be a challenge. The Translation Hook Assistant helps you automate this process by leveraging the power of OpenAI's language model, integrating directly into your Git workflow. Every time you make a commit, the updateTranslationFileOnCommit function ensures that your translation files are up-to-date, making internationalization seamless and efficient.

Enhancing Translations with Context

To achieve more accurate and contextually appropriate translations from OpenAI, you can optionally include appContext and context keys in your translation files. The appContext key can provide general information or context about the application, while the context key can provide context about a specific section or key within the translation file. This additional context can help OpenAI better understand the intended meaning and usage, leading to improved translation quality.

{
  "appContext": "A finance management app",
  "screen": {
    "dashboard": {
      "context": "Main dashboard displaying financial overview",
      "balance": "Balance",
      ...
    },
    ...
  },
  ...
}

Installation

npm install translation-hook-assistant

Prerequisites

  1. Obtain an OpenAI API key. If you don’t have one, sign up here.

  2. Set up a default translation language and any number of other languages you're targeting for your project. Make sure to have these files already created before setting up the updateTranslationFileOnCommit function.


Usage

Update Translation Files

  1. Set up the function to manually update your translation files.
import { updateTranslationFiles } from 'translation-hook-assistant';

updateTranslationFiles({
  openAiApiKey: 'YOUR_OPENAI_API_KEY',
  defaultLanguage: 'en',
  otherLanguages: ['es', 'fr', 'de'],
});
  1. Run the script whenever you need to update your translation files manually.
npm run updateTranslationFiles

Update Translation Files On Commit

  1. Set up the function in a pre-commit script, ensuring you pass the required parameters.
import { updateTranslationFilesOnCommit } from 'translation-hook-assistant';

updateTranslationFilesOnCommit({
  openAiApiKey: 'YOUR_OPENAI_API_KEY',
  defaultLanguage: 'en',
  otherLanguages: ['es', 'fr', 'de'],
});
  1. Create a script that runs the pre-commit script.
{
  "scripts": {
    "updateTranslationOnCommit": "ts-node path/to/pre-commit/script.ts"
  }
}

You can use a package like husky to easily set up commit hooks.

  1. Add the script to your pre-commit hook.
npm run updateTranslationOnCommit
  1. Whenever you make changes to your translation files and commit them, the updateTranslationFilesOnCommit function will automatically detect translation changes or new keys created and update translations for other languages as needed.

Configuration

Update Translation Files

| Parameter | Description | | ----------------- | ------------------------------------------------------ | | openAiApiKey | Your OpenAI API key. | | defaultLanguage | The default language of your project (e.g., 'en'). | | otherLanguages | An array of other languages you want translations for. |

Update Translation Files On Commit

| Parameter | Description | | ----------------- | ------------------------------------------------------ | | openAiApiKey | Your OpenAI API key. | | defaultLanguage | The default language of your project (e.g., 'en'). | | otherLanguages | An array of other languages you want translations for. |

Limitations

  1. Make sure your OpenAI API key remains confidential. Never hard-code it directly in your scripts.

Contributing

Contributions, issues, and feature requests are welcome. For major changes, please open an issue first to discuss what you'd like to change.

License

MIT


By leveraging the power of OpenAI and Git hooks, the Translation Hook Assistant ensures your project's translations remain consistent and updated, helping you cater to a global audience effortlessly.