Skip to content

How to generate multiple localized bundles using Vite and React? #15999

Closed Answered by afarber
afarber asked this question in Q&A
Discussion options

You must be logged in to vote

Ok, solved my problem by utilizing the generateBundle hook:

Here my custom vite-plugin-react-localize.js file:

"use strict";

import fs from "fs";
import path from "path";

const localizedStrings = {
  en: {
    __YES__: "Yes",
    __NO__: "No",
    __CANCEL__: "Cancel",
  },
  de: {
    __YES__: "Ja",
    __NO__: "Nein",
    __CANCEL__: "Abbrechen",
  },
  fr: {
    __YES__: "Oui",
    __NO__: "Non",
    __CANCEL__: "Annuler",
  },
};

export default function localize() {
  return {
    name: "localize-plugin",
    generateBundle(outputOptions, bundle) {
      for (const [fileName, bundleValue] of Object.entries(bundle)) {
        if (!fileName.endsWith("index.js")) {
          continue…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by afarber
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant