2
2
3
3
[ ![ Coverage report] ( https://repo.pkgkit.com/4GBWO/awes-io/localization-helper/badges/master/coverage.svg )] ( https://www.awes.io/ )
4
4
[ ![ Build status] ( https://repo.pkgkit.com/4GBWO/awes-io/localization-helper/badges/master/build.svg )] ( https://www.awes.io/ )
5
- [ ![ Composer Ready] ( https://www.pkgkit.com/4GBWO/awes-io/auth /status.svg )] ( https://www.awes.io/ )
6
- [ ![ Downloads] ( https://www.pkgkit.com/4GBWO/awes-io/auth /downloads.svg )] ( https://www.awes.io/ )
7
- [ ![ Last version] ( https://www.pkgkit.com/4GBWO/awes-io/auth /version.svg )] ( https://www.awes.io/ )
5
+ [ ![ Composer Ready] ( https://www.pkgkit.com/4GBWO/awes-io/localization-helper /status.svg )] ( https://www.awes.io/ )
6
+ [ ![ Downloads] ( https://www.pkgkit.com/4GBWO/awes-io/localization-helper /downloads.svg )] ( https://www.awes.io/ )
7
+ [ ![ Last version] ( https://www.pkgkit.com/4GBWO/awes-io/localization-helper /version.svg )] ( https://www.awes.io/ )
8
8
9
- Package for convenient work with Laravel's localization features. Take a look at [ contributing.md] ( contributing.md ) to see a to do list.
9
+ 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.
10
10
11
11
## Installation
12
12
@@ -16,17 +16,18 @@ Via Composer
16
16
$ composer require awes-io/localization-helper
17
17
```
18
18
19
- In Laravel 5.5, the service provider and facade will automatically get registered. For older versions of the framework, follow the steps below:
19
+ In Laravel 5.5+, service provider and facade will be automatically registered. For older versions, follow the steps below:
20
+
21
+ Register service provider in ` config/app.php ` :
20
22
21
- Register the service provider in config/app.php
22
23
``` php
23
24
'providers' => [
24
25
// [...]
25
26
AwesIO\LocalizationHelper\LocalizationHelperServiceProvider::class,
26
27
],
27
28
```
28
29
29
- You may also register the LaravelLocalization facade:
30
+ You may also register ` LaravelLocalization ` facade:
30
31
31
32
``` php
32
33
'aliases' => [
@@ -39,7 +40,7 @@ You may also register the LaravelLocalization facade:
39
40
40
41
### Config Files
41
42
42
- In order to edit the default configuration for this package you may execute:
43
+ In order to edit default configuration you may execute:
43
44
44
45
```
45
46
php artisan vendor:publish --provider="AwesIO\LocalizationHelper\LocalizationHelperServiceProvider"
@@ -49,23 +50,52 @@ After that, `config/localizationhelper.php` will be created.
49
50
50
51
## Usage
51
52
52
- Package registers global helper function:
53
+ Package registers global helper function ` _p($file_key, $default, $placeholders) ` :
53
54
54
55
``` php
55
- _p('auth.login', 'Login');
56
+ _p('auth.login', 'Login'); // "Login"
56
57
```
57
58
58
- Placeholders support:
59
+ It will create new localization file ` auth.php ` (if it doesn't exist) and write second parameter as language string under ` login ` key:
60
+
61
+ ``` php
62
+ return [
63
+ "login" => "Login"
64
+ ];
65
+ ```
66
+
67
+ On second call with same file/key ` _p('auth.login') ` , localization string will be returned, file will remain untouched.
68
+
69
+ Placeholders are also supported:
59
70
60
71
``` php
61
72
_p(
62
73
'mail.invitation',
63
74
'You’re invited to join :company company workspace',
64
- ['company' => $this->data['company'] ]
75
+ ['company' => 'Awesio' ]
65
76
);
66
77
```
67
78
68
- If key is returned, it means that string already exists and you trying to add new one using it as array.
79
+ 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.
80
+
81
+ ``` php
82
+ // in localization file.php
83
+ return [
84
+ "test" => "Test string"
85
+ ];
86
+
87
+ _p('file.test.new', 'Test string'); // will return "file.test.new"
88
+
89
+ _p('file.test_2.new', 'Test string'); // will return "Test string"
90
+
91
+ // and modify localization file:
92
+ return [
93
+ "test" => "Test string",
94
+ "test_2" => [
95
+ "new" => "Test string"
96
+ ]
97
+ ];
98
+ ```
69
99
70
100
## Change log
71
101
0 commit comments