0

In the event that you are developing your software using the Laravel framework and need to use the Vue library, you will face some obstacles, including how to access the files translation system provided by Laravel . like how to access trans('home.var')

2 Answers 2

2

Add Language file like this

<messagings v-bind:language="{{ json_encode(trans('messages')) }}"></messagings>

then in vue component print like this

<h4>{{ this.language.messaging }}</h4>
Sign up to request clarification or add additional context in comments.

Comments

0

1: pass trans as prop in blade normally just you need to encoding with json used json_encode() method :
<component :trans="{{json_encode(trans('home'))}}"></component>


2: in vue component page you need to decode json data first and set the translation data in some var :

export default {
props:['trans'],
data () {
  return {
     translation:[],
  };
},
created(){
  this.setTranslation()
},
methods:{
  setTranslation(){
     let decoded_trans = JSON.parse(this.trans);
     this.transaction = decoded_trans;
  }
}


3: Now you can access laravel trans normaly just be careful because vue will not detect if you call last node or first.

<template>
  <div>
    <h2>{{translation.header.login}}</h2> // this line in laravel mean : trans('home.header.login')
  </div>
<template>

Finally I recently started learning vue , so this method may have some flaws, but We all strive to benefit :)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.