Skip to content
This repository was archived by the owner on Oct 9, 2023. It is now read-only.

unnoq/laravel-js-localization

Repository files navigation

Give ability to uses laravel's trans function in js

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.

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •