From ffeaba6fbbd0dcd2afe58304ff287339744a774d Mon Sep 17 00:00:00 2001 From: overtrue Date: Wed, 28 Apr 2021 11:54:03 +0800 Subject: [PATCH 01/11] 5.x --- src/FileLoader.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/FileLoader.php b/src/FileLoader.php index c444e8a..6f106bf 100644 --- a/src/FileLoader.php +++ b/src/FileLoader.php @@ -40,6 +40,8 @@ public function load($locale, $group, $namespace = null) { $defaults = []; + $locale = str_replace('-', '_', $locale); + foreach ($this->paths as $path) { $defaults = array_replace_recursive($defaults, $this->loadPath($path, $locale, $group)); } From 30133b4b97a43368949ca48985cd04968d50ba40 Mon Sep 17 00:00:00 2001 From: overtrue Date: Wed, 28 Apr 2021 11:56:56 +0800 Subject: [PATCH 02/11] require 8.x --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index c2c81aa..3270d77 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,7 @@ "overtrue" ], "require": { - "laravel-lang/lang": "^7.0", + "laravel-lang/lang": "^8.0", "symfony/process": "^5.0.0", "ext-json": "*" }, @@ -39,4 +39,4 @@ "check-style": "php-cs-fixer fix --using-cache=no --diff --config=.php_cs --dry-run --ansi", "fix-style": "php-cs-fixer fix --using-cache=no --config=.php_cs --ansi" } -} +} \ No newline at end of file From ac84d724691d3ec70d8114ba8a6f52c1cad05910 Mon Sep 17 00:00:00 2001 From: overtrue Date: Wed, 28 Apr 2021 12:06:35 +0800 Subject: [PATCH 03/11] add docs. --- README.md | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 75aa664..5bd4dd5 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,6 @@ Total Downloads License

- # Features - Laravel 5+ && Lumen support. @@ -16,21 +15,16 @@ # Install -```shell -$ composer require "overtrue/laravel-lang:~3.0" -``` - -#### Laravel 5.* - -After completion of the above, Replace the `config/app.php` content - -```php -Illuminate\Translation\TranslationServiceProvider::class, -``` -with: +| Laravel version | Composer command | +| --------------- | --------------------------------------------- | +| 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` | -```php -Overtrue\LaravelLang\TranslationServiceProvider::class, +```shell +$ composer require "overtrue/laravel-lang:~5.0" ``` #### Lumen @@ -44,6 +38,7 @@ $app->register(Overtrue\LaravelLang\TranslationServiceProvider::class); # Configuration ### Laravel + you can change the locale at `config/app.php`: ```php @@ -62,7 +57,7 @@ APP_LOCALE=zh_CN 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 @@ -78,6 +73,7 @@ return [ 'email_has_registed' => '邮箱 :email 已经注册过!', ]; ``` + Used in the template: ```php From 471d59af70d7e9515986267fb864233afd65c524 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Thu, 29 Apr 2021 19:31:26 +0000 Subject: [PATCH 04/11] Upgrade to GitHub-native Dependabot --- .github/dependabot.yml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 .github/dependabot.yml 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 From 998e60218d547f88dfb92b39eedae31224ea2967 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 2 Jun 2021 21:12:06 +0000 Subject: [PATCH 05/11] Update laravel-lang/lang requirement from ^8.0 to ^10.1 Updates the requirements on [laravel-lang/lang](https://github.com/Laravel-Lang/lang) to permit the latest version. - [Release notes](https://github.com/Laravel-Lang/lang/releases) - [Changelog](https://github.com/Laravel-Lang/lang/blob/master/docs/changelog.md) - [Commits](https://github.com/Laravel-Lang/lang/compare/8.0.0...10.1.0) --- updated-dependencies: - dependency-name: laravel-lang/lang dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 3270d77..58a712d 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,7 @@ "overtrue" ], "require": { - "laravel-lang/lang": "^8.0", + "laravel-lang/lang": "^10.1", "symfony/process": "^5.0.0", "ext-json": "*" }, From 8aaca30aabfad979c31ed5333c76cde3e26bd4d1 Mon Sep 17 00:00:00 2001 From: suyaqi Date: Fri, 20 Aug 2021 17:39:53 +0800 Subject: [PATCH 06/11] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20laravel-lang/?= =?UTF-8?q?lang:10x=20=E7=89=88=E6=9C=AC=E7=9B=AE=E5=BD=95=E7=BB=93?= =?UTF-8?q?=E6=9E=84=E5=8F=98=E6=9B=B4=E5=AF=BC=E8=87=B4=E7=9A=84=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E7=BF=BB=E8=AF=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Commands/Publish.php | 12 ++++---- src/FileLoader.php | 48 ++++++++++++++++++++++++++++++ src/TranslationServiceProvider.php | 4 +-- 3 files changed, 57 insertions(+), 7 deletions(-) diff --git a/src/Commands/Publish.php b/src/Commands/Publish.php index 85c58f9..7b473cd 100644 --- a/src/Commands/Publish.php +++ b/src/Commands/Publish.php @@ -37,8 +37,8 @@ public function handle() $locale = \str_replace('-', '_', $this->argument('locales')); $force = $this->option('force') ? 'f' : 'n'; - $sourcePath = base_path('vendor/laravel-lang/lang/src'); - $sourceJsonPath = base_path('vendor/laravel-lang/lang/json'); + $sourcePath = base_path('vendor/laravel-lang/lang/locales'); + $sourceJsonPath = base_path('vendor/laravel-lang/lang/locales'); $targetPath = base_path('resources/lang/'); if (!is_dir($targetPath) && !mkdir($targetPath)) { @@ -53,7 +53,7 @@ public function handle() if ('all' == $locale) { $files = [ \addslashes($sourcePath).'/*', - escapeshellarg($sourceJsonPath), + \addslashes($sourceJsonPath).'/*/*.json', ]; $message = 'all'; $copyEnFiles = true; @@ -64,8 +64,10 @@ public function handle() continue; } - $file = $sourcePath.'/'.trim($filename); - $jsonFile = $sourceJsonPath.'/'.trim($filename).'.json'; + + $trimFilename = trim($filename); + $file = $sourcePath.'/'.$trimFilename; + $jsonFile = $sourceJsonPath."/{$trimFilename}/{$trimFilename}".'.json'; if (!file_exists($file)) { $this->error("'$filename' not found."); diff --git a/src/FileLoader.php b/src/FileLoader.php index 6f106bf..e793e00 100644 --- a/src/FileLoader.php +++ b/src/FileLoader.php @@ -5,6 +5,7 @@ use Illuminate\Support\Str; use Illuminate\Filesystem\Filesystem; use Illuminate\Translation\FileLoader as LaravelTranslationFileLoader; +use RuntimeException; class FileLoader extends LaravelTranslationFileLoader { @@ -13,6 +14,11 @@ class FileLoader extends LaravelTranslationFileLoader */ protected $paths; + /** + * @var string[] + */ + protected $customJsonPaths = []; + /** * Create a new file loader instance. * @@ -68,4 +74,46 @@ protected function loadPath($path, $locale, $group) return $result; } + + /** + * Add a new JSON path to the loader. + * + * @param string $path + * @return void + */ + public function addJsonPath($path) + { + $this->customJsonPaths[] = $path; + parent::addJsonPath($path); + } + + /** + * Load a locale from the given JSON file path. + * + * @param string $locale + * @return array + * + * @throws RuntimeException + */ + protected function loadJsonPaths($locale) + { + return collect(array_merge($this->jsonPaths, [$this->path])) + ->reduce(function ($output, $path) use ($locale) { + if (in_array($path, $this->customJsonPaths)) { + $locale = "{$locale}/{$locale}"; + } + + if ($this->files->exists($full = "{$path}/{$locale}.json")) { + $decoded = json_decode($this->files->get($full), true); + + if (is_null($decoded) || json_last_error() !== JSON_ERROR_NONE) { + throw new RuntimeException("Translation file [{$full}] contains an invalid JSON structure."); + } + + $output = array_merge($output, $decoded); + } + + return $output; + }, []); + } } diff --git a/src/TranslationServiceProvider.php b/src/TranslationServiceProvider.php index 4073c44..bd0f2ed 100644 --- a/src/TranslationServiceProvider.php +++ b/src/TranslationServiceProvider.php @@ -46,7 +46,7 @@ protected function registerLoader() { $this->app->singleton('translation.loader', function ($app) { $paths = [ - base_path('vendor/laravel-lang/lang/src/'), + base_path('vendor/laravel-lang/lang/locales/'), ]; if ($this->inLumen) { @@ -57,7 +57,7 @@ protected function registerLoader() $loader = new FileLoader($app['files'], $app['path.lang'], $paths); if (\is_callable([$loader, 'addJsonPath'])) { - $loader->addJsonPath(base_path('vendor/laravel-lang/lang/json/')); + $loader->addJsonPath(base_path('vendor/laravel-lang/lang/locales/')); } return $loader; From da3b2c34aa5241c9ca7d2efe7deaa48458ff3089 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=89=E6=AD=A3=E8=B6=85?= Date: Tue, 2 Nov 2021 11:26:38 +0800 Subject: [PATCH 07/11] Update FUNDING.yml --- .github/FUNDING.yml | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index a3be7fa..5ea9ebf 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -1,9 +1 @@ -# These are supported funding model platforms - -github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] -patreon: overtrue -open_collective: # Replace with a single Open Collective username -ko_fi: # Replace with a single Ko-fi username -tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel -community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry -custom: # Replace with a single custom sponsorship URL +github: [overtrue] From bd4ed62569a968a25098daeb373ca981fbcf5847 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=89=E6=AD=A3=E8=B6=85?= Date: Wed, 3 Nov 2021 19:53:37 +0800 Subject: [PATCH 08/11] Update README.md --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 5bd4dd5..1bd6df2 100644 --- a/README.md +++ b/README.md @@ -110,6 +110,12 @@ examples: $ php artisan lang:publish zh_CN,zh_HK,th,tk ``` +## :heart: Sponsor me + +If you like the work I do and want to support it, [you know what to do :heart:](https://github.com/sponsors/overtrue) + +如果你喜欢我的项目并想支持它,[点击这里 :heart:](https://github.com/sponsors/overtrue) + ## PHP 扩展包开发 > 想知道如何从零开始构建 PHP 扩展包? From 58929511da635c06982235fee7d72056a1383be5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=89=E6=AD=A3=E8=B6=85?= Date: Thu, 18 Nov 2021 12:52:47 +0800 Subject: [PATCH 09/11] Update README.md --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1bd6df2..49319db 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,8 @@ - Translations Publisher. - Made with 💖. +[![Sponsor me](https://raw.githubusercontent.com/overtrue/overtrue/master/sponsor-me-button-s.svg)](https://github.com/sponsors/overtrue) + # Install | Laravel version | Composer command | @@ -112,7 +114,7 @@ $ php artisan lang:publish zh_CN,zh_HK,th,tk ## :heart: Sponsor me -If you like the work I do and want to support it, [you know what to do :heart:](https://github.com/sponsors/overtrue) +[![Sponsor me](https://raw.githubusercontent.com/overtrue/overtrue/master/sponsor-me.svg)](https://github.com/sponsors/overtrue) 如果你喜欢我的项目并想支持它,[点击这里 :heart:](https://github.com/sponsors/overtrue) From 7a2e728f147293befe273fe041e584d5cee47eaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=89=E6=AD=A3=E8=B6=85?= Date: Tue, 23 Nov 2021 09:59:53 +0800 Subject: [PATCH 10/11] Update README.md --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index 49319db..c4ca242 100644 --- a/README.md +++ b/README.md @@ -118,6 +118,13 @@ $ php artisan lang:publish zh_CN,zh_HK,th,tk 如果你喜欢我的项目并想支持它,[点击这里 :heart:](https://github.com/sponsors/overtrue) + +## Project supported by JetBrains + +Many thanks to Jetbrains for kindly providing a license for me to work on this and other open-source projects. + +[![](https://resources.jetbrains.com/storage/products/company/brand/logos/jb_beam.svg)](https://www.jetbrains.com/?from=https://github.com/overtrue) + ## PHP 扩展包开发 > 想知道如何从零开始构建 PHP 扩展包? From 9afd6b3f99e34583927df95ff01782ab592d942c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=89=E6=AD=A3=E8=B6=85?= Date: Wed, 1 Dec 2021 00:05:56 +0800 Subject: [PATCH 11/11] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c4ca242..5ec3297 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ - Translations Publisher. - Made with 💖. -[![Sponsor me](https://raw.githubusercontent.com/overtrue/overtrue/master/sponsor-me-button-s.svg)](https://github.com/sponsors/overtrue) +[![Sponsor me](https://github.com/overtrue/overtrue/blob/master/sponsor-me-button-s.svg?raw=true)](https://github.com/sponsors/overtrue) # Install @@ -114,7 +114,7 @@ $ php artisan lang:publish zh_CN,zh_HK,th,tk ## :heart: Sponsor me -[![Sponsor me](https://raw.githubusercontent.com/overtrue/overtrue/master/sponsor-me.svg)](https://github.com/sponsors/overtrue) +[![Sponsor me](https://github.com/overtrue/overtrue/blob/master/sponsor-me.svg?raw=true)](https://github.com/sponsors/overtrue) 如果你喜欢我的项目并想支持它,[点击这里 :heart:](https://github.com/sponsors/overtrue)