mach3builders/vuetrans

Package to use trans like helper in vue

v0.0.4 2019-03-04 15:55 UTC

This package is auto-updated.

Last update: 2024-05-05 03:38:54 UTC


README

You can install the package via composer:

composer require mach3builders/vuetrans

After requiring the package, publish the assets.

php artisan vendor:publish --tag=assets

After Publishing the assets add the following script tag to your head

<script src="{{ route('mach3builders.vuetrans') }}"></script>

After adding the script tag, import the vue plugin inside your app.js

import Trans from './vendor/vuetrans/trans'
window.vue = require('Vue')
Vue.use(Trans)

Usage

When you are done with the installation steps youll now be able to use the following helper. Inside your vue templates

{{ trans('auth.failed') }}

If you have a translation with an attribute, you can send this as a param. Note since it is in js youll need to send an object.

{{ trans('auth.throttle', {seconds: 3}) }}

Props return by your vue component can also be used with the translation. like computed, watched and return data. If the name of the property matches the name of the translation attribute than soly passing it wil sufy.

in example

User.php
'welcome' => 'Welcome :name',
{{ trans('user.welcome', {name}) }} OR
{{ trans('user.welcome', {name: user.name}) }}

For developing porpuses make sure your cache driver is on array mode.

CACHE_DRIVER=array

Testing

composer test

Credits

License

The MIT License (MIT). Please see License File for more information.

Laravel Package Boilerplate

This package was generated using the Laravel Package Boilerplate.