Download the PHP package drewneon/lang4js without Composer

On this page you can find all versions of the php package drewneon/lang4js. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package lang4js

Lang4JS

Latest Version on Packagist Total Downloads

Localization, one of the core features of Laravel, separates language strings from views, so as to serve a robust foundation for multilingual projects. However, trans(), trans_choice() or the newly-introduced __(), supported by Blade template engine of different version of Laravel, are not usable in Javascript. This issue is definitely inevitable for developing any serious multilingual projects and just what Lang4JS is addressing. When Lang4JS is installed as a package in your Laravel application, you are able to use trans(), trans_choice() and __() in Javascript with the same syntax just as in Blade templates, the language strings defined in files under resources/lang folder are retrieved correspondently and displayed right to the users. Lang4JS is very easy to use and lightweight, merely a 3Kb controller file and a 4Kb minified JS file.

Compatibility

Lang4JS is compatible with Laravel 4.2+.

Installation

1) Via Composer

2) Then add the service provider in config/app.php:

3) And publish the asset file, i.e. lang4js.min.js:

4) Finally, add a route in routes/web.php:

Usage

1) Language Strings

Lang4JS retrieves language strings directly from your language files resides in resources/lang folder. Please add lines supposed to be used in your Javascript as those for your view blades.

2) Load Javascript Libraries

Lang4JS requires [jQuery] (http://jquery.com) library, you have to load it before the lang4js.min.js. So in any view blades you want to apply multilingual strings in Javascript, please insert these two lines:

3) Absolute Path

Both post('/lang4js', in route and src="/vendor/lang4js/lang4js.min.js" in view uses absolute path for the convenience to include the script from any URL. This means you have to point your domain to the public folder in your project, instead of the root folder, otherwise, a 404 error will occur or modify the paths according to your own environment.

4) CSRF Token

Lang4JS utilizes Ajax requests to retrieve language strings, and this requires CSRF Token in Laravel. There are two ways to set CSRF Token in your webpages.

  1. If the webpage contains a form, you may have probably had the line {{ csrf_field() }} in there. If not, add the line somewhere between <form>...</form>.
  2. If the webpage is not for form submission, please add <meta name="csrf-token" content="{{ csrf_token() }}"> into <head>...</head>.

In terms of security of you website, it's a good practice to always have CSRF Token presented in all webpages, which can be easily done by adding the meta tag for CSRF Token in the head sub-view for all views.

5) Use Language Keys in Javascript

Now in your Javascript, feel free to use trans(), trans_choice() as well as __() newly introduced in Laravel 5.4. Please refer to the Localization document according to your Laravel version for more information. For example:

The only difference in syntax

When using the place-holder feature of trans() or __(), the syntax ['name' => 'dayle'] does NOT work for Javascript, please write {'name' : 'dayle'} instead.

Some Issues

  1. trans(), trans_choice() or __() in your Javascript does NOT work before the DOM is ready, and will halt your entire Javascript. Please use them in functions.
  2. It's also a fatal error when there's no trans() nor trans_choice() nor __() at all in your Javascript. To fix this, just remove <script src="/vendor/lang4js/lang4js.min.js"></script> from you view.
  3. When the locale string requires newlines, please always use <br> for HTML and \n for Javascript. If you want to show \n as is in Javascript, please wrap it in double quotes, i.e. "\n".

Change log

Please see CHANGELOG for more information on what has changed recently.

Testing

Contributing

Please see CONDUCT for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.


All versions of lang4js with dependencies

PHP Build Version
Package Version
Requires illuminate/support Version ~4.2|~5.0
php Version ~5.6|~7.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package drewneon/lang4js contains the following files

Loading the files please wait ....