DEV Community

Discussion on: How to use Laravel translations in JS (vue) files?

Collapse
 
anejjar profile image
anejjar Elhoucine

Hello bro,
i'm trying to use your solution but i got some errors like
error
this error comes from this block of code
if (translationNotFound) {
translation = window._translations[window._locale]['json'][key]
? window._translations[window._locale]['json'][key]
: key
}

Collapse
 
abalest14 profile image
abalest14

i have the same error how did you solved?
thanks

Collapse
 
anejjar profile image
anejjar Elhoucine • Edited

you should just check if window._translations is set or not
dev-to-uploads.s3.amazonaws.com/i/...

Thread Thread
 
abalest14 profile image
abalest14

thanks this fixed the console error. Another problem i get window._translations undefined and con't understand what i make wrong is like is not passing window._translations from blade to JS. You have some advise?

Thread Thread
 
anejjar profile image
anejjar Elhoucine

sceenshot
did you put this in app.blade.php, but sometimes the {!! cache('translations') !!} is not returning any data so the window._translations is null

Thread Thread
 
r4nd3l profile image
Matt Miller

Do you have any updates so far? I've struggling with that particular issue and it's occur totally random. I would very appreciate if so!

Thread Thread
 
anejjar profile image
anejjar Elhoucine

i used same package but i found a lot of issus and i have updated the code many times to work for me. and i dont know how to explain my method to you unless i see your code and the error your are having