My vue component like this :
<template>
<ul class="nav nav-tabs nav-tabs-bg">
<li role="presentation" v-for="item in tabs">
1. failed -> {{ item.name }} 2.success -> {{trans('purchase.payment.tab')}}
</li>
</ul>
</template>
<script>
export default {
data() {
return {
tabs: [
{name: "trans('purchase.payment.tab')"}
]
}
}
}
</script>
My lang in laravel(resources/lang/en/purchase.php) like this :
<?php
return [
'payment' => [
'tab' => 'Payment Status',
],
...
];
If the component vue executed, the result like this :
- failed -> trans('purchase.payment.tab') 2.success -> Payment Status
So, if trans used in data, it does not work
How can I solve this problem?
I use vue-i18n for that. That way you should make its own dictionary. I made a
i18n/en.js
file;and a
i18n/hu.js
with the same variables in Hungarian. Then I made ai18n/map.js
file:and finally, set it in
vue.js
, check myapp.js
file part:Its a very elegant way.
and how I use in component? simple:
Is not possible to use a PHP helper inside JavaScript. But, you can create an object of translations.
In your
AppServiceProvider
(you can create a new one if you want):In your HTML (I suggest header) you can just call:
And to access using in JS, you can just do this, for example: