diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..5ea9ebf --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1 @@ +github: [overtrue] diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..c67cb49 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,15 @@ +version: 2 +updates: +- package-ecosystem: composer + directory: "/" + schedule: + interval: daily + time: "21:00" + open-pull-requests-limit: 10 + ignore: + - dependency-name: laravel-lang/lang + versions: + - 8.0.0 + - 8.1.0 + - 9.0.0 + - 9.1.0 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d5b2f67 --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +*.DS_Store +/vendor +sftp-config.json +/*.php +/.idea +/coverage +/.split +/composer.lock +.php_cs.cache \ No newline at end of file diff --git a/.php_cs b/.php_cs deleted file mode 100755 index 18254c1..0000000 --- a/.php_cs +++ /dev/null @@ -1,27 +0,0 @@ - - -This source file is subject to the MIT license that is bundled -with this source code in the file LICENSE. -EOF; - -Symfony\CS\Fixer\Contrib\HeaderCommentFixer::setHeader($header); - -return Symfony\CS\Config\Config::create() - // use default SYMFONY_LEVEL and extra fixers: - ->fixers(array( - 'header_comment', - 'short_array_syntax', - 'ordered_use', - 'php_unit_construct', - 'strict_param', - )) - ->finder( - Symfony\CS\Finder\DefaultFinder::create() - ->in(__DIR__.'/src') - ) -; \ No newline at end of file diff --git a/README.md b/README.md index d77b0a3..318dbac 100644 --- a/README.md +++ b/README.md @@ -1,39 +1,35 @@ -# Laravel-lang - -52 languages support for Laravel 5 application based on [caouecs/Laravel-lang](https://github.com/caouecs/Laravel-lang). - -[中文说明](README_CN.md) - -[![For Laravel 5][badge_laravel]][link-github-repo] -[![For Lumen 5][badge_lumen]][link-github-repo] -[![Latest Stable Version][badge_stable]][link-packagist] -[![Latest Unstable Version][badge_unstable]][link-packagist] -[![Total Downloads][badge_downloads]][link-packagist] -[![License][badge_license]][link-packagist] +
75 languages support for Laravel application based on Laravel-Lang/lang. +
+ +> **Warning** +> +> There is already a better solution to use [our official Laravel-Lang publisher](https://publisher.laravel-lang.com/). This project will be discontinued, thank you for your support. # Features -- Laravel 5 & Lumen support. +- Laravel 5+ && Lumen support. - Translations Publisher. - Made with 💖. # Install -```shell -$ composer require "overtrue/laravel-lang:~3.0" -``` - -#### Laraval 5.* +| Laravel version | Composer command | +| --------------- | --------------------------------------------- | +| Laravel 9.x | `composer require overtrue/laravel-lang:~6.0` | +| Laravel 7.x-8.x | `composer require overtrue/laravel-lang:~5.0` | +| Laravel 6.x | `composer require overtrue/laravel-lang:~4.0` | +| Laravel 5.8 | `composer require overtrue/laravel-lang:~3.0` | +| Laravel 5.1-5.7 | `composer require overtrue/laravel-lang:~2.0` | +| Laravel 5 | `composer require overtrue/laravel-lang:~1.0` | -After completion of the above, Replace the `config/app.php` content - -```php -Illuminate\Translation\TranslationServiceProvider::class, -``` -with: - -```php -Overtrue\LaravelLang\TranslationServiceProvider::class, +```shell +composer require "overtrue/laravel-lang:~6.0" ``` #### Lumen @@ -47,10 +43,11 @@ $app->register(Overtrue\LaravelLang\TranslationServiceProvider::class); # Configuration ### Laravel + you can change the locale at `config/app.php`: ```php -'locale' => 'zh-CN', +'locale' => 'zh_CN', ``` ### Lumen @@ -58,20 +55,20 @@ you can change the locale at `config/app.php`: set locale in `.env` file: ``` -APP_LOCALE=zh-CN +APP_LOCALE=zh_CN ``` # Usage There is no difference with the usual usage. -If you need to add additional language content, Please create a file in the `resources/lang/{LANGUAGE}` directory. +If you need to add additional language content, Please create a file in the `resources/lang/{LANGUAGE}` directory. ### Add custom language items Here, for example in Chinese: -`resources/lang/zh-CN/demo.php`: +`resources/lang/zh_CN/demo.php`: ```php '邮箱 :email 已经注册过!', ]; ``` + Used in the template: ```php @@ -93,7 +91,7 @@ echo trans('demo.email_has_registed', ['email' => 'anzhengchao@gmail.com']); We assume that want to replace the `password.reset` message: -`resources/lang/zh-CN/passwords.php`: +`resources/lang/zh_CN/passwords.php`: ```php 想知道如何从零开始构建 PHP 扩展包? +> +> 请关注我的实战课程,我会在此课程中分享一些扩展开发经验 —— [《PHP 扩展包实战教程 - 从入门到发布》](https://learnku.com/courses/creating-package) + +# License + +MIT diff --git a/README_CN.md b/README_CN.md deleted file mode 100644 index 1993dc3..0000000 --- a/README_CN.md +++ /dev/null @@ -1,129 +0,0 @@ -# Laravel-lang - -Laravel 5 语言包,包含 52 种语言, 基于 [caouecs/Laravel-lang](https://github.com/caouecs/Laravel-lang). - -[![For Laravel 5][badge_laravel]][link-github-repo] -[![For Lumen 5][badge_lumen]][link-github-repo] -[![Latest Stable Version][badge_stable]][link-packagist] -[![Latest Unstable Version][badge_unstable]][link-packagist] -[![Total Downloads][badge_downloads]][link-packagist] -[![License][badge_license]][link-packagist] - -# Features - -- Laravel 5 & Lumen support. -- Translations Publisher. -- Made with 💖. - -# 安装 - -```shell -composer require "overtrue/laravel-lang:~3.0" -``` - -#### Laraval 5.* - -完成上面的操作后,将项目文件 `config/app.php` 中的下一行 - -```php -Illuminate\Translation\TranslationServiceProvider::class, -``` - -替换为: - -```php -Overtrue\LaravelLang\TranslationServiceProvider::class, -``` - -#### Lumen - -在 `bootstrap/app.php` 中添加下面这行: - -```php -$app->register(Overtrue\LaravelLang\TranslationServiceProvider::class); -``` - -# 配置 - -### Laravel - -修改项目语言 `config/app.php`: - -```php -'locale' => 'zh-CN', -``` - -### Lumen - -在 `.env` 文件中修改语言: -``` -APP_LOCALE=zh-CN -``` - - - -# 使用 - -和正常使用一样,你如果需要额外添加语言项,请在 `resources/lang/zh-CN/` 下建立你自己的文件即可,也可以建立同样的文件来替换掉默认的语言部分。 - -### 添加自定义语言项 - -例如创建文件 `resources/lang/zh-CN/demo.php`: - -```php - '用户不存在', - 'email_has_registed' => '邮箱 :email 已经注册过!', -]; -``` -然后在任何地方: - -```php -echo trans('demo.user_not_exists'); // 用户不存在 -echo trans('demo.email_has_registed', ['email' => 'anzhengchao@gmail.com']); -// 邮箱 anzhengchao@gmail.com 已经注册过! -``` - -### 替换掉默认的语言项 - -我们假设想替换掉密码重围成功的提示文字为例,创建 `resources/lang/zh-CN/passwords.php`: - -```php - '您的密码已经重置成功了,你可以使用新的密码登录了!', -]; -``` - -只放置你需要替换的部分即可。 - - -### 将翻译文件拷贝到你的项目 `resources/lang/` 目录下: - -```shell -$ php artisan lang:publish LOCALES {--force} -``` - -examples: - -```shell -$ php artisan lang:publish zh-CN,zh-HK,th,tk -``` - -# License - -MIT - - -[badge_laravel]: https://img.shields.io/badge/laravel-5.*-green.svg -[badge_lumen]: https://img.shields.io/badge/lumen-5.*-green.svg -[badge_stable]: https://img.shields.io/packagist/v/overtrue/laravel-lang.svg -[badge_unstable]: https://img.shields.io/packagist/vpre/overtrue/laravel-lang.svg -[badge_downloads]: https://img.shields.io/packagist/dt/overtrue/laravel-lang.svg?maxAge=2592000 -[badge_license]: https://img.shields.io/packagist/l/overtrue/laravel-lang.svg?maxAge=2592000 - -[link-github-repo]: https://github.com/overtrue/laravel-lang -[link-packagist]: https://packagist.org/packages/overtrue/laravel-lang \ No newline at end of file diff --git a/composer.json b/composer.json index d4513b1..c63efee 100644 --- a/composer.json +++ b/composer.json @@ -1,25 +1,58 @@ { - "name": "overtrue/laravel-lang", - "description": "List of 52 languages for Laravel 5", - "keywords": [ - "laravel", - "languages", - "overtrue" + "name": "overtrue/laravel-lang", + "description": "List of 75 languages for Laravel.", + "keywords": [ + "laravel", + "languages", + "i18n", + "locale", + "overtrue" + ], + "require": { + "laravel-lang/lang": "^10.4", + "symfony/process": "^6.0", + "ext-json": "*" + }, + "autoload": { + "psr-4": { + "Overtrue\\LaravelLang\\": "src/" + } + }, + "license": "MIT", + "authors": [ + { + "name": "overtrue", + "email": "anzhengchao@gmail.com" + } + ], + "extra": { + "laravel": { + "providers": [ + "Overtrue\\LaravelLang\\TranslationServiceProvider" + ] + } + }, + "require-dev": { + "laravel/framework": "^9.0" + }, + "scripts": { + "post-update-cmd": [ + "cghooks remove", + "cghooks add --ignore-lock", + "cghooks update" ], - "require": { - "caouecs/laravel-lang": "~3.0" - }, - "autoload": { - "psr-4": { - "Overtrue\\LaravelLang\\": "src/" - }, - "files": ["src/helpers.php"] - }, - "license": "MIT", - "authors": [ - { - "name": "overtrue", - "email": "anzhengchao@gmail.com" - } - ] + "post-merge": "composer install", + "post-install-cmd": [ + "cghooks remove", + "cghooks add --ignore-lock", + "cghooks update" + ], + "cghooks": "vendor/bin/cghooks", + "check-style": "php-cs-fixer fix --using-cache=no --diff --dry-run --ansi", + "fix-style": "php-cs-fixer fix --using-cache=no --ansi" + }, + "scripts-descriptions": { + "check-style": "Run style checks (only dry run - no fixing!).", + "fix-style": "Run style checks and fix violations." + } } diff --git a/src/Commands/Publish.php b/src/Commands/Publish.php index 647ecbb..e9be64c 100644 --- a/src/Commands/Publish.php +++ b/src/Commands/Publish.php @@ -1,14 +1,5 @@ - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - namespace Overtrue\LaravelLang\Commands; use Illuminate\Console\Command; @@ -16,12 +7,21 @@ class Publish extends Command { + /** + * @var string + */ protected $signature = 'lang:publish {locales=all : Comma-separated list of, eg: zh_CN,tk,th} {--force : override existing files.}'; + /** + * @var string + */ protected $description = 'publish language files to resources directory.'; + /** + * Publish constructor. + */ public function __construct() { parent::__construct(); @@ -30,56 +30,86 @@ public function __construct() /** * Execute the console command. * - * @return mixed + * @return void */ public function handle() { - $locale = $this->argument('locales'); + $locale = \str_replace('-', '_', $this->argument('locales')); $force = $this->option('force') ? 'f' : 'n'; - $sourcePath = base_path('vendor/caouecs/laravel-lang/src'); - $targetPath = base_path('resources/lang/'); + $sourcePath = base_path('vendor/laravel-lang/lang/locales'); + $sourceJsonPath = base_path('vendor/laravel-lang/lang/locales'); + $targetPath = function_exists('lang_path') ? lang_path() : base_path('lang'); - if (!is_dir($targetPath) || !is_writable($targetPath)) { - return $this->error('The lang path "resources/lang/" does not exist or not writable.'); + if (!is_dir($targetPath) && !mkdir($targetPath)) { + $this->error('The lang path "lang" does not exist or not writable.'); + return; } $files = []; $published = []; - - if ($locale == 'all') { - $files = $sourcePath.'/*'; + $copyEnFiles = false; + $inLumen = $this->laravel instanceof \Laravel\Lumen\Application; + + if ('all' == $locale) { + $files = [ + \addslashes($sourcePath).'/*', + \addslashes($sourceJsonPath).'/*/*.json', + ]; $message = 'all'; + $copyEnFiles = true; } else { foreach (explode(',', $locale) as $filename) { - $file = $sourcePath.'/'.trim($filename); + if ('en' === $locale) { + $copyEnFiles = true; + + continue; + } + + $trimFilename = trim($filename); + $file = $sourcePath.'/'.$trimFilename; + $jsonFile = $sourceJsonPath."/{$trimFilename}/{$trimFilename}".'.json'; if (!file_exists($file)) { - $this->error("lang '$filename' not found."); + $this->error("'$filename' not found."); + continue; } $published[] = $filename; - $files[] = $file; + $files[] = escapeshellarg($file); + + if (!file_exists($jsonFile)) { + $this->error("'$filename' not found."); + + continue; + } + $files[] = escapeshellarg($jsonFile); } if (empty($files)) { return; } - $files = implode(' ', $files); $message = json_encode($published); } - $process = new Process("cp -r{$force} $files $targetPath"); + if ($inLumen && $copyEnFiles) { + $files[] = escapeshellarg(base_path('vendor/laravel/lumen-framework/resources/lang/en')); + } + + $files = implode(' ', $files); + $targetPath = escapeshellarg($targetPath); + $command = "cp -r{$force} {$files} {$targetPath}"; + $process = \method_exists(Process::class, 'fromShellCommandline') ? Process::fromShellCommandline($command) : new Process([$command]); $process->run(function ($type, $buffer) { if (Process::ERR === $type) { - return $this->error(trim($buffer)); + $this->error(trim($buffer)); } }); - $type = ($force == 'f') ? 'overwrite' : 'no overwrite'; + $type = ('f' == $force) ? 'overwrite' : 'no overwrite'; $this->info("published languages