bambamboole / laravel-i18next
A laravel package which provides a HTTP backend for i18next.js
Requires
- php: ^8.1
- bambamboole/laravel-translation-dumper: ^1.0.2
- illuminate/cache: ^9.0|^10.0|^11.0
- illuminate/http: ^9.0|^10.0|^11.0
- illuminate/support: ^9.0|^10.0|^11.0
- illuminate/translation: ^9.0|^10.0|^11.0
Requires (Dev)
- laravel/pint: ^1.8
- phpunit/phpunit: ^10.1
README
If you are using i18next in your frontend and Laravel in your backend, this package is for you.
How does it work?
The package provides the routes to fetch the translations and to save missing translations when using i18next-http-backend.
it supports Laravels JSON and PHP translation files and converts them on the fly to be compatible with i18next.
Installation
You can install the package via composer.
composer require bambamboole/laravel-i18next
Usage
The package is still in its early development and therefor pretty opinionated and not very flexible.
It provides two routes. One is for fetching the translations and the other one is for saving missing translations.
Fetching translations
The route
With Vue.js
To use the translations in your Vue.js components you can use the i18next-vue
package.
npm install -D i18next-vue i18next-http-backend
To configure i18next-vue
you can use the following code snippet:
import I18NextVue from 'i18next-vue'; import HttpBackend from 'i18next-http-backend' i18next.use(HttpBackend).init({ saveMissing: true, lng: 'en', backend: { // This is needed for CSRF protection withCredentials: true, customHeaders: () => { const csrf = document.querySelector<HTMLElement>('meta[name="csrf-token"]') return csrf === null ? {} : {'X-CSRF-TOKEN': csrf.getAttribute('content')} }, }, }); //... app.use(I18NextVue, {i18next})
Testing
composer test
Contributing
Ideas/Roadmap
- Add more tests
- Make the package more flexible
- Support namespaces
- Support i18next multiload
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email manuel@christlieb.eu instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.