Skip to content

Commit 310fc1b

Browse files
committed
Merge pull request #10 from Liingon/master
Support for Laravel5 --- Not tested by potsky on Laravel 5. Work on Laravel 4. Ok.
2 parents 0f920d3 + 2906087 commit 310fc1b

File tree

4 files changed

+233
-17
lines changed

4 files changed

+233
-17
lines changed

README.md

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,36 @@ LLH is a set of tools to help you manage translations in your Laravel project.
1616

1717
2 - Update your installation : `composer update`
1818

19-
3 - Add the following line in the `providers` array of the `app/config/app.php` configuration file :
20-
`'Potsky\LaravelLocalizationHelpers\LaravelLocalizationHelpersServiceProvider',`
19+
3 - Add one of the following lines in the `providers` array of the `app/config/app.php` configuration file :
20+
21+
Laravel 4: `'Potsky\LaravelLocalizationHelpers\LaravelLocalizationHelpersServiceProvider',`
22+
23+
Laravel 5: `'Potsky\LaravelLocalizationHelpers\LaravelLocalizationHelpersServiceProviderLaravel5',`
24+
2125

2226
Now execute `php artisan list` and you should view the new *localization* commands:
2327

2428
```
2529
...
2630
key
27-
key:generate Set the application key
31+
key:generate Set the application key
2832
localization
29-
localization:find Display all files where the argument is used as a lemma
30-
localization:missing Parse all translations in app directory and build all lang files
33+
localization:find Display all files where the argument is used as a lemma
34+
localization:missing Parse all translations in app directory and build all lang files
3135
migrate
32-
migrate:install Create the migration repository
36+
migrate:install Create the migration repository
3337
...
3438
```
3539

3640
## Configuration
3741

3842
To configure your fresh installed package, please create a configuration file by executing :
3943

40-
`php artisan config:publish potsky/laravel-localization-helpers`
44+
For Laravel 4: `php artisan config:publish potsky/laravel-localization-helpers`
45+
46+
For Laravel 5: `php artisan vendor:publish`
4147

42-
Then you can modify the configuration in file `app/config/packages/potsky/laravel-localization-helpers/config.php`.
48+
Then you can modify the configuration in file `app/config/packages/potsky/laravel-localization-helpers/config.php` (Laravel 4) or `app/config/laravel-localization-helpers.php` (Laravel 5).
4349

4450
Add new folders to search for, add your own lang methods or functions, ...
4551

