Laravel-JS-Localization
Laravel-JS-Localization copied to clipboard
Vite
I am struggling to use this after I switched to Vite. Maybe someone solved it?
@EmilMoe Having the same issue. Have you found something out?
@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.
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
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';