Download the PHP package appointer/laravel-vue-i18n-bridge without Composer
On this page you can find all versions of the php package appointer/laravel-vue-i18n-bridge. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download appointer/laravel-vue-i18n-bridge
More information about appointer/laravel-vue-i18n-bridge
Files in appointer/laravel-vue-i18n-bridge
Package laravel-vue-i18n-bridge
Short Description Exposes laravel translations through api routes.
License MIT
Informations about the package laravel-vue-i18n-bridge
Laravel vue-i18n Bridge
Deprecation notice
THIS PACKAGE IS NO LONGER MAINTAINED SINCE THE DYNAMIC LOCALE FEATURE OF VUE-I18N IS DROPPED IN VERSION 6.x. IF THERE WILL BE ANYTHING LIKE THIS COMMING BACK TO VUE-I18N, WE MIGHT CONSIDER PICKING UP MAINTENANCE FOR THIS PACKAGE AGAIN.
This bridge gives you full freedom of translating your Vue (especially SPA) frontend with Laravels built-in translation techniques, without sacrificing frontend performance or general user experience. It ensures that only the client requested language has to be downloaded by the client. You are no longer forced to either maintain a second place for translation in javascript, or pregenerate a javascript file containing all your translated strings of all locales.
This package is designed to work in direct conjunction with vue-i18n and especially its dynamic locale feature. However, it should be possible to make it work with other vue plugins or even other javascript frameworks with minimal javascript effort.
Other approaches and inspiration
Generating a javascript dictionary with your translatable strings may be totally fine for some use cases. If this is for you, you should totally check out Martin Lindhe's exceptional laravel-vue-i18n-generator.
Credits to him and his package for inspiration.
Installation
Navigate to your project and run the composer command:
The next step is to register the service provider:
Finally, you have to register the routes of this package:
(Optional) If you want to, you can publish the config. This gives you full control over white- and blacklists amongst other things. Use the following artisan command:
NOTE: White- and blacklisting is also possible using the VueTranslation::whitelist()
and VueTranslation::blacklist()
methods respectively.
Implementing the javascript
No worries, its a piece of cake. We are using axios
as an example HTTP client. If you got a stock laravel frontend,
you probably got it installed already. You just have to replace your current locale population with the following implementation:
Pitfalls
- Vendor translations are supported and loaded automatically. Though vue-i18n does not support namespacing (
{namespace}::{key}
) like laravel does, the vendor namespaces are part of the translation key ({namespace}.{key}
). - White- and blacklisting is currently only possible using the root group (the translation file like
auth.php
=>auth
) or namespace (namespace::
=>namespace
) of a translation.
Testing
Tests can be executed using the command:
Contibuting
Every help is very welcome. Do you got an issue, or having a great idea for extending this project? Feel free to open a pull request or submit an issue.
If you file a bug report, your issue should contain a title and a clear description of the issue. You should also include as much relevant information as possible and a code sample that demonstrates the issue. The goal of a bug report is to make it easy for yourself - and others - to replicate the bug and develop a fix.
Please use the issue tracker to report issues.
License
This library is open-sourced software licensed under the MIT license.