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.
apiKeystringfolderNamestringlocaleDir that contains the i18n JSON files of your input language. The plugin will monitor this folder for changes.langLanguageslocaleDirType: string
Description: The directory path relative to the project root where the locale files are stored.
contextstring@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
@aexol/dynamite is a React i18n library with build-time string extraction and SSR/RSC support. Unlike traditional i18n solutions, Dynamite extracts translation strings directly from your source code at build time.
npm install @aexol/dynamite
npx dynamite init
This creates a .dynamite.json config file:
{
"localesDir": "./locales",
"defaultLocale": "en",
"sourceLocale": "en",
"inputLanguage": "ENUS",
"targetLocales": ["pl", "de", "fr"],
"srcDirs": ["./src"],
"include": ["**/*.tsx", "**/*.ts"],
"exclude": ["node_modules/**"]
}
t() Calls'use client';
import { useDynamite } from '@aexol/dynamite';
const Page = () => {
const { t } = useDynamite();
return (
<div>
{t('Hello world')} {t('This is dynamite')}
</div>
);
};
npx dynamite extract
This scans your source files and generates locales/en.json:
{
"Hello world": "Hello world",
"This is dynamite": "This is dynamite"
}
npx dynamite translate
This uses the dev-translate API to generate translations for all target locales:
locales/pl.jsonlocales/de.jsonlocales/fr.json'use client';
import { useDynamite } from '@aexol/dynamite';
export function MyComponent() {
const { t, locale } = useDynamite();
return <h1>{t('Welcome to our app')}</h1>;
}
import { getDynamite } from '@aexol/dynamite/server';
export default async function Page({ params }: { params: { locale: string } }) {
const { t } = await getDynamite(params.locale, {
localesDir: './locales',
defaultLocale: 'en',
});
return <h1>{t('Welcome to our app')}</h1>;
}
import { DynamiteProvider } from '@aexol/dynamite';
import { loadTranslations } from '@aexol/dynamite/server';
export default function RootLayout({ children, params }: { children: React.ReactNode; params: { locale: string } }) {
const translations = loadTranslations(params.locale, {
localesDir: './locales',
defaultLocale: 'en',
});
return (
<html lang={params.locale}>
<body>
<DynamiteProvider locale={params.locale} translations={translations}>
{children}
</DynamiteProvider>
</body>
</html>
);
}
| Command | Description |
|---|---|
dynamite init |
Create .dynamite.json configuration file |
dynamite extract |
Extract t() strings from source files |
dynamite translate |
Translate extracted strings to target languages |
t("...") function callsgetDynamite() helper for React Server ComponentsThis project is licensed under the MIT License.
Run
$ npm run build
$ cd packages/testground
$ npm run start