dinhdjj/laravel-js-localization

This package is abandoned and no longer maintained. No replacement package was suggested.

Give ability to uses laravel's `trans` & `trans_choice` function in js

v1.0.2 2022-05-09 08:29 UTC

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

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.