@@ -125,9 +131,9 @@ php artisan localization:missing -l 'Please translate this !'
125131
126132
php artisan localization:missing -s
127133
if [ $? -eq 0 ]; then
128-
echo "Nothing to do dude, GO for release"
134+
echo "Nothing to do dude, GO for release"
129135
else
130-
echo "I will not release in production, lang files are not clean"
136+
echo "I will not release in production, lang files are not clean"
131137
fi
132138
```
133139

@@ -146,7 +152,7 @@ php artisan localization:missing -e
146152
You can edit the editor path in your configuration file. By default, editor is *Sublime Text* on *Mac OS X* :
147153

148154
```
149-
'editor_command_line' => '/Applications/Sublime\\ Text.app/Contents/SharedSupport/bin/subl'
155+
'editor_command_line' => '/Applications/Sublime\\ Text.app/Contents/SharedSupport/bin/subl'
150156
```
151157

152158
### Command `localization:find`

src/Potsky/LaravelLocalizationHelpers/Commands/LocalizationAbstract.php

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,27 @@ abstract class LocalizationAbstract extends Command
6767
*/
6868
public function __construct( Repository $configRepository )
6969
{
70-
$this->trans_methods = \Config::get('laravel-localization-helpers::config.trans_methods');
71-
$this->folders = \Config::get('laravel-localization-helpers::config.folders');
72-
$this->ignore_lang_files = \Config::get('laravel-localization-helpers::config.ignore_lang_files');
73-
$this->lang_folder_path = \Config::get('laravel-localization-helpers::config.lang_folder_path');
74-
$this->never_obsolete_keys = \Config::get('laravel-localization-helpers::config.never_obsolete_keys');
75-
$this->editor = \Config::get('laravel-localization-helpers::config.editor_command_line');
70+
$laravel = app();
71+
if (substr($laravel::VERSION, 0, 1) == '5')
72+
{
73+
// Laravel 5
74+
$this->trans_methods = \Config::get('laravel-localization-helpers.trans_methods');
75+
$this->folders = \Config::get('laravel-localization-helpers.folders');
76+
$this->ignore_lang_files = \Config::get('laravel-localization-helpers.ignore_lang_files');
77+
$this->lang_folder_path = \Config::get('laravel-localization-helpers.lang_folder_path');
78+
$this->never_obsolete_keys = \Config::get('laravel-localization-helpers.never_obsolete_keys');
79+
$this->editor = \Config::get('laravel-localization-helpers.editor_command_line');
80+
}
81+
else
82+
{
83+
// Laravel 4
84+
$this->trans_methods = \Config::get('laravel-localization-helpers::config.trans_methods');
85+
$this->folders = \Config::get('laravel-localization-helpers::config.folders');
86+
$this->ignore_lang_files = \Config::get('laravel-localization-helpers::config.ignore_lang_files');
87+
$this->lang_folder_path = \Config::get('laravel-localization-helpers::config.lang_folder_path');
88+
$this->never_obsolete_keys = \Config::get('laravel-localization-helpers::config.never_obsolete_keys');
89+
$this->editor = \Config::get('laravel-localization-helpers::config.editor_command_line');
90+
}
7691
parent::__construct();
7792
}
7893

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php namespace Potsky\LaravelLocalizationHelpers;
2+
3+
use Illuminate\Support\ServiceProvider;
4+
5+
class LaravelLocalizationHelpersServiceProviderLaravel5 extends ServiceProvider {
6+
7+
/**
8+
* Indicates if loading of the provider is deferred.
9+
*
10+
* @var bool
11+
*/
12+
protected $defer = false;
13+
14+
/**
15+
* Bootstrap the application events.
16+
*
17+
* @return void
18+
*/
19+
public function boot()
20+
{
21+
$this->publishes(array(
22+
__DIR__.'/../../config/config-laravel5.php' => config_path('laravel-localization-helpers.php')
23+
));
24+
}
25+
26+
/**
27+
* Register the service provider.
28+
*
29+
* @return void
30+
*/
31+
public function register()
32+
{
33+
$this->app['localization.missing'] = $this->app->share( function( $app ) {
34+
return new Commands\LocalizationMissing( $app['config'] );
35+
});
36+
37+
$this->app['localization.find'] = $this->app->share( function( $app ) {
38+
return new Commands\LocalizationFind( $app['config'] );
39+
});
40+
41+
$this->commands(
42+
'localization.missing',
43+
'localization.find'
44+
);
45+
46+
$this->mergeConfigFrom(
47+
__DIR__.'/../../config/config-laravel5.php', 'laravel-localization-helpers'
48+
);
49+
}
50+
51+
/**
52+
* Get the services provided by the provider.
53+
*
54+
* @return array
55+
*/
56+
public function provides()
57+
{
58+
return array();
59+
}
60+
61+
}
62+
63+
64+

src/config/config-laravel5.php

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
<?php
2+
3+
return array(
4+
5+
/*
6+
|--------------------------------------------------------------------------
7+
| Folders where to search for lemmas
8+
|--------------------------------------------------------------------------
9+
|
10+
| Localization::Missing will search recursively for lemmas in all php files
11+
| included in these folders. You can use these keywords :
12+
| - %APP : the laravel app folder of your project
13+
| - %BASE : the laravel base folder of your project
14+
| - %PUBLIC : the laravel public folder of your project
15+
| - %STORAGE : the laravel storage folder of your project
16+
| No error or exception is thrown when a folder does not exist.
17+
|
18+
*/
19+
'folders' => array(
20+
'%BASE/resources/views',
21+
'%APP/Http/Controllers',
22+
),
23+
24+
25+
/*
26+
|--------------------------------------------------------------------------
27+
| Lang file to ignore
28+
|--------------------------------------------------------------------------
29+
|
30+
| These lang files will not be written
31+
|
32+
*/
33+
'ignore_lang_files' => array(
34+
'validation',
35+
),
36+
37+
38+
/*
39+
|--------------------------------------------------------------------------
40+
| Lang folder
41+
|--------------------------------------------------------------------------
42+
|
43+
| You can overwrite where is located your lang folder
44+
| If null or missing, Localization::Missing will search :
45+
| - first in app_path() . DIRECTORY_SEPARATOR . 'lang',
46+
| - then in app_path() . DIRECTORY_SEPARATOR . 'resources' . DIRECTORY_SEPARATOR . 'lang',
47+
|
48+
*/
49+
'lang_folder_path' => null,
50+
51+
52+
/*
53+
|--------------------------------------------------------------------------
54+
| Methods or functions to search for
55+
|--------------------------------------------------------------------------
56+
|
57+
| Localization::Missing will search lemmas by using these regular expressions
58+
| Several regular expressions can be used for a single method or function.
59+
|
60+
*/
61+
'trans_methods' => array(
62+
'trans' => array(
63+
'@trans\(\s*(\'.*\')\s*(,.*)*\)@U',
64+
'@trans\(\s*(".*")\s*(,.*)*\)@U',
65+
),
66+
'Lang::Get' => array(
67+
'@Lang::Get\(\s*(\'.*\')\s*(,.*)*\)@U',
68+
'@Lang::Get\(\s*(".*")\s*(,.*)*\)@U',
69+
'@Lang::get\(\s*(\'.*\')\s*(,.*)*\)@U',
70+
'@Lang::get\(\s*(".*")\s*(,.*)*\)@U',
71+
),
72+
'trans_choice' => array(
73+
'@trans_choice\(\s*(\'.*\')\s*,.*\)@U',
74+
'@trans_choice\(\s*(".*")\s*,.*\)@U',
75+
),
76+
'Lang::choice' => array(
77+
'@Lang::choice\(\s*(\'.*\')\s*,.*\)@U',
78+
'@Lang::choice\(\s*(".*")\s*,.*\)@U',
79+
),
80+
'@lang' => array(
81+
'@\@lang\(\s*(\'.*\')\s*(,.*)*\)@U',
82+
'@\@lang\(\s*(".*")\s*(,.*)*\)@U',
83+
),
84+
'@choice' => array(
85+
'@\@choice\(\s*(\'.*\')\s*,.*\)@U',
86+
'@\@choice\(\s*(".*")\s*,.*\)@U',
87+
),
88+
),
89+
90+
91+
/*
92+
|--------------------------------------------------------------------------
93+
| Keywords for obsolete check
94+
|--------------------------------------------------------------------------
95+
|
96+
| Localization::Missing will search lemmas in existing lang files.
97+
| Then it searches in all PHP source files.
98+
| When using dynamic or auto-generated lemmas, you must tell Localization::Missing
99+
| that there are dynamic because it cannot guess them.
100+
|
101+
| Example :
102+
| - in PHP blade code : <span>{{{ trans( "message.user.dynamo.$s" ) }}}</span>
103+
| - in lang/en.message.php :
104+
| - 'user' => array(
105+
| 'dynamo' => array(
106+
| 'lastname' => 'Family name',
107+
| 'firstname' => 'Name',
108+
| 'email' => 'Email address',
109+
| ...
110+
| Then you can define in this parameter value dynamo for example so that
111+
| Localization::Missing will not exclude lastname, firstname and email from
112+
| translation files.
113+
|
114+
*/
115+
'never_obsolete_keys' => array(
116+
'dynamic' ,
117+
'fields' ,
118+
),
119+
120+
121+
/*
122+
|--------------------------------------------------------------------------
123+
| Editor
124+
|--------------------------------------------------------------------------
125+
|
126+
| when using option editor, package will use this command to open your files
127+
|
128+
*/
129+
'editor_command_line' => '/Applications/Sublime\\ Text.app/Contents/SharedSupport/bin/subl'
130+
131+
);

0 commit comments

Comments
 (0)