Translate your JSON i18 folders with:
Features:
This plugin is particularly useful for developers working with projects that have multiple language support and require seamless translation updates during development.
$ npm i @aexol/dev-translate
$ dev-translate translate
Interactive command will ask you for the paths and will create a .dev-translate.json
config file for further use.
{
"apiKey": "YOUR_API_KEY",
"localeDir": "locales",
"inputLanguageFolderName": "en",
"inputLanguage": "ENUS",
"context": "User Interface of a web app used to SEO"
}
Config will also include all the dev-translate available languages.
Then dev-translate CLI will translate all the json files from input Language and create files with same names in language folder.
For example if you have a folder ./locales/
with en
, pl
. de
, fr
, in
and you choose en
as an input language. Dev translate will automatically translate from en
to all other langauges keeping the json file structure.
As translations consume tokens from API you can easily predict translation cost of your locale folder by running:
dev-translate predict
Dev-translate backend includes cache inside it so we don't need to implement local cache here
If you want to clear your cache not to reuse cached translations anymore:
dev-translate clear
Those options are parameters of options param of each plugin.
apiKey
string
folderName
string
localeDir
that contains the i18n JSON files of your input language. The plugin will monitor this folder for changes.lang
Languages
localeDir
string
context
string
@aexol/nextjs-dev-translate-plugin
is a Vite plugin designed to automatically translate i18n JSON files while Vite is in watch mode.
To install the plugin, use either npm or yarn:
npm install @aexol/nextjs-dev-translate-plugin --save-dev
In your Next.js configuration file (next.config.js
or next.config.mjs
), import and configure the plugin with the necessary options.
const { withDevTranslate } = await import('@aexol/nextjs-dev-translate-plugin');
/** @type {import('next').NextConfig} */
const nextConfig = {
//...your config
};
/** @type {import('@aexol/nextjs-dev-translate-plugin').withDevTranslate} */
export default withDevTranslate(nextConfig, {
apiKey: 'your-api-key',
folderName: 'pl',
lang: 'PL',
localeDir: './src/app/i18n/locales',
});
If your project has the following structure:
my-project/
│
├── src/
│ └── locales/
│ ├── pl
│ │ ├── home.json
│ │ └── auth.json
│ ├── en
│ │ ├── home.json
│ │ └── auth.json
│ └── de
│ ├── home.json
│ └── auth.json
│
└── nextjs.config.mjs
You would configure the plugin as follows:
const { withDevTranslate } = await import('@aexol/nextjs-dev-translate-plugin');
/** @type {import('next').NextConfig} */
const nextConfig = {
//...your config
};
/** @type {import('@aexol/nextjs-dev-translate-plugin').withDevTranslate} */
export default withDevTranslate(nextConfig, {
apiKey: 'your-api-key',
folderName: 'pl',
lang: 'PL',
localeDir: './src/app/i18n/locales',
});
This will enable the plugin to automatically watch and translate the JSON files from the src/locales/pl
folder to en
and de
folders
@aexol/vite-plugin-dev-translate
is a Vite plugin designed to automatically translate i18n JSON files while Vite is in watch mode.
To install the plugin, you can use npm or yarn:
npm install @aexol/vite-plugin-dev-translate --save-dev
In your vite.config.js
or vite.config.ts
file, import the plugin and configure it with the required options.
import { defineConfig } from 'vite';
import devTranslatePlugin from '@aexol/vite-plugin-dev-translate';
export default defineConfig({
plugins: [
devTranslatePlugin({
apiKey: 'your-api-key-here',
folderName: 'locales',
lang: 'en-US',
localeDir: 'src/locales'
})
]
});
If your project has the following structure:
my-project/
│
├── src/
│ └── locales/
│ ├── en
│ │ ├── home.json
│ │ └── auth.json
│ ├── fr
│ │ ├── home.json
│ │ └── auth.json
│ └── es
│ ├── home.json
│ └── auth.json
│
└── vite.config.ts
You would configure the plugin as follows:
import { defineConfig } from 'vite';
import devTranslatePlugin from '@aexol/vite-plugin-dev-translate';
export default defineConfig({
plugins: [
devTranslatePlugin({
apiKey: 'your-api-key-here',
folderName: 'en',
lang: 'ENUS',
localeDir: 'src/locales'
})
]
});
This will enable the plugin to automatically watch and translate the JSON files from the src/locales/en
folder to fr
and es
folders
This project is licensed under the MIT License.
Run
$ npm run build
$ cd packages/testground
$ npm run start