Skip to content

Commit d846c4d

Browse files
Component "awes-io/localization-helper" was updated to v1.0
1 parent a5c71b0 commit d846c4d

File tree

1 file changed

+42
-10
lines changed
  • docs/components/localization-helper/1.0

1 file changed

+42
-10
lines changed

docs/components/localization-helper/1.0/index.md

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,27 @@
11
# Localization Helper
22

3+
Package for convenient work with Laravel's localization features and fast language files generation.
4+
35
## Installation
46

57
Via Composer
68

79
``` bash
8-
$ composer require AwesIO/localizationhelper
10+
$ composer require awes-io/localization-helper
911
```
1012

11-
In Laravel 5.5, the service provider and facade will automatically get registered. For older versions of the framework, follow the steps below:
13+
In Laravel 5.5+, service provider and facade will be automatically registered. For older versions, follow the steps below:
14+
15+
Register service provider in `config/app.php`:
1216

13-
Register the service provider in config/app.php
1417
```php
1518
'providers' => [
1619
// [...]
1720
AwesIO\LocalizationHelper\LocalizationHelperServiceProvider::class,
1821
],
1922
```
2023

21-
You may also register the LaravelLocalization facade:
24+
You may also register `LaravelLocalization` facade:
2225

2326
```php
2427
'aliases' => [
@@ -31,7 +34,7 @@ You may also register the LaravelLocalization facade:
3134

3235
### Config Files
3336

34-
In order to edit the default configuration for this package you may execute:
37+
In order to edit default configuration you may execute:
3538

3639
```
3740
php artisan vendor:publish --provider="AwesIO\LocalizationHelper\LocalizationHelperServiceProvider"
@@ -41,23 +44,52 @@ After that, `config/localizationhelper.php` will be created.
4144

4245
## Usage
4346

44-
Package registers global helper function:
47+
Package registers global helper function `_p($file_key, $default, $placeholders)`:
48+
49+
```php
50+
_p('auth.login', 'Login'); // "Login"
51+
```
52+
53+
It will create new localization file `auth.php` (if it doesn't exist) and write second parameter as language string under `login` key:
4554

4655
```php
47-
_p('auth.login', 'Login');
56+
return [
57+
"login" => "Login"
58+
];
4859
```
4960

50-
Placeholders support:
61+
On second call with same file/key `_p('auth.login')`, localization string will be returned, file will remain untouched.
62+
63+
Placeholders are also supported:
5164

5265
```php
5366
_p(
5467
'mail.invitation',
5568
'You’re invited to join :company company workspace',
56-
['company' => $this->data['company']]
69+
['company' => 'Awesio']
5770
);
5871
```
5972

60-
If key is returned, it means that string already exists and you trying to add new one using it as array.
73+
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.
74+
75+
```php
76+
// in localization file.php
77+
return [
78+
"test" => "Test string"
79+
];
80+
81+
_p('file.test.new', 'Test string'); // will return "file.test.new"
82+
83+
_p('file.test_2.new', 'Test string'); // will return "Test string"
84+
85+
// and modify localization file:
86+
return [
87+
"test" => "Test string",
88+
"test_2" => [
89+
"new" => "Test string"
90+
]
91+
];
92+
```
6193

6294
## Testing
6395

0 commit comments

Comments
 (0)