@@ -23,28 +23,28 @@ composer require kg-bot/laravel-localization-to-vue
23
23
Laravel 5.5 uses Package Auto-Discovery, so doesn't require you to manually add the ServiceProvider.
24
24
25
25
If you don't use auto-discovery, add the ServiceProvider to the providers array in config/app.php
26
- ```
26
+ ``` php
27
27
KgBot\LaravelLocalization\LaravelLocalizationServiceProvider::class
28
28
```
29
29
30
30
and if you want alias add this inside aliases array in config/app.php
31
- ```
31
+ ``` php
32
32
"ExportLocalization" => "KgBot\\LaravelLocalization\\Facades\\ExportLocalizations"
33
33
```
34
34
35
35
## Settings and configuration
36
36
37
37
You can export config by running
38
38
39
- ```
40
- php artisan vendor:publish --provider=" KgBot\LaravelLocalization\LaravelLocalizationServiceProvider" --tag=config
39
+ ``` php
40
+ php artisan vendor:publish --provider=KgBot\LaravelLocalization\LaravelLocalizationServiceProvider --tag=config
41
41
```
42
42
43
43
if you want to parse multiple language directories or some other directory except ` resources/lang ` you can add multiple
44
44
paths in config ` paths.lang_dirs ` inside array.
45
45
46
46
It can be just one path or multiple paths, for example
47
- ```
47
+ ``` php
48
48
paths => [resource_path('lang'), app_path('lang'), app_path('Modules/Blog/lang')]
49
49
```
50
50
@@ -54,7 +54,7 @@ This package can be used in multiple ways, I'll give examples for some of them,
54
54
55
55
First example would be to add view composed variable and use it in blade views.
56
56
57
- ```
57
+ ``` php
58
58
// inside ServiceProvider
59
59
60
60
// With alias
@@ -74,7 +74,7 @@ View::composer( 'view.file', function ( $view ) {
74
74
75
75
Second way would be to request it over HTTP just like any other file
76
76
77
- ```
77
+ ``` html
78
78
<script >
79
79
let messages = axios .get (' http://localhost/js/lang.js' ) // This is default route which can be changed in config
80
80
</script >
@@ -88,7 +88,7 @@ You can also export messages to ECMAScript 6 standard JavaScript module with art
88
88
## Export for npm localization packages like Lang.js
89
89
If you need special format of array that's recognised by some npm localization packages as [ Lang.js] ( https://github.com/rmariuzzo/Lang.js ) .
90
90
91
- ```
91
+ ``` php
92
92
// Call toFlat() instead of toArray()
93
93
ExportLocalization::export()->toFlat()
94
94
@@ -101,14 +101,16 @@ php artisan export:messages-flat
101
101
102
102
## Some examples why would you use this package and messages over Laravel standard localization
103
103
104
- ```
104
+ ``` html
105
105
// Inside blade view
106
106
<script >
107
107
window .default_locale = " {{ config('app.locale') }}" ;
108
108
window .fallback_locale = " {{ config('app.fallback_locale') }}" ;
109
109
window .messages = @json ($messages);
110
110
</script >
111
+ ```
111
112
113
+ ``` js
112
114
// And optionaly you can then use it in any JavaScript file or Vue.js component
113
115
114
116
// app.js
@@ -120,23 +122,28 @@ const fallback_locale = window.fallback_locale;
120
122
const messages = window .messages ;
121
123
122
124
Vue .prototype .trans = new Lang ( { messages, locale: default_locale, fallback: fallback_locale } );
125
+ ```
123
126
127
+ ``` html
124
128
// Example.vue
125
129
<b-input v-model =" query"
126
- type="text"
127
- :placeholder="trans.get('search.placeholder')"></b-input>
130
+ type =" text"
131
+ :placeholder =" trans.get('search.placeholder')"
132
+ ></b-input >
128
133
```
129
134
130
135
## A note about json files
131
136
132
137
Laravel 5.4+ allows localization to be strutured [ using a single ` .json ` file for each language] ( https://laravel.com/docs/5.7/localization#using-translation-strings-as-keys ) , in order to use the strings inside the provided json file you must prepend the ` __JSON__ ` key
133
138
134
- ```
139
+ ``` json
135
140
// Assuming that es.json exists and it is the default locale in your app
136
141
{
137
142
"I love programming" : " Me encanta programar"
138
143
}
144
+ ```
139
145
146
+ ``` html
140
147
// Example.vue
141
148
<b-input v-model =" query" type =" text" :placeholder =" trans.get('__JSON__.I love programming')" ></b-input >
142
149
```
0 commit comments