{"id":16184622,"url":"https://github.com/rmariuzzo/laravel-js-localization","last_synced_at":"2025-05-13T21:06:42.418Z","repository":{"id":16469113,"uuid":"19221257","full_name":"rmariuzzo/Laravel-JS-Localization","owner":"rmariuzzo","description":"🌐 Convert your Laravel messages and consume them in the front-end!","archived":false,"fork":false,"pushed_at":"2025-04-21T04:50:07.000Z","size":366,"stargazers_count":605,"open_issues_count":27,"forks_count":172,"subscribers_count":19,"default_branch":"master","last_synced_at":"2025-04-28T12:12:30.803Z","etag":null,"topics":["i18n","internationalization","javascript","l10n","laravel","laravel-4-package","laravel-5-package","laravel-package","localization","php"],"latest_commit_sha":null,"homepage":"https://github.com/rmariuzzo/laravel-js-localization","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rmariuzzo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-04-27T23:25:58.000Z","updated_at":"2025-04-23T09:31:24.000Z","dependencies_parsed_at":"2024-06-18T11:02:10.621Z","dependency_job_id":"3d3993f7-e6ce-4bce-a112-8780029ca9ef","html_url":"https://github.com/rmariuzzo/Laravel-JS-Localization","commit_stats":{"total_commits":185,"total_committers":39,"mean_commits":4.743589743589744,"dds":0.4864864864864865,"last_synced_commit":"1ea310be42d3a4f09c38a0d97b8d5bd4683c7026"},"previous_names":[],"tags_count":32,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rmariuzzo%2FLaravel-JS-Localization","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rmariuzzo%2FLaravel-JS-Localization/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rmariuzzo%2FLaravel-JS-Localization/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rmariuzzo%2FLaravel-JS-Localization/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rmariuzzo","download_url":"https://codeload.github.com/rmariuzzo/Laravel-JS-Localization/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251311332,"owners_count":21569009,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["i18n","internationalization","javascript","l10n","laravel","laravel-4-package","laravel-5-package","laravel-package","localization","php"],"created_at":"2024-10-10T07:10:50.227Z","updated_at":"2025-04-28T12:12:40.819Z","avatar_url":"https://github.com/rmariuzzo.png","language":"PHP","readme":"# ![Laravel JS Localization - Convert you Laravel messages and use them in the front-end!](.github/assets/banner.svg)\n\n![Laravel 5.5](https://img.shields.io/badge/Laravel-5.5-f4645f.svg)\n![Laravel 4.2](https://img.shields.io/badge/Laravel-4.2-f4645f.svg)\n[![Latest Stable Version](https://poser.pugx.org/mariuzzo/laravel-js-localization/v/stable.svg)](https://packagist.org/packages/mariuzzo/laravel-js-localization)\n[![Total Downloads](https://poser.pugx.org/mariuzzo/laravel-js-localization/downloads.svg)](https://packagist.org/packages/mariuzzo/laravel-js-localization)\n[![License](https://poser.pugx.org/mariuzzo/laravel-js-localization/license.svg)](https://packagist.org/packages/mariuzzo/laravel-js-localization)\n\nThis package convert all your localization messages from your Laravel app to JavaScript with a small library to interact with those messages following a very similar syntax you are familiar with.\n\n## Features\n\n - Support Laravel 4.2, 5.0, 5.1, 5.2, 5.3, 5.4, 5.5, 6.x, 7.x and 8.x!\n - Includes [Lang.js](https://github.com/rmariuzzo/lang.js) (a thin library highly inspired on Laravel's [`Translator`](https://laravel.com/api/5.4/Illuminate/Translation/Translator.html) class).\n - Allow to specify desired lang files to be converted to JS.\n - Lang.js API is based on Laravel's [`Translator`](https://laravel.com/api/5.4/Illuminate/Translation/Translator.html) class. No need to learn a whole API.\n\n\u003ctable\u003e\u003ctbody\u003e\u003ctr\u003e\u003ctd\u003e\n\n:star: **Webpack user?** Try the new and shiny [**Laravel localization loader**](https://github.com/rmariuzzo/laravel-localization-loader) for Webpack!\n\n\u003c/td\u003e\u003c/tr\u003e\u003c/tbody\u003e\u003c/table\u003e\n\n\n## Installation\n\n```shell\ncomposer require mariuzzo/laravel-js-localization\n```\n\nIn your Laravel app go to `config/app.php` and add the following service provider:\n\n```php\nMariuzzo\\LaravelJsLocalization\\LaravelJsLocalizationServiceProvider::class\n```\n\n## Usage\n\nThe `Laravel-JS-Localization` package provides a command that generate the JavaScript version of all your messages found at: `app/lang` (Laravel 4) or `resources/lang` (Laravel 5) directory. The resulting JavaScript file will contain all your messages plus [Lang.js](https://github.com/rmariuzzo/lang.js) (a thin library highly inspired on Laravel's [`Translator`](https://laravel.com/api/5.4/Illuminate/Translation/Translator.html) class).\n\n### Generating JS messages\n\n```shell\nphp artisan lang:js\n```\n\n### Specifying a custom target\n\n```shell\nphp artisan lang:js public/assets/dist/lang.dist.js\n```\n\n### Compressing the JS file\n\n```shell\nphp artisan lang:js -c\n```\n\n### Specifying a custom source folder\n\n```shell\nphp artisan lang:js public/assets/dist/lang.dist.js -s themes/default/lang\n```\n\n### Output a JSON file instead.\n\n```shell\nphp artisan lang:js --json\n```\n\n## Configuration\n\nFirst, publish the default package's configuration file running:\n\n```shell\nphp artisan vendor:publish --provider=\"Mariuzzo\\LaravelJsLocalization\\LaravelJsLocalizationServiceProvider\"\n```\n\nThe configuration will be published to `config/localization-js.php`.\n\nYou may edit this file to define the messages you need in your Javascript code. Just edit the `messages` array in the config file. **Empty messages array will include all the language files in build**.\n\nTo make only `pagination.php` and `validation.php` files to be included in build process:\n\n```php\n\u003c?php\n\nreturn [\n    'messages' =\u003e [\n        'pagination',\n        'validation',\n    ],\n];\n```\n\n### Using [gulp](http://gulpjs.com/) (optional)\n\nInstall [`gulp-shell`](https://github.com/sun-zheng-an/gulp-shell) and then run it directly in your `gulpfile.js`:\n\n```js\nvar shell = require('gulp-shell');\n\ngulp.task('langjs', shell.task('php artisan lang:js -c public/js/messages.js'));\n```\n\n### Using [Laravel's elixir](http://laravel.com/docs/elixir) (optional)\nBefore Elixir 4.0:\n\n```js\nelixir.extend('langjs', function(path) {\n    gulp.task('langjs', function() {\n        gulp.src('').pipe(shell('php artisan lang:js ' + (path || 'public/js/messages.js')));\n    });\n\n    return this.queueTask('langjs');\n});\n```\nElixir 4.0+:\n```js\nvar Task = elixir.Task;\nelixir.extend('langjs', function(path) {\n    new Task('langjs', function() {\n        gulp.src('').pipe(shell('php artisan lang:js ' + (path || 'public/js/messages.js')));\n    });\n});\n```\n\nAnd use it like this:\n\n```js\nelixir(function(mix) {\n    mix.langjs();\n});\n```\n\n### Using [Laravel's Mix](https://laravel.com/docs/5.4/mix) with Laravel 5.4+ (optional)\n\nAdd \"[webpack-shell-plugin-next](https://www.npmjs.com/package/webpack-shell-plugin-next)\" to package.json's \"devDependencies\" section.\n\nAdd the following to webpack.mix.js:\n\n```js\nconst WebpackShellPluginNext = require('webpack-shell-plugin-next');\n\n// Add shell command plugin configured to create JavaScript language file\nmix.webpackConfig({\n    plugins:\n    [\n        new WebpackShellPluginNext({onBuildStart:['php artisan lang:js --quiet'], onBuildEnd:[]})\n    ]\n});\n```\n\n## Documentation\n\nThis is a quick documentation regarding [Lang.js](https://github.com/rmariuzzo/lang.js) (the thin JavaScript library included by `Laravel-JS-Localization`). The [Lang.js](https://github.com/rmariuzzo/lang.js) (a thin library highly inspired on Laravel's [`Translator`](https://laravel.com/api/5.3/Illuminate/Translation/Translator.html) class).\n\n \u003e 💁 Go to [Lang.js documentation]([Lang.js](https://github.com/rmariuzzo/lang.js)) to see all available methods.\n\n### Getting a message\n\n```js\nLang.get('messages.home');\n```\n\n### Getting a message with replacements\n\n```js\nLang.get('messages.welcome', { name: 'Joe' });\n```\n\n### Changing the locale\n\n```js\nLang.setLocale('es');\n```\n\n### Checking if a message key exists\n\n```js\nLang.has('messages.foo');\n```\n\n### Support for singular and plural message based on a count\n\n```js\nLang.choice('messages.apples', 10);\n```\n\n### Calling the `choice` method with replacements\n\n```js\nLang.choice('messages.apples', 10, { name: 'Joe' });\n```\n\n\u003e 💁 Go to [Lang.js documentation]([Lang.js](https://github.com/rmariuzzo/lang.js)) to see all available methods.\n\n## Want to contribute?\n\n 1. Fork this repository and clone it.\n 2. Create a [feature branch](https://guides.github.com/introduction/flow/) from develop: `git checkout develop; git checkout -b feature-foo`.\n 3. Push your commits and create a pull request.\n\n### Prerequisites:\n\nYou will need to have installed the following softwares.\n\n - Composer.\n - PHP 5.5+.\n\n### Development setup\n\nAfter getting all the required softwares you may run the following commands to get everything ready:\n\n 1. Install PHP dependencies:\n    ```shell\n    composer install\n    ```\n\n 2. Install test dependencies:\n    ```shell\n    composer test-install\n    ```\n\nNow you are good to go! Happy coding!\n\n## Testing\n\nThis project uses PHPUnit. All tests are stored at `tests` directory. To run all tests type in your terminal:\n\n```shell\ncomposer test\n```\n\n\u003cdiv align=center\u003e\n\nMade with :heart: by [Rubens Mariuzzo](https://github.com/rmariuzzo).\n\n[MIT license](LICENSE)\n\n\u003c/div\u003e\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frmariuzzo%2Flaravel-js-localization","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frmariuzzo%2Flaravel-js-localization","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frmariuzzo%2Flaravel-js-localization/lists"}