Skip to content

Commit 8a0a13c

Browse files
committed
Merge remote-tracking branch 'origin/master'
# Conflicts: # README.md
2 parents 559d782 + e408847 commit 8a0a13c

File tree

6 files changed

+28
-21
lines changed

6 files changed

+28
-21
lines changed

README.md

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,28 +23,28 @@ composer require kg-bot/laravel-localization-to-vue
2323
Laravel 5.5 uses Package Auto-Discovery, so doesn't require you to manually add the ServiceProvider.
2424

2525
If you don't use auto-discovery, add the ServiceProvider to the providers array in config/app.php
26-
```
26+
```php
2727
KgBot\LaravelLocalization\LaravelLocalizationServiceProvider::class
2828
```
2929

3030
and if you want alias add this inside aliases array in config/app.php
31-
```
31+
```php
3232
"ExportLocalization" => "KgBot\\LaravelLocalization\\Facades\\ExportLocalizations"
3333
```
3434

3535
## Settings and configuration
3636

3737
You can export config by running
3838

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
4141
```
4242

4343
if you want to parse multiple language directories or some other directory except `resources/lang` you can add multiple
4444
paths in config `paths.lang_dirs` inside array.
4545

4646
It can be just one path or multiple paths, for example
47-
```
47+
```php
4848
paths => [resource_path('lang'), app_path('lang'), app_path('Modules/Blog/lang')]
4949
```
5050

@@ -54,7 +54,7 @@ This package can be used in multiple ways, I'll give examples for some of them,
5454

5555
First example would be to add view composed variable and use it in blade views.
5656

57-
```
57+
```php
5858
// inside ServiceProvider
5959

6060
// With alias
@@ -74,7 +74,7 @@ View::composer( 'view.file', function ( $view ) {
7474

7575
Second way would be to request it over HTTP just like any other file
7676

77-
```
77+
```html
7878
<script>
7979
let messages = axios.get('http://localhost/js/lang.js') // This is default route which can be changed in config
8080
</script>
@@ -88,7 +88,7 @@ You can also export messages to ECMAScript 6 standard JavaScript module with art
8888
## Export for npm localization packages like Lang.js
8989
If you need special format of array that's recognised by some npm localization packages as [Lang.js](https://github.com/rmariuzzo/Lang.js).
9090

91-
```
91+
```php
9292
// Call toFlat() instead of toArray()
9393
ExportLocalization::export()->toFlat()
9494

@@ -101,14 +101,16 @@ php artisan export:messages-flat
101101

102102
## Some examples why would you use this package and messages over Laravel standard localization
103103

104-
```
104+
```html
105105
// Inside blade view
106106
<script>
107107
window.default_locale = "{{ config('app.locale') }}";
108108
window.fallback_locale = "{{ config('app.fallback_locale') }}";
109109
window.messages = @json($messages);
110110
</script>
111+
```
111112

113+
```js
112114
// And optionaly you can then use it in any JavaScript file or Vue.js component
113115

114116
// app.js
@@ -120,23 +122,28 @@ const fallback_locale = window.fallback_locale;
120122
const messages = window.messages;
121123

122124
Vue.prototype.trans = new Lang( { messages, locale: default_locale, fallback: fallback_locale } );
125+
```
123126

127+
```html
124128
// Example.vue
125129
<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>
128133
```
129134

130135
## A note about json files
131136

132137
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
133138

134-
```
139+
```json
135140
// Assuming that es.json exists and it is the default locale in your app
136141
{
137142
"I love programming": "Me encanta programar"
138143
}
144+
```
139145

146+
```html
140147
// Example.vue
141148
<b-input v-model="query" type="text" :placeholder="trans.get('__JSON__.I love programming')"></b-input>
142149
```

src/Classes/ExportLocalizations.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class ExportLocalizations implements \JsonSerializable
4444
* @param string $phpRegex
4545
* @param string $jsonRegex
4646
*/
47-
public function __construct($phpRegex, $jsonRegex)
47+
public function __construct($phpRegex = '/^.+\.php$/i', $jsonRegex = '/^.+\.json$/i')
4848
{
4949
$this->phpRegex = $phpRegex;
5050
$this->jsonRegex = $jsonRegex;

src/Console/Commands/ExportMessages.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
namespace KgBot\LaravelLocalization\Console\Commands;
44

55
use Illuminate\Console\Command;
6-
use League\Flysystem\Filesystem;
7-
use League\Flysystem\Adapter\Local;
86
use KgBot\LaravelLocalization\Facades\ExportLocalizations;
7+
use League\Flysystem\Adapter\Local;
8+
use League\Flysystem\Filesystem;
99

1010
class ExportMessages extends Command
1111
{

src/Console/Commands/ExportMessagesToFlat.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
namespace KgBot\LaravelLocalization\Console\Commands;
44

55
use Illuminate\Console\Command;
6-
use League\Flysystem\Filesystem;
7-
use League\Flysystem\Adapter\Local;
86
use KgBot\LaravelLocalization\Facades\ExportLocalizations;
7+
use League\Flysystem\Adapter\Local;
8+
use League\Flysystem\Filesystem;
99

1010
class ExportMessagesToFlat extends Command
1111
{

src/Events/LaravelLocalizationExported.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88

99
namespace KgBot\LaravelLocalization\Events;
1010

11-
use Illuminate\Queue\SerializesModels;
11+
use Illuminate\Broadcasting\InteractsWithSockets;
1212
use Illuminate\Broadcasting\PrivateChannel;
1313
use Illuminate\Foundation\Events\Dispatchable;
14-
use Illuminate\Broadcasting\InteractsWithSockets;
14+
use Illuminate\Queue\SerializesModels;
1515

1616
class LaravelLocalizationExported
1717
{

src/LaravelLocalizationServiceProvider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ class LaravelLocalizationServiceProvider extends ServiceProvider
1818
public function boot()
1919
{
2020
$this->app->bind('export-localization', function () {
21-
$phpRegex = config('laravel-localization.file_regexp.php');
22-
$jsonRegex = config('laravel-localization.file_regexp.json');
21+
$phpRegex = config('laravel-localization.file_regexp.php', '/^.+\.php$/i');
22+
$jsonRegex = config('laravel-localization.file_regexp.json', '/^.+\.json$/i');
2323

2424
return new ExportLocalizations($phpRegex, $jsonRegex);
2525
});

0 commit comments

Comments
 (0)