dinhdjj / laravel-js-localization
Give ability to uses laravel's `trans` & `trans_choice` function in js
Requires
- php: ^8.1
- friendsofphp/php-cs-fixer: ^3.8
- illuminate/contracts: ^9.0
- spatie/laravel-package-tools: ^1.9.2
Requires (Dev)
- nunomaduro/collision: ^6.0
- nunomaduro/larastan: ^2.0.1
- orchestra/testbench: ^7.0
- pestphp/pest: ^1.21
- pestphp/pest-plugin-laravel: ^1.1
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- phpunit/phpunit: ^9.5
- spatie/laravel-ray: ^1.26
This package is auto-updated.
Last update: 2023-10-11 12:02:54 UTC
README
This is where your description should go. Limit it to a paragraph or two. Consider adding a small example.
Installation
You can install the package via composer:
composer require dinhdjj/laravel-js-localization
Usage
This package minify step to usage. You just add directive @jslocalization
to blade layout.
<!-- resources/view/app.blade.com --> <!DOCTYPE html> <html> <head> @jslocalization <!-- other js --> </head> <body class="font-sans antialiased"> <!-- --> </body> </html>
And you must remember that when you update this package or update lang files. You should run below command to make it effect
php artisan view:cache
If you use typescript below lines will help you
type Trans = (key: string, replaces?: Record<string,string>, local?: string|null) => string; type TransChoice = (key: string, number: number, replaces?: Record<string,string>, local?: string|null) => string; declare global { interface Window { __: Trans; trans: Trans; transChoice: TransChoice; } }
Finally usage in real life
window.trans('hello :name', {name: 'dinhdjj'}); window.__('hello :name', {name: 'dinhdjj'}); window.transChoice('hello :name|xin chao :name', 1,{name: 'dinhdjj'});
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.