1
1
# Localization Helper
2
2
3
+ Package for convenient work with Laravel's localization features and fast language files generation.
4
+
3
5
## Installation
4
6
5
7
Via Composer
6
8
7
9
``` bash
8
- $ composer require AwesIO/localizationhelper
10
+ $ composer require awes-io/localization-helper
9
11
```
10
12
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 ` :
12
16
13
- Register the service provider in config/app.php
14
17
``` php
15
18
'providers' => [
16
19
// [...]
17
20
AwesIO\LocalizationHelper\LocalizationHelperServiceProvider::class,
18
21
],
19
22
```
20
23
21
- You may also register the LaravelLocalization facade:
24
+ You may also register ` LaravelLocalization ` facade:
22
25
23
26
``` php
24
27
'aliases' => [
@@ -31,7 +34,7 @@ You may also register the LaravelLocalization facade:
31
34
32
35
### Config Files
33
36
34
- In order to edit the default configuration for this package you may execute:
37
+ In order to edit default configuration you may execute:
35
38
36
39
```
37
40
php artisan vendor:publish --provider="AwesIO\LocalizationHelper\LocalizationHelperServiceProvider"
@@ -41,23 +44,52 @@ After that, `config/localizationhelper.php` will be created.
41
44
42
45
## Usage
43
46
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:
45
54
46
55
``` php
47
- _p('auth.login', 'Login');
56
+ return [
57
+ "login" => "Login"
58
+ ];
48
59
```
49
60
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:
51
64
52
65
``` php
53
66
_p(
54
67
'mail.invitation',
55
68
'You’re invited to join :company company workspace',
56
- ['company' => $this->data['company'] ]
69
+ ['company' => 'Awesio' ]
57
70
);
58
71
```
59
72
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
+ ```
61
93
62
94
## Testing
63
95
0 commit comments