dcodegroup / vite-plugin-laravel-translations

Vite Plugin to convert Laravel Translations into a global variable for use within front-end frameworks.
5 stars 4 forks source link

Add option to save translations to a file somewhere? #20

Open chessandrock opened 3 months ago

chessandrock commented 3 months ago

Here is my use case:

I do all my translations using Laravel to avoid duplication of work, but make use of these in a React frontend. When I post stuff to production, I store the content of window.LARAVEL_TRANSLATIONS in a file (let's say "resources/js/translations.js") and have a condition that, if I am running in prod, I load messages from the translations.js file because once my frontend is built I'm no longer relying on vite; otherwise, I'm loading window.LARAVEL_TRANSLATIONS.

Today I forgot that step, and my customer wasn't happy at all, but that's another story.

Is it possible to add this option? I could try adding such a feature (although I don't know much about TypeScript), but wanted to discuss with you all. I've searched for a solution, but came empty handed on that.

adesege commented 1 month ago

Hey @chessandrock, I built a package that exports the translations to a separate file https://www.npmjs.com/package/vite-plugin-laravel-i18next. It handles pluralization, interpolation, nested translations etc. You can also use a http backend to fetch the translations for use in i18next.

Give it a try and let me know if you have questions.