From fe5db1837b775215150296ef5ad510658611cd8f Mon Sep 17 00:00:00 2001
From: kenjis <kenji.uui@gmail.com>
Date: Tue, 7 Nov 2023 20:35:37 +0900
Subject: [PATCH] fix: replace {locale} with default locale in
 SampleURIGenerator

---
 system/Commands/Utilities/Routes/SampleURIGenerator.php  | 9 +++++++++
 .../Commands/Utilities/Routes/SampleURIGeneratorTest.php | 2 ++
 2 files changed, 11 insertions(+)

diff --git a/system/Commands/Utilities/Routes/SampleURIGenerator.php b/system/Commands/Utilities/Routes/SampleURIGenerator.php
index 38b333fd33c2..43d1934438bb 100644
--- a/system/Commands/Utilities/Routes/SampleURIGenerator.php
+++ b/system/Commands/Utilities/Routes/SampleURIGenerator.php
@@ -13,6 +13,7 @@
 
 use CodeIgniter\Config\Services;
 use CodeIgniter\Router\RouteCollection;
+use Config\App;
 
 /**
  * Generate a sample URI path from route key regex.
@@ -51,6 +52,14 @@ public function get(string $routeKey): string
     {
         $sampleUri = $routeKey;
 
+        if (strpos($routeKey, '{locale}') !== false) {
+            $sampleUri = str_replace(
+                '{locale}',
+                config(App::class)->defaultLocale,
+                $routeKey
+            );
+        }
+
         foreach ($this->routes->getPlaceholders() as $placeholder => $regex) {
             $sample = $this->samples[$placeholder] ?? '::unknown::';
 
diff --git a/tests/system/Commands/Utilities/Routes/SampleURIGeneratorTest.php b/tests/system/Commands/Utilities/Routes/SampleURIGeneratorTest.php
index 4f7d6221665d..5f490be437e1 100644
--- a/tests/system/Commands/Utilities/Routes/SampleURIGeneratorTest.php
+++ b/tests/system/Commands/Utilities/Routes/SampleURIGeneratorTest.php
@@ -40,6 +40,8 @@ public static function provideGet(): iterable
             'placeholder num'     => ['shop/product/([0-9]+)', 'shop/product/123'],
             'placeholder segment' => ['shop/product/([^/]+)', 'shop/product/abc_123'],
             'placeholder any'     => ['shop/product/(.*)', 'shop/product/123/abc'],
+            'locale'              => ['{locale}/home', 'en/home'],
+            'locale segment'      => ['{locale}/product/([^/]+)', 'en/product/abc_123'],
             'auto route'          => ['home/index[/...]', 'home/index/1/2/3/4/5'],
         ];
     }