1.2.1 • Published 3 months ago

openai-translation-updater v1.2.1

Weekly downloads
-
License
MIT
Repository
github
Last release
3 months ago

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

ParameterDescription
openAiApiKeyYour OpenAI API key.
defaultLanguageThe default language of your project (e.g., 'en').
otherLanguagesAn array of other languages you want translations for.

Update Translation Files On Commit

ParameterDescription
openAiApiKeyYour OpenAI API key.
defaultLanguageThe default language of your project (e.g., 'en').
otherLanguagesAn 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.

1.2.0

3 months ago

1.2.1

3 months ago

1.1.0

7 months ago

1.0.13

7 months ago

1.0.12

7 months ago

1.0.11

7 months ago

1.0.10

7 months ago

1.0.9

7 months ago

1.0.8

7 months ago

1.0.7

7 months ago

1.0.6

7 months ago

1.0.5

7 months ago

1.0.4

7 months ago

1.0.3

7 months ago

1.0.2

7 months ago

1.0.1

7 months ago

1.0.0

7 months ago