There is two variants of installing a package. Either install it for a certain project to dev dependencies or install it globally.
Install using yarn:
yarn add i18n-openai -D
Install using npm:
npm i i18n-openai --save-dev
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.
In order to use OpenAI translation, the key must be provided in .env file.
OPENAI_API_KEY=<your_api_key>
If you have installed package in dev dependencies, then run:
npx i18n-openai
i18n-openai
will translate all files for all locales, except mainLocale provided in config.
Use -locales
to specify locales for translation. The separator is ,
:
npx i18n-openai -locales ar,cs,de
npx i18n-openai -locales de
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
npx i18n-openai -h
npx i18n-openai -files firstFile.json,secondFile.json -locales ar,de
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 |
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.
All PRs are welcome :)