Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vite #185

Open
EmilMoe opened this issue Aug 2, 2023 · 4 comments
Open

Vite #185

EmilMoe opened this issue Aug 2, 2023 · 4 comments

Comments

@EmilMoe
Copy link
Contributor

EmilMoe commented Aug 2, 2023

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

@wldrve
Copy link

wldrve commented Nov 2, 2023

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

@EmilMoe
Copy link
Contributor Author

EmilMoe commented Nov 2, 2023

@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.

@sinnbeck
Copy link

sinnbeck commented Nov 28, 2023

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

@cryptoprof
Copy link

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';

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants