Skip to content

Commit 30791a7

Browse files
committed
Merge pull request overtrue#5 from overtrue/v2.1
V 3
2 parents e44412b + 0652562 commit 30791a7

File tree

8 files changed

+340
-56
lines changed

8 files changed

+340
-56
lines changed

.php_cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
$header = <<<EOF
4+
This file is part of the overtrue/laravel-lang.
5+
6+
(c) overtrue <[email protected]>
7+
8+
This source file is subject to the MIT license that is bundled
9+
with this source code in the file LICENSE.
10+
EOF;
11+
12+
Symfony\CS\Fixer\Contrib\HeaderCommentFixer::setHeader($header);
13+
14+
return Symfony\CS\Config\Config::create()
15+
// use default SYMFONY_LEVEL and extra fixers:
16+
->fixers(array(
17+
'header_comment',
18+
'short_array_syntax',
19+
'ordered_use',
20+
'php_unit_construct',
21+
'strict_param',
22+
))
23+
->finder(
24+
Symfony\CS\Finder\DefaultFinder::create()
25+
->in(__DIR__.'/src')
26+
)
27+
;

README.md

Lines changed: 49 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,27 @@
44

55
[中文说明](README_CN.md)
66

7-
[![Latest Stable Version](https://poser.pugx.org/overtrue/laravel-lang/v/stable.svg)](https://packagist.org/packages/overtrue/laravel-lang) [![Total Downloads](https://poser.pugx.org/overtrue/laravel-lang/downloads.svg)](https://packagist.org/packages/overtrue/laravel-lang) [![Latest Unstable Version](https://poser.pugx.org/overtrue/laravel-lang/v/unstable.svg)](https://packagist.org/packages/overtrue/laravel-lang) [![License](https://poser.pugx.org/overtrue/laravel-lang/license.svg)](https://packagist.org/packages/overtrue/laravel-lang)
7+
[![For Laravel 5][badge_laravel]][link-github-repo]
8+
[![For Lumen 5][badge_lumen]][link-github-repo]
9+
[![Latest Stable Version][badge_stable]][link-packagist]
10+
[![Latest Unstable Version][badge_unstable]][link-packagist]
11+
[![Total Downloads][badge_downloads]][link-packagist]
12+
[![License][badge_license]][link-packagist]
813

9-
## Install
14+
# Features
15+
16+
- Laravel 5 & Lumen support.
17+
- Translations Publisher.
18+
- Made with 💖.
19+
20+
# Install
1021

1122
```shell
12-
$ composer require "overtrue/laravel-lang:~2.0"
23+
$ composer require "overtrue/laravel-lang:~2.1"
1324
```
1425

26+
#### Laraval 5.*
27+
1528
After completion of the above, Replace the `config/app.php` content
1629

1730
```php
@@ -23,15 +36,32 @@ with:
2336
Overtrue\LaravelLang\TranslationServiceProvider::class,
2437
```
2538

26-
## Configuration
39+
#### Lumen
40+
41+
Add the following line to `bootstrap/app.php`:
42+
43+
```php
44+
$app->register(Overtrue\LaravelLang\TranslationServiceProvider::class);
45+
```
46+
47+
# Configuration
2748

49+
### Laravel
2850
you can change the locale at `config/app.php`:
2951

3052
```php
3153
'locale' => 'zh-CN',
3254
```
3355

34-
## Usage
56+
### Lumen
57+
58+
set locale in `.env` file:
59+
60+
```
61+
APP_LOCALE=zh-CN
62+
```
63+
64+
# Usage
3565

3666
There is no difference with the usual usage.
3767

@@ -78,15 +108,25 @@ You need only add the partials item what you want.
78108
### publish the language files to your project `resources/lang/` directory:
79109

80110
```shell
81-
$ php artisan vendor:publish --provider="Overtrue\LaravelLang\TranslationServiceProvider" --tag=resouece
111+
$ php artisan lang:publish LOCALES {--force}
82112
```
83113

84-
or force publish(will overwrite old files):
114+
examples:
85115

86116
```shell
87-
$ php artisan vendor:publish --provider="Overtrue\LaravelLang\TranslationServiceProvider" --tag=resource --force
117+
$ php artisan lang:publish zh-CN,zh-HK,th,tk
88118
```
89119

90-
## License
120+
# License
91121

92122
MIT
123+
124+
[badge_laravel]: https://img.shields.io/badge/laravel-5.*-green.svg
125+
[badge_lumen]: https://img.shields.io/badge/lumen-5.*-green.svg
126+
[badge_stable]: https://img.shields.io/packagist/v/overtrue/laravel-lang.svg
127+
[badge_unstable]: https://img.shields.io/packagist/vpre/overtrue/laravel-lang.svg
128+
[badge_downloads]: https://img.shields.io/packagist/dt/overtrue/laravel-lang.svg?maxAge=2592000
129+
[badge_license]: https://img.shields.io/packagist/l/overtrue/laravel-lang.svg?maxAge=2592000
130+
131+
[link-github-repo]: https://github.com/overtrue/laravel-lang
132+
[link-packagist]: https://packagist.org/packages/overtrue/laravel-lang

README_CN.md

Lines changed: 50 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,28 @@
11
# Laravel-lang
22

3-
Laravel 5 语言包,包含 46 种语言, 基于 [caouecs/Laravel-lang](https://github.com/caouecs/Laravel-lang).
3+
Laravel 5 语言包,包含 52 种语言, 基于 [caouecs/Laravel-lang](https://github.com/caouecs/Laravel-lang).
44

5-
## 安装
5+
[![For Laravel 5][badge_laravel]][link-github-repo]
6+
[![For Lumen 5][badge_lumen]][link-github-repo]
7+
[![Latest Stable Version][badge_stable]][link-packagist]
8+
[![Latest Unstable Version][badge_unstable]][link-packagist]
9+
[![Total Downloads][badge_downloads]][link-packagist]
10+
[![License][badge_license]][link-packagist]
611

7-
```shell
8-
composer require "overtrue/laravel-lang:1.0.*"
9-
```
12+
# Features
1013

11-
或者添加下面一行到你的项目 `composer.json``require` 部分:
14+
- Laravel 5 & Lumen support.
15+
- Translations Publisher.
16+
- Made with 💖.
1217

13-
```json
14-
"require": {
15-
"overtrue/laravel-lang": "1.0.*"
16-
}
17-
```
18-
然后
18+
# 安装
1919

2020
```shell
21-
composer update
21+
composer require "overtrue/laravel-lang:~2.1"
2222
```
2323

24+
#### Laraval 5.*
25+
2426
完成上面的操作后,将项目文件 `config/app.php` 中的下一行
2527

2628
```php
@@ -33,17 +35,34 @@ Illuminate\Translation\TranslationServiceProvider::class,
3335
Overtrue\LaravelLang\TranslationServiceProvider::class,
3436
```
3537

36-
即可。
38+
#### Lumen
39+
40+
`bootstrap/app.php` 中添加下面这行:
41+
42+
```php
43+
$app->register(Overtrue\LaravelLang\TranslationServiceProvider::class);
44+
```
45+
46+
# 配置
3747

38-
## 配置
48+
### Laravel
3949

4050
修改项目语言 `config/app.php`
4151

4252
```php
4353
'locale' => 'zh-CN',
4454
```
4555

46-
## 使用
56+
### Lumen
57+
58+
`.env` 文件中修改语言:
59+
```
60+
APP_LOCALE=zh-CN
61+
```
62+
63+
64+
65+
# 使用
4766

4867
和正常使用一样,你如果需要额外添加语言项,请在 `resources/lang/zh-CN/` 下建立你自己的文件即可,也可以建立同样的文件来替换掉默认的语言部分。
4968

@@ -85,15 +104,26 @@ return [
85104
### 将翻译文件拷贝到你的项目 `resources/lang/` 目录下:
86105

87106
```shell
88-
$ php artisan vendor:publish --provider="Overtrue\LaravelLang\TranslationServiceProvider" --tag=resouece
107+
$ php artisan lang:publish LOCALES {--force}
89108
```
90109

91-
当然你也可以强制拷贝(将会覆盖原有同名文件哦):
110+
examples:
92111

93112
```shell
94-
$ php artisan vendor:publish --provider="Overtrue\LaravelLang\TranslationServiceProvider" --tag=resource --force
113+
$ php artisan lang:publish zh-CN,zh-HK,th,tk
95114
```
96115

97-
## License
116+
# License
98117

99118
MIT
119+
120+
121+
[badge_laravel]: https://img.shields.io/badge/laravel-5.*-green.svg
122+
[badge_lumen]: https://img.shields.io/badge/lumen-5.*-green.svg
123+
[badge_stable]: https://img.shields.io/packagist/v/overtrue/laravel-lang.svg
124+
[badge_unstable]: https://img.shields.io/packagist/vpre/overtrue/laravel-lang.svg
125+
[badge_downloads]: https://img.shields.io/packagist/dt/overtrue/laravel-lang.svg?maxAge=2592000
126+
[badge_license]: https://img.shields.io/packagist/l/overtrue/laravel-lang.svg?maxAge=2592000
127+
128+
[link-github-repo]: https://github.com/overtrue/laravel-lang
129+
[link-packagist]: https://packagist.org/packages/overtrue/laravel-lang

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"autoload": {
1313
"psr-4": {
1414
"Overtrue\\LaravelLang\\": "src/"
15-
}
15+
},
16+
"files": ["src/helpers.php"]
1617
},
1718
"license": "MIT",
1819
"authors": [

src/Commands/Publish.php

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the overtrue/laravel-lang.
5+
*
6+
* (c) overtrue <[email protected]>
7+
*
8+
* This source file is subject to the MIT license that is bundled
9+
* with this source code in the file LICENSE.
10+
*/
11+
12+
namespace Overtrue\LaravelLang\Commands;
13+
14+
use Illuminate\Console\Command;
15+
use Symfony\Component\Process\Process;
16+
17+
class Publish extends Command
18+
{
19+
protected $signature = 'lang:publish
20+
{locales=all : Comma-separated list of, eg: zh_CN,tk,th}
21+
{--force : override existing files.}';
22+
23+
protected $description = 'publish language files to resources directory.';
24+
25+
public function __construct()
26+
{
27+
parent::__construct();
28+
}
29+
30+
/**
31+
* Execute the console command.
32+
*
33+
* @return mixed
34+
*/
35+
public function handle()
36+
{
37+
$locale = $this->argument('locales');
38+
$force = $this->option('force') ? 'f' : 'n';
39+
40+
$sourcePath = app()->basePath().'/vendor/caouecs/laravel-lang/src';
41+
$targetPath = app()->basePath().'/resources/lang/';
42+
43+
if (!is_dir($targetPath) || !is_writable($targetPath)) {
44+
return $this->error('The lang path "resources/lang/" does not exist or not writable.');
45+
}
46+
47+
$files = [];
48+
$published = [];
49+
50+
if ($locale == 'all') {
51+
$files = $sourcePath.'/*';
52+
$message = 'all';
53+
} else {
54+
foreach (explode(',', $locale) as $filename) {
55+
$file = $sourcePath.'/'.trim($filename);
56+
57+
if (!file_exists($file)) {
58+
$this->error("lang '$filename' not found.");
59+
continue;
60+
}
61+
62+
$published[] = $filename;
63+
$files[] = $file;
64+
}
65+
66+
$files = implode(' ', $files);
67+
$message = json_encode($published);
68+
}
69+
70+
$process = new Process("cp -r{$force} $files $targetPath");
71+
72+
$process->run(function ($type, $buffer) {
73+
if (Process::ERR === $type) {
74+
return $this->error(trim($buffer));
75+
}
76+
});
77+
78+
$type = ($force == 'f') ? 'no overwrite' : 'overwrite';
79+
80+
$this->info("published languages <comment>({$type})</comment>: {$message}.");
81+
}
82+
}

0 commit comments

Comments
 (0)