Socket
Book a DemoInstallSign in
Socket

@coscom/vite-plugin-lang

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@coscom/vite-plugin-lang

Vite plugin to fetch and translate language files using external API

1.0.0
latest
npmnpm
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

vite-plugin-lang

Automatically fetch and generate translation files for multiple languages during Vite build.

Features

  • 📤 Reads a base language file (e.g. de.json)
  • 🌍 Translates it to multiple languages via your API
  • 💾 Outputs language files to the specified directory
  • ⚙️ Fully configurable

Installation

npm install @coscom/vite-plugin-lang --save-dev

Usage

In your vite.config.js or vite.config.ts:

import { defineConfig } from 'vite'
import fetchLangPlugin from 'vite-plugin-lang'

export default defineConfig({
  plugins: [
    fetchLangPlugin({
      inputLangPath: './public/translations/de.json',   // Source language file (e.g., German)
      outputLanguages: ['en', 'fr', 'it'],               // Languages to generate
      outputDir: './public/translations',                // Output folder for translated files
      apiUrl: 'http://localhost:5000/api/v1/strings',    // Your translation API
      indent: 2                                          // (Optional) JSON indentation
    })
  ]
})

How It Works

During the Vite build, this plugin:

  • Reads the base language file (de.json)
  • Sends its contents to your translation API for each target language (en, fr, it, ...)
  • Saves translated versions (e.g. en.json, fr.json, ...) to the output directory

API Requirements

Your API should accept a POST request like:

POST /api/v1/strings?targetLang=fr
Content-Type: application/json

{
  "KEY1": "Wert 1",
  "KEY2": "Wert 2"
}

And return:

{
  "data": {
    "KEY1": "Value 1",
    "KEY2": "Value 2"
  }
}

Testing

This plugin supports tests using Vitest.

npm test

Example File Structure

public/
├── translations/
│   └── de.json
└── translations/
    ├── en.json
    ├── fr.json
    └── it.json

Options

OptionTypeDefaultDescription
inputLangPathstring'./translations/de.json'Path to the source language file
outputLanguagesstring[]['en']List of target languages
outputDirstring'./public/translations'Folder where translated files are saved
apiUrlstring''Endpoint of your translation API
indentnumber2JSON indent spacing for output files

License

MIT

Credits

Built with ❤️ to simplify multilingual Vite projects.

Keywords

vite

FAQs

Package last updated on 08 Aug 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.