Laravel-JS-Localization icon indicating copy to clipboard operation
Laravel-JS-Localization copied to clipboard

Vite

Open EmilMoe opened this issue 1 year ago • 4 comments

I am struggling to use this after I switched to Vite. Maybe someone solved it?

EmilMoe avatar Aug 02 '23 17:08 EmilMoe

@EmilMoe Having the same issue. Have you found something out?

wldrve avatar Nov 02 '23 10:11 wldrve

@EmilMoe Having the same issue. Have you found something out?

I got it to work, however that project has since been archived. I can see I used these packages, that might help you:

In the current project I'm working on we took a different approach, to avoid these dependencies, by injecting necessary translations as a property (call it i18n or translations).

Route::get('/page', function() {
  return Inertia::render('Page', [
    'i18n' => [
      'title' => __('page.title'),
    ],
  ]);
});

Possibly there are optimisation to that approach.

EmilMoe avatar Nov 02 '23 10:11 EmilMoe

Export to json and import that. Then pass it in as options. This is how I do it in react

import messages from '@/i18n' //json file
import Lang from 'lang.js'
const lang = new Lang({messages, fallback: 'en'}) //this now has the translations loaded

sinnbeck avatar Nov 28 '23 09:11 sinnbeck

I do like this

php artisan lang:js resources/js/vue-translations.js --json
echo "$(echo -n 'export default '; cat resources/js/vue-translations.js)" > resources/js/vue-translations.js

After i can import my json translations correctly import translations from './vue-translations.js';

cryptoprof avatar Jan 11 '24 11:01 cryptoprof