https://github.com/awes-io/localization-helper
π Laravel Localization Helper :: Easily add translation variables from Blade templates.
https://github.com/awes-io/localization-helper
language laravel locale localization php translation
Last synced: 5 months ago
JSON representation
π Laravel Localization Helper :: Easily add translation variables from Blade templates.
- Host: GitHub
- URL: https://github.com/awes-io/localization-helper
- Owner: awes-io
- License: gpl-3.0
- Created: 2019-06-20T17:59:20.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-10-10T16:12:15.000Z (over 6 years ago)
- Last Synced: 2024-02-23T22:43:36.936Z (about 2 years ago)
- Topics: language, laravel, locale, localization, php, translation
- Language: PHP
- Homepage: https://www.awes.io
- Size: 27.3 KB
- Stars: 35
- Watchers: 5
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- Changelog: changelog.md
- Contributing: contributing.md
- License: LICENSE
Awesome Lists containing this project
README
# LocalizationHelper
[](https://www.awes.io/)
[](https://www.awes.io/)
[](https://www.awes.io/)
[](https://www.awes.io/)
[](https://www.awes.io/)
Package for convenient work with Laravel's localization features and fast language files generation. Take a look at [contributing.md](contributing.md) to see a to do list.
## Installation
Via Composer
``` bash
$ composer require awes-io/localization-helper
```
In Laravel 5.5+, service provider and facade will be automatically registered. For older versions, follow the steps below:
Register service provider in `config/app.php`:
```php
'providers' => [
// [...]
AwesIO\LocalizationHelper\LocalizationHelperServiceProvider::class,
],
```
You may also register `LaravelLocalization` facade:
```php
'aliases' => [
// [...]
'LocalizationHelper' => AwesIO\LocalizationHelper\Facades\LocalizationHelper::class,
],
```
## Config
### Config Files
In order to edit default configuration you may execute:
```
php artisan vendor:publish --provider="AwesIO\LocalizationHelper\LocalizationHelperServiceProvider"
```
After that, `config/localizationhelper.php` will be created.
## Usage
Package registers global helper function `_p($file_key, $default, $placeholders)`:
```php
_p('auth.login', 'Login'); // "Login"
```
It will create new localization file `auth.php` (if it doesn't exist) and write second parameter as language string under `login` key:
```php
return [
"login" => "Login"
];
```
On second call with same file/key `_p('auth.login')`, localization string will be returned, file will remain untouched.
Placeholders are also supported:
```php
_p(
'mail.invitation',
'Youβre invited to join :company company workspace',
['company' => 'Awesio']
);
```
If key is returned, it means that string already exists in localization file and you are trying to add new one using its value as an array.
```php
// in localization file.php
return [
"test" => "Test string"
];
_p('file.test.new', 'Test string'); // will return "file.test.new"
_p('file.test_2.new', 'Test string'); // will return "Test string"
// and modify localization file:
return [
"test" => "Test string",
"test_2" => [
"new" => "Test string"
]
];
```
## Change log
Please see the [changelog](changelog.md) for more information on what has changed recently.
## Testing
``` bash
$ composer test
```
## Contributing
Please see [contributing.md](contributing.md) for details and a todolist.
## Security
If you discover any security related issues, please email info@awescrm.de instead of using the issue tracker.
## Credits
- [Galymzhan Begimov](https://github.com/begimov)
- [All Contributors](contributing.md)
## License
[MIT](http://opensource.org/licenses/MIT)