diff --git a/src/app/Console/Commands/TranslateShortDescriptionJapanese.php b/src/app/Console/Commands/TranslateShortDescriptionJapanese.php index e63eadf..bf97350 100644 --- a/src/app/Console/Commands/TranslateShortDescriptionJapanese.php +++ b/src/app/Console/Commands/TranslateShortDescriptionJapanese.php @@ -15,7 +15,8 @@ class TranslateShortDescriptionJapanese extends Command */ protected $signature = 'world-heritage:translate-short-description-japanese {--force : Allow execution outside local environment} - {--dry-run : Skip DB writes and API calls}'; + {--dry-run : Skip DB writes and API calls} + {--from-json : Use translation JSON instead of calling API}'; /** * The console command description. @@ -46,6 +47,23 @@ public function handle(): int $total = count($sites); $this->info("Total sites: {$total}"); + $fromJson = (bool) $this->option('from-json'); + + // Load translation map from JSON if --from-json is specified + $translationMap = []; + if ($fromJson) { + $translationPath = storage_path('app/private/unesco/world_heritage_sites_translation.json'); + if (!file_exists($translationPath)) { + $this->error("Translation JSON not found: {$translationPath}"); + return 1; + } + $translationData = json_decode(file_get_contents($translationPath), true); + foreach ($translationData['results'] as $item) { + $translationMap[$item['id_no']] = $item; + } + $this->info("Loaded translation JSON: " . count($translationMap) . " records"); + } + $bar = $this->output->createProgressBar($total); $bar->start(); @@ -59,11 +77,9 @@ public function handle(): int continue; } - // DBに翻訳済みのものがあればそこから取得してJSONに反映 - // if translated columns are existed in DB, fetching from there and reflected on Json File + // If already translated in DB, fetch from there and reflect on JSON file $record = WorldHeritageDescription::where('world_heritage_site_id', $idNo) ->whereNotNull('short_description_ja') - ->whereNotNull('description_ja') ->first(); if ($record) { @@ -73,12 +89,44 @@ public function handle(): int continue; } + // If --from-json is specified, use translation JSON instead of calling API + if ($fromJson) { + $translated = $translationMap[$idNo] ?? null; + if (!$translated) { + $this->newLine(); + $this->warn("No translation found in JSON for id_no={$idNo}, skipping."); + $bar->advance(); + continue; + } + + $shortDescriptionJa = $translated['short_description_ja'] ?? null; + $descriptionJa = $translated['description_ja'] ?? null; + + if (!$this->option('dry-run')) { + WorldHeritageDescription::updateOrCreate( + ['world_heritage_site_id' => $idNo], + [ + 'short_description_en' => $shortDescriptionEn, + 'short_description_ja' => $shortDescriptionJa, + 'description_en' => $descriptionEn, + 'description_ja' => $descriptionJa, + ] + ); + } + + $sites[$index]['short_description_ja'] = $shortDescriptionJa; + $sites[$index]['description_ja'] = $descriptionJa; + $bar->advance(); + continue; + } + if ($this->option('dry-run')) { $this->line(" [dry-run] Would translate id_no={$idNo}: " . mb_substr($shortDescriptionEn, 0, 50) . '...'); $bar->advance(); continue; } + // Call Google Translate API $texts = $shortDescriptionEn === $descriptionEn ? [$shortDescriptionEn] : [$shortDescriptionEn, $descriptionEn]; @@ -123,8 +171,9 @@ public function handle(): int $bar->finish(); $this->newLine(); + // Write translation results back to JSON as a backup if (!$this->option('dry-run')) { - $outputDir = storage_path('app/private/unesco/normalized'); + $outputDir = storage_path('app/private/unesco'); $outputPath = $outputDir . '/world_heritage_sites_translation.json'; if (!is_dir($outputDir)) { diff --git a/src/app/Console/Commands/WorldHeritageBuild.php b/src/app/Console/Commands/WorldHeritageBuild.php index 0c424da..5c23ace 100644 --- a/src/app/Console/Commands/WorldHeritageBuild.php +++ b/src/app/Console/Commands/WorldHeritageBuild.php @@ -33,7 +33,9 @@ class WorldHeritageBuild extends Command {--jp-missing-limit=200 : Max missing ids to print to console} {--algolia : Also import records into Algolia} - {--algolia-truncate : Clear Algolia index before import}'; + {--algolia-truncate : Clear Algolia index before import} + + {--translate-jp-from-json : Use translation JSON for Japanese translation}'; protected $description = 'Rebuild local DB and import UNESCO World Heritage data (dump -> split -> import)'; @@ -105,8 +107,9 @@ public function handle(): int if ((bool) $this->option('translate-jp')) { $this->callOrFail('world-heritage:translate-short-description-japanese', array_filter([ - '--force' => true, - '--dry-run' => (bool) $this->option('translate-jp-dry-run') ? true : null, + '--force' => true, + '--dry-run' => (bool) $this->option('translate-jp-dry-run') ? true : null, + '--from-json' => (bool) $this->option('translate-jp-from-json') ? true : null, ], static fn ($v) => $v !== null)); } diff --git a/src/app/Models/WorldHeritage.php b/src/app/Models/WorldHeritage.php index fba6777..d39580d 100644 --- a/src/app/Models/WorldHeritage.php +++ b/src/app/Models/WorldHeritage.php @@ -5,7 +5,7 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Illuminate\Database\Eloquent\Relations\HasMany; -use Illuminate\Database\Eloquent\Relations\BelongsTo; +use Illuminate\Database\Eloquent\Relations\HasOne; use Illuminate\Database\Eloquent\SoftDeletes; class WorldHeritage extends Model @@ -60,9 +60,9 @@ public function images(): HasMany ->orderBy('sort_order', 'asc'); } - public function descriptions(): HasMany + public function descriptions(): HasOne { - return $this->hasMany(WorldHeritageDescription::class, 'world_heritage_site_id', 'id'); + return $this->hasOne(WorldHeritageDescription::class, 'world_heritage_site_id', 'id'); } protected function casts(): array diff --git a/src/app/Models/WorldHeritageDescription.php b/src/app/Models/WorldHeritageDescription.php index 81b82ab..a747dcd 100644 --- a/src/app/Models/WorldHeritageDescription.php +++ b/src/app/Models/WorldHeritageDescription.php @@ -26,7 +26,7 @@ class WorldHeritageDescription extends Model 'updated_at', ]; - public function worldHeritageSite(): BelongsTo + public function heritageSite(): BelongsTo { return $this->belongsTo(WorldHeritage::class, 'world_heritage_site_id', 'id'); } diff --git a/src/app/Packages/Domains/Test/QueryService/WorldHeritageQueryService_getAllHeritagesTest.php b/src/app/Packages/Domains/Test/QueryService/WorldHeritageQueryService_getAllHeritagesTest.php index fe2878e..edea257 100644 --- a/src/app/Packages/Domains/Test/QueryService/WorldHeritageQueryService_getAllHeritagesTest.php +++ b/src/app/Packages/Domains/Test/QueryService/WorldHeritageQueryService_getAllHeritagesTest.php @@ -6,6 +6,7 @@ use App\Models\Country; use App\Models\Image; use App\Models\WorldHeritage; +use App\Models\WorldHeritageDescription; use Database\Seeders\DatabaseSeeder; use Illuminate\Support\Facades\DB; use Tests\TestCase; @@ -57,6 +58,7 @@ private function refresh(): void Country::truncate(); DB::table('site_state_parties')->truncate(); Image::truncate(); + WorldHeritageDescription::truncate(); DB::connection('mysql')->statement('SET FOREIGN_KEY_CHECKS=1;'); } } diff --git a/src/app/Packages/Domains/Test/QueryService/WorldHeritageQueryService_getByIdTest.php b/src/app/Packages/Domains/Test/QueryService/WorldHeritageQueryService_getByIdTest.php index e596def..13dbeca 100644 --- a/src/app/Packages/Domains/Test/QueryService/WorldHeritageQueryService_getByIdTest.php +++ b/src/app/Packages/Domains/Test/QueryService/WorldHeritageQueryService_getByIdTest.php @@ -4,6 +4,7 @@ use App\Models\Country; use App\Models\WorldHeritage; +use App\Models\WorldHeritageDescription; use App\Packages\Domains\Ports\Dto\HeritageSearchResult; use App\Packages\Domains\Ports\WorldHeritageSearchPort; use App\Packages\Domains\WorldHeritageQueryService; @@ -48,6 +49,7 @@ private function refresh(): void WorldHeritage::truncate(); Country::truncate(); Image::truncate(); + WorldHeritageDescription::truncate(); DB::table('site_state_parties')->truncate(); DB::connection('mysql')->statement('SET FOREIGN_KEY_CHECKS=1;'); } @@ -72,6 +74,7 @@ private function arrayData(): array 'latitude' => 0.0, 'longitude' => 0.0, 'short_description' => '氷期後のブナの自然拡散史を示すヨーロッパ各地の原生的ブナ林群から成る越境・連続資産。', + 'short_description_jp' => 'あいうえお', 'unesco_site_url' => 'https://whc.unesco.org/en/list/1133', 'state_parties_codes' => [ 'ALB','AUT','BEL','BIH','BGR','HRV','CZE','FRA','DEU','ITA','MKD','POL','ROU','SVK','SVN','ESP','CHE','UKR' @@ -157,6 +160,7 @@ public function test_check_data_value(): void $this->assertEquals($this->arrayData()['latitude'], $result->getLatitude()); $this->assertEquals($this->arrayData()['longitude'], $result->getLongitude()); $this->assertEquals($this->arrayData()['short_description'], $result->getShortDescription()); + $this->assertEquals($this->arrayData()['short_description_jp'], $result->getShortDescriptionJp()); $this->assertEquals($this->arrayData()['unesco_site_url'], $result->getUnescoSiteUrl()); $this->assertEquals($expectedCodes, $result->getStatePartyCodes()); $this->assertEquals($orderedExpected, $result->getStatePartiesMeta()); diff --git a/src/app/Packages/Domains/Test/QueryService/WorldHeritageQueryService_searchHeritagesTest.php b/src/app/Packages/Domains/Test/QueryService/WorldHeritageQueryService_searchHeritagesTest.php index 6f60253..957c4d7 100644 --- a/src/app/Packages/Domains/Test/QueryService/WorldHeritageQueryService_searchHeritagesTest.php +++ b/src/app/Packages/Domains/Test/QueryService/WorldHeritageQueryService_searchHeritagesTest.php @@ -16,6 +16,7 @@ use Mockery; use Tests\TestCase; use Illuminate\Support\Collection; +use App\Models\WorldHeritageDescription; final class WorldHeritageQueryService_searchHeritagesTest extends TestCase { @@ -81,6 +82,7 @@ private function refresh(): void Country::truncate(); DB::table('site_state_parties')->truncate(); Image::truncate(); + WorldHeritageDescription::truncate(); DB::connection('mysql')->statement('SET FOREIGN_KEY_CHECKS=1;'); } } diff --git a/src/app/Packages/Domains/Test/QueryService/WorldHeritageReadQueryService_findTest.php b/src/app/Packages/Domains/Test/QueryService/WorldHeritageReadQueryService_findTest.php index 8430de2..da25f18 100644 --- a/src/app/Packages/Domains/Test/QueryService/WorldHeritageReadQueryService_findTest.php +++ b/src/app/Packages/Domains/Test/QueryService/WorldHeritageReadQueryService_findTest.php @@ -4,6 +4,7 @@ use App\Models\Country; use App\Models\Image; +use App\Models\WorldHeritageDescription; use App\Packages\Domains\WorldHeritageReadQueryService; use App\Models\WorldHeritage; use Database\Seeders\DatabaseSeeder; @@ -39,6 +40,7 @@ private function refresh(): void Country::truncate(); DB::table('site_state_parties')->truncate(); Image::truncate(); + WorldHeritageDescription::truncate(); DB::connection('mysql')->statement('SET FOREIGN_KEY_CHECKS=1;'); } } diff --git a/src/app/Packages/Domains/Test/WorldHeritageEntityCollectionTest.php b/src/app/Packages/Domains/Test/WorldHeritageEntityCollectionTest.php index 0b68b90..48d7a65 100644 --- a/src/app/Packages/Domains/Test/WorldHeritageEntityCollectionTest.php +++ b/src/app/Packages/Domains/Test/WorldHeritageEntityCollectionTest.php @@ -5,6 +5,7 @@ use App\Models\Country; use App\Models\Image; use App\Models\WorldHeritage; +use App\Models\WorldHeritageDescription; use App\Packages\Domains\WorldHeritageEntityCollection; use Database\Seeders\DatabaseSeeder; use Illuminate\Support\Facades\DB; @@ -34,6 +35,7 @@ private function refresh(): void WorldHeritage::truncate(); Country::truncate(); Image::truncate(); + WorldHeritageDescription::truncate(); DB::table('site_state_parties')->truncate(); DB::connection('mysql')->statement('SET FOREIGN_KEY_CHECKS=1;'); } @@ -63,6 +65,7 @@ private function arraySingleData(): array 'latitude' => 34.6851, 'longitude' => 135.8048, 'short_description' => 'Temples and shrines of the first permanent capital of Japan.', + 'short_description_jp' => 'あいうえお', 'image_url' => '', 'unesco_site_url' => 'https://whc.unesco.org/en/list/668/', ], @@ -89,6 +92,7 @@ private function arrayMultiData(): array 'latitude' => 0.0, 'longitude' => 0.0, 'short_description' => 'Transnational serial property of European beech forests illustrating post-glacial expansion and ecological processes across Europe.', + 'short_description_jp' => 'あいうえお', 'image_url' => '', 'unesco_site_url' => 'https://whc.unesco.org/en/list/1133/', 'state_parties' => [ @@ -132,6 +136,7 @@ private function arrayMultiData(): array 'latitude' => 0.0, 'longitude' => 0.0, 'short_description' => 'Transnational Silk Road corridor across China, Kazakhstan and Kyrgyzstan illustrating exchange of goods, ideas and beliefs.', + 'short_description_jp' => 'あいうえお', 'image_url' => '', 'unesco_site_url' => 'https://whc.unesco.org/en/list/1442/', 'state_parties' => ['CHN','KAZ','KGZ'], @@ -166,6 +171,7 @@ public function test_collection_check_type(): void $data['area_hectares'], $data['buffer_zone_hectares'], $data['short_description'], + $data['short_description_jp'], null, $data['unesco_site_url'], $data['state_parties'] ?? [], @@ -205,6 +211,7 @@ public function test_collection_check_count_value(): void $data['area_hectares'], $data['buffer_zone_hectares'], $data['short_description'], + $data['short_description_jp'], null, $data['unesco_site_url'], $data['state_parties'] ?? [], @@ -238,6 +245,7 @@ public function test_multi_collection_check_type(): void $data['area_hectares'], $data['buffer_zone_hectares'], $data['short_description'], + $data['short_description_jp'], null, $data['unesco_site_url'], $data['state_parties'] ?? [], @@ -271,6 +279,7 @@ public function test_multi_collection_check_count_value(): void $data['area_hectares'], $data['buffer_zone_hectares'], $data['short_description'], + $data['short_description_jp'], null, $data['unesco_site_url'], $data['state_parties'] ?? [], diff --git a/src/app/Packages/Domains/Test/WorldHeritageEntityTest.php b/src/app/Packages/Domains/Test/WorldHeritageEntityTest.php index a376b8b..051a28d 100644 --- a/src/app/Packages/Domains/Test/WorldHeritageEntityTest.php +++ b/src/app/Packages/Domains/Test/WorldHeritageEntityTest.php @@ -4,6 +4,7 @@ use App\Models\Country; use App\Models\WorldHeritage; +use App\Models\WorldHeritageDescription; use Illuminate\Support\Facades\DB; use Tests\TestCase; use App\Packages\Domains\WorldHeritageEntity; @@ -31,6 +32,7 @@ private function refresh(): void WorldHeritage::truncate(); Country::truncate(); DB::table('site_state_parties')->truncate(); + WorldHeritageDescription::truncate(); DB::connection('mysql')->statement('SET FOREIGN_KEY_CHECKS=1;'); } } @@ -54,6 +56,7 @@ private function arraySingleData(): array 'latitude' => 34.6851, 'longitude' => 135.8048, 'short_description' => 'Temples and shrines of the first permanent capital of Japan.', + 'short_description_jp' => 'これはテストです', 'image_url' => '', 'unesco_site_url' => 'https://whc.unesco.org/en/list/668/', 'state_parties' => null, @@ -85,6 +88,7 @@ private function arrayMultiData(): array 'latitude' => 0.0, 'longitude' => 0.0, 'short_description' => 'Transnational serial property of European beech forests illustrating post-glacial expansion and ecological processes across Europe.', + 'short_description_jp' => 'これはテストです', 'image_url' => '', 'unesco_site_url' => 'https://whc.unesco.org/en/list/1133/', 'state_parties' => [ @@ -133,6 +137,7 @@ public function test_entity_check_single_type(): void $this->arraySingleData()['area_hectares'], $this->arraySingleData()['buffer_zone_hectares'], $this->arraySingleData()['short_description'], + $this->arraySingleData()['short_description_jp'], null, // collection (ImageEntityCollection) $this->arraySingleData()['unesco_site_url'], $this->arraySingleData()['state_parties'] ?? [], @@ -162,6 +167,7 @@ public function test_entity_check_single_value(): void $this->arraySingleData()['area_hectares'], $this->arraySingleData()['buffer_zone_hectares'], $this->arraySingleData()['short_description'], + $this->arraySingleData()['short_description_jp'], null, $this->arraySingleData()['unesco_site_url'], $this->arraySingleData()['state_parties'] ?: [], @@ -183,6 +189,7 @@ public function test_entity_check_single_value(): void $this->assertEquals($this->arraySingleData()['area_hectares'], $entity->getAreaHectares()); $this->assertEquals($this->arraySingleData()['buffer_zone_hectares'], $entity->getBufferZoneHectares()); $this->assertEquals($this->arraySingleData()['short_description'], $entity->getShortDescription()); + $this->assertEquals($this->arraySingleData()['short_description_jp'], $entity->getShortDescriptionJp()); $this->assertEquals($this->arraySingleData()['unesco_site_url'], $entity->getUnescoSiteUrl()); $this->assertSame(['JPN'], $entity->getStatePartyCodes()); $this->assertSame($this->arraySingleData()['state_parties_meta'], $entity->getStatePartyMeta()); @@ -208,6 +215,7 @@ public function test_entity_check_multi_type(): void $this->arrayMultiData()['area_hectares'], $this->arrayMultiData()['buffer_zone_hectares'], $this->arrayMultiData()['short_description'], + $this->arrayMultiData()['short_description_jp'], null, $this->arrayMultiData()['unesco_site_url'], $this->arrayMultiData()['state_parties'] ?? [], @@ -237,6 +245,7 @@ public function test_entity_check_multi_value(): void $this->arrayMultiData()['area_hectares'], $this->arrayMultiData()['buffer_zone_hectares'], $this->arrayMultiData()['short_description'], + $this->arrayMultiData()['short_description_jp'], null, // collection $this->arrayMultiData()['unesco_site_url'], $this->arrayMultiData()['state_parties'] ?? [], @@ -257,6 +266,7 @@ public function test_entity_check_multi_value(): void $this->assertEquals($this->arrayMultiData()['area_hectares'], $entity->getAreaHectares()); $this->assertEquals($this->arrayMultiData()['buffer_zone_hectares'], $entity->getBufferZoneHectares()); $this->assertEquals($this->arrayMultiData()['short_description'], $entity->getShortDescription()); + $this->assertEquals($this->arrayMultiData()['short_description_jp'], $entity->getShortDescriptionJp()); $this->assertEquals($this->arrayMultiData()['unesco_site_url'], $entity->getUnescoSiteUrl()); $this->assertEquals($this->arrayMultiData()['state_parties'], $entity->getStatePartyCodes()); $this->assertEquals($this->arrayMultiData()['state_parties_meta'], $entity->getStatePartyMeta()); diff --git a/src/app/Packages/Domains/WorldHeritageEntity.php b/src/app/Packages/Domains/WorldHeritageEntity.php index 9fc3c44..d942892 100644 --- a/src/app/Packages/Domains/WorldHeritageEntity.php +++ b/src/app/Packages/Domains/WorldHeritageEntity.php @@ -23,6 +23,7 @@ public function __construct( public ?float $areaHectares = null, public ?float $bufferZoneHectares = null, public ?string $shortDescription = null, + public ?string $shortDescriptionJp = null, public ?ImageEntityCollection $collection = null, public ?string $unescoSiteUrl = null, private array $statePartyCodes = [], @@ -109,6 +110,11 @@ public function getShortDescription(): ?string return $this->shortDescription; } + public function getShortDescriptionJp(): ?string + { + return $this->shortDescriptionJp; + } + public function getImageCollection(): ?ImageEntityCollection { return $this->collection; @@ -139,11 +145,6 @@ public function getStatePartyMeta(): array return $this->statePartyMeta; } - public function isTransnational(): bool - { - return count($this->statePartyCodes) > 1; - } - public function getPrimaryStatePartyCode(): ?string { foreach ($this->statePartyMeta as $code => $meta) { diff --git a/src/app/Packages/Domains/WorldHeritageQueryService.php b/src/app/Packages/Domains/WorldHeritageQueryService.php index 936ac34..d2933f2 100644 --- a/src/app/Packages/Domains/WorldHeritageQueryService.php +++ b/src/app/Packages/Domains/WorldHeritageQueryService.php @@ -60,6 +60,12 @@ public function getAllHeritages( 'images' => static function ($imagesQuery): void { $imagesQuery->where('is_primary', true)->limit(1); }, + 'descriptions' => static function ($descriptionsQuery): void { + $descriptionsQuery->select([ + 'world_heritage_descriptions.world_heritage_site_id', + 'world_heritage_descriptions.short_description_ja', + ]); + } ]) ->orderBy('world_heritage_sites.id', $order) ->paginate($perPage, page: $currentPage); @@ -100,6 +106,12 @@ public function getHeritageById(int $id): WorldHeritageDto 'images' => static function ($imagesQuery): void { $imagesQuery->orderBy('sort_order', 'asc'); }, + 'descriptions' => static function ($descriptionsQuery): void { + $descriptionsQuery->select([ + 'world_heritage_descriptions.world_heritage_site_id', + 'world_heritage_descriptions.short_description_ja', + ]); + } ]) ->findOrFail($id); @@ -184,6 +196,7 @@ public function getHeritageById(int $id): WorldHeritageDto 'state_party_code' => $statePartyCodes, 'state_party_codes' => $statePartyCodesCompat, 'state_parties_meta' => $statePartiesMeta, + 'short_description_ja' => $heritage->descriptions->short_description_ja, 'images' => $imageCollection->toArray(), ]); } @@ -308,6 +321,7 @@ private function buildWorldHeritagePayload($heritage): array 'short_description' => $heritage->short_description, 'image_url' => $heritage->images->first()?->url, 'unesco_site_url' => $heritage->unesco_site_url, + 'short_description_jp' => $heritage->descriptions?->short_description_ja, 'state_parties' => $statePartyCodeList, 'state_parties_meta' => $statePartiesMeta, ]; diff --git a/src/app/Packages/Domains/WorldHeritageReadQueryService.php b/src/app/Packages/Domains/WorldHeritageReadQueryService.php index c13daf5..4c71fcd 100644 --- a/src/app/Packages/Domains/WorldHeritageReadQueryService.php +++ b/src/app/Packages/Domains/WorldHeritageReadQueryService.php @@ -43,6 +43,12 @@ public function findByIdsPreserveOrder(array $ids): Collection 'images' => static function ($imageQuery): void { $imageQuery->where('is_primary', true)->limit(1); }, + 'descriptions' => static function ($descriptionQuery): void { + $descriptionQuery->select([ + 'world_heritage_descriptions.world_heritage_site_id', + 'world_heritage_descriptions.short_description_ja', + ]); + } ]) ->whereIn('world_heritage_sites.id', $ids) ->get() diff --git a/src/app/Packages/Features/QueryUseCases/Dto/WorldHeritageDto.php b/src/app/Packages/Features/QueryUseCases/Dto/WorldHeritageDto.php index 7ee0b6b..bfdc8a3 100644 --- a/src/app/Packages/Features/QueryUseCases/Dto/WorldHeritageDto.php +++ b/src/app/Packages/Features/QueryUseCases/Dto/WorldHeritageDto.php @@ -24,6 +24,7 @@ public function __construct( private readonly ?ImageDtoCollection $images = null, private readonly ?ImageDto $imageUrl = null, private readonly ?string $unescoSiteUrl = null, + private readonly ?string $shortDescriptionJp = null, private readonly array $statePartyCodes = [], private readonly array $statePartiesMeta = [], ){} @@ -178,6 +179,11 @@ public function getThumbnailUrl(): ?string return $this->imageUrl?->getUrl(); } + public function getShortDescriptionJp(): ?string + { + return $this->shortDescriptionJp; + } + public function toArray(): array { $value = [ @@ -198,6 +204,7 @@ public function toArray(): array 'area_hectares' => $this->getAreaHectares(), 'buffer_zone_hectares' => $this->getBufferZoneHectares(), 'short_description' => $this->getShortDescription(), + 'short_description_jp' => $this->getShortDescriptionJp(), 'unesco_site_url' => $this->getUnescoSiteUrl(), 'state_party_codes' => $this->getStatePartyCodes(), 'state_parties_meta' => $this->getStatePartiesMeta(), diff --git a/src/app/Packages/Features/QueryUseCases/Dto/WorldHeritageDtoCollection.php b/src/app/Packages/Features/QueryUseCases/Dto/WorldHeritageDtoCollection.php index b5d511c..0f6ef60 100644 --- a/src/app/Packages/Features/QueryUseCases/Dto/WorldHeritageDtoCollection.php +++ b/src/app/Packages/Features/QueryUseCases/Dto/WorldHeritageDtoCollection.php @@ -40,6 +40,7 @@ public function toSummaryArray(): array 'area_hectares' => $heritage->getAreaHectares(), 'buffer_zone_hectares' => $heritage->getBufferZoneHectares(), 'short_description' => $heritage->getShortDescription(), + 'short_description_jp' => $heritage->getShortDescriptionJp(), 'unesco_site_url' => $heritage->getUnescoSiteUrl(), 'state_party_codes' => $heritage->getStatePartyCodes(), 'state_parties_meta' => $heritage->getStatePartiesMeta(), diff --git a/src/database/seeders/DatabaseSeeder.php b/src/database/seeders/DatabaseSeeder.php index cba9d99..3141d7f 100644 --- a/src/database/seeders/DatabaseSeeder.php +++ b/src/database/seeders/DatabaseSeeder.php @@ -17,6 +17,7 @@ public function run(): void SiteStatePartySeeder::class, ImageSeeder::class, WorldHeritageThumbnailSeeder::class, + WorldHeritageDescriptionSeeder::class, ]); } } diff --git a/src/database/seeders/WorldHeritageDescriptionSeeder.php b/src/database/seeders/WorldHeritageDescriptionSeeder.php new file mode 100644 index 0000000..3fcc7f7 --- /dev/null +++ b/src/database/seeders/WorldHeritageDescriptionSeeder.php @@ -0,0 +1,39 @@ +orderBy('id')->get(); + + if ($sites->isEmpty()) { + $this->command?->warn('WorldHeritageDescriptionSeeder: world_heritage_sites が空です。先に世界遺産データを投入してください。'); + return; + } + + foreach ($sites as $site) { + WorldHeritageDescription::create([ + 'world_heritage_site_id' => $site->id, + 'short_description_en' => "Short description (EN) for site {$site->id}", + 'short_description_ja' => "あいうえお", + 'description_en' => "Description (EN) for site {$site->id}", + 'description_ja' => null, + 'created_at' => $now, + 'updated_at' => $now, + ]); + } + } +}