alienfast / vite-plugin-i18next-loader

Vite plugin to client bundle i18next locales composited from one to many json/yaml files from one to many libraries. Zero config HMR support included.
Other
42 stars 3 forks source link

How to make it work with a different locale structure ? #19

Closed JPetitpierre closed 4 months ago

JPetitpierre commented 4 months ago

How can I configure vite.config.ts and i18next.init() to handle a structure like this one?

└── app
    └── src
    │  └── index.js
    └── locales
       ├── contacts
       │   ├── fr-ca.yml
       │   └── en-us.yml
       └── products
           ├── fr-ca.yml
           └── en-us.yml

I tried i18nextLoader({paths: ['./locales/contacts', './locales/products'],}) but resources get undefined...thanks!

rosskevin commented 4 months ago

You have an entirely different scheme that what the default behavior is expecting. We expect language code as a top level dir, and locales underneath. I'm not against the structure you are using, but we have never used something like that.

https://github.com/alienfast/vite-plugin-i18next-loader/blob/main/src/index.ts#L84

      // all subdirectories match language codes
      const langs = enumerateLangs(nextLocaleDir)

You would have to:

  1. make the searching pluggable
  2. write a searcher/resolver plugin with the behavior you want
  3. and add an option to use the new searcher instead of the current default behavior
  4. add tests to validate behavior