Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/chinleung/laravel-locales
Add configurations and helpers for a multi locale Laravel application.
https://github.com/chinleung/laravel-locales
composer-package laravel localization package
Last synced: 17 days ago
JSON representation
Add configurations and helpers for a multi locale Laravel application.
- Host: GitHub
- URL: https://github.com/chinleung/laravel-locales
- Owner: chinleung
- License: mit
- Created: 2019-07-30T15:33:03.000Z (over 5 years ago)
- Default Branch: v2
- Last Pushed: 2024-04-09T13:18:50.000Z (7 months ago)
- Last Synced: 2024-10-11T18:32:18.442Z (about 1 month ago)
- Topics: composer-package, laravel, localization, package
- Language: PHP
- Homepage:
- Size: 40 KB
- Stars: 35
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Laravel Locales
[![Latest Version on Packagist](https://img.shields.io/packagist/v/chinleung/laravel-locales.svg?style=flat-square)](https://packagist.org/packages/chinleung/laravel-locales)
[![Build Status](https://github.com/chinleung/laravel-locales/workflows/tests/badge.svg?branch=v2)](https://github.com/chinleung/laravel-locales/actions?query=workflow%3Atests)
[![Quality Score](https://img.shields.io/scrutinizer/g/chinleung/laravel-locales.svg?style=flat-square)](https://scrutinizer-ci.com/g/chinleung/laravel-locales)
[![Total Downloads](https://img.shields.io/packagist/dt/chinleung/laravel-locales.svg?style=flat-square)](https://packagist.org/packages/chinleung/laravel-locales)Add configurations and helpers to make an application support multiple locales.
## Installation
You can install the package via composer:
```bash
composer require chinleung/laravel-locales
```## Configuration
By default, the application locales is only going to be `en`. If your application support other locales, you can either set a `app.locales` in your `config/app.php` or publish the configuration file:
``` bash
php artisan vendor:publish --provider="ChinLeung\LaravelLocales\LaravelLocalesServiceProvider" --tag="config"
```## Helpers
### locale(string $locale = null) : string
> Retrieve or update the current locale of the application.
```php
// Alias of app()->getLocale();
locale(); // 'en'// Alias of app()->setLocale('fr');
locale('fr'); // 'fr'
locale(); // 'fr'
```### locales(array $locales = null) : array
> Retrieve or update the supported locales of the application.
> Has priority for `app.locales` over `laravel-locales.supported`.``` php
locales(); // ['en']locales(['en', 'fr', 'zh']);
locales(); // ['en', 'fr', 'zh']locales(['en', 'zh']);
locales(); // ['en', 'zh']
```### Testing
``` bash
composer test
```### Changelog
Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.
## Contributing
Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
### Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
## Credits
- [Chin Leung](https://github.com/chinleung)
- [All Contributors](../../contributors)## License
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.
## Laravel Package Boilerplate
This package was generated using the [Laravel Package Boilerplate](https://laravelpackageboilerplate.com).