Download the PHP package apih/laravel-jslang without Composer
On this page you can find all versions of the php package apih/laravel-jslang. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download apih/laravel-jslang
More information about apih/laravel-jslang
Files in apih/laravel-jslang
Package laravel-jslang
Short Description Language localization in JavaScript, for Laravel-based application
License MIT
Homepage https://github.com/apih/laravel-jslang
Informations about the package laravel-jslang
Laravel JS Lang
This package provides the ability to use all language localization messages from your Laravel-based app in browser's JavaScript. It also comes with a simple JavaScript Translator library that has some methods to interact with the messages.
Requirements
- PHP:
^8.0
- Laravel:
^8.0|^9.0|^10.0|^11.0|^12.0
Installation
You can install the package via Composer:
The Apih\JsLang\JsLangServiceProvider
class is auto-discovered and registered by default.
If you want to register it yourself, add the service provider in config/app.php
:
You can publish the config file with:
You can publish the JavaScript Translator library with:
Usage
Testing
To test whether the installation is successful, you can run the following code:
It should output the URL and the JavaScript code for language localization messages.
Message Types
There are three message types:
short
- localization messages defined inPHP
fileslong
- localization messages defined inJSON
filesall
- combination of bothshort
andlong
types
JavaScript Files
By opening the URL generated by getUrl()
, you will get the respective contents based on provided locale and type. By default, the contents are generated on runtime, unless you generate all the files beforehand, using the provided Artisan command.
Artisan Commands
You can generate all JavaScript files with:
By default, crc32
hashing algorithm is used to generate the contents' hash included in the filename. You can change the algorithm by using --hash-algo
option. The following example uses sha256
hashing algorithm and only takes first 12 characters from the generated hash:
Generated files are placed in public/lang
directory, based on the default config. It is recommended to put the directory in .gitignore
file.
You can clear all generated files with:
Bootstrapping for Front-end
In order to use in front-end, several steps have to be taken. First, edit resources/js/app.js
to add the JavaScript translator:
Then, use npm run dev
or npm run prod
to compile resources/js/app.js
.
After that, you need to configure it in your page:
To test it, you can open the page in the browser and run the following code in the console to test it:
Security Vulnerabilities
If you discover any security related issues, please email [email protected] instead of using the issue tracker. Please prefix the subject with Laravel JS Lang:
.
Credits
- Mohd Hafizuddin M Marzuki
- All Contributors
License
The MIT License (MIT). Please see License File for more information.