diff --git a/app/Importers/UpmImporter.php b/app/Importers/UpmImporter.php index 392d25578..590bb75b1 100644 --- a/app/Importers/UpmImporter.php +++ b/app/Importers/UpmImporter.php @@ -15,16 +15,6 @@ class UpmImporter extends AbstractImporter 'dating:sk' => 'Datace', 'date_earliest' => 'Od', 'date_latest' => 'Do', - 'work_type:cs' => 'Výtvarný druh', - 'work_type:sk' => 'Výtvarný druh', - 'object_type:cs' => 'Typ', - 'object_type:sk' => 'Typ', - 'medium:cs' => 'Materiál', - 'medium:sk' => 'Materiál', - 'technique:cs' => 'Technika', - 'technique:sk' => 'Technika', - 'topic:cs' => 'Námět', - 'topic:sk' => 'Námět', 'inscription:cs' => 'Značení', 'inscription:sk' => 'Značení', 'related_work:sk' => 'Sbírka', @@ -51,11 +41,24 @@ class UpmImporter extends AbstractImporter 'newline' => "\n", ]; + private array $workTypeTranslationKeys; + private array $techniqueTranslationKeys; + private array $mediumTranslationKeys; + private array $objectTypeTranslationKeys; + private array $topicTranslationKeys; + + protected function init() { $this->sanitizers[] = function ($value) { return empty_to_null(trim($value)); }; + + $this->workTypeTranslationKeys = array_flip(trans('item.work_types', locale: 'cs')); + $this->techniqueTranslationKeys = array_flip(trans('item.techniques', locale: 'cs')); + $this->mediumTranslationKeys = array_flip(trans('item.media', locale: 'cs')); + $this->objectTypeTranslationKeys = array_flip(trans('item.object_types', locale: 'cs')); + $this->topicTranslationKeys = array_flip(trans('item.topics', locale: 'cs')); } protected function getItemId(array $record) @@ -98,6 +101,86 @@ protected function hydrateAuthor(array $record): string ->join('; '); } + protected function hydrateWorkType(array $record, string $locale): ?string + { + if ($locale === 'cs') { + return $record['Výtvarný druh']; + } + + return str($record['Výtvarný druh']) + ->split('/\s*;\s*/') + ->map(function (string $workType) use ($locale) { + $key = $this->workTypeTranslationKeys[$workType] ?? null; + return $key ? trans("item.work_types.$key", locale: $locale) : null; + }) + ->filter() + ->join('; ') ?: null; + } + + protected function hydrateTechnique(array $record, string $locale): ?string + { + if ($locale === 'cs') { + return $record['Technika']; + } + + return str($record['Technika']) + ->split('/\s*;\s*/') + ->map(function (string $technique) use ($locale) { + $key = $this->techniqueTranslationKeys[$technique] ?? null; + return $key ? trans("item.techniques.$key", locale: $locale) : null; + }) + ->filter() + ->join('; ') ?: null; + } + + protected function hydrateMedium(array $record, string $locale): ?string + { + if ($locale === 'cs') { + return $record['Materiál']; + } + + return str($record['Materiál']) + ->split('/\s*;\s*/') + ->map(function (string $medium) use ($locale) { + $key = $this->mediumTranslationKeys[$medium] ?? null; + return $key ? trans("item.media.$key", locale: $locale) : null; + }) + ->filter() + ->join('; ') ?: null; + } + + protected function hydrateObjectType(array $record, string $locale): ?string + { + if ($locale === 'cs') { + return $record['Typ']; + } + + return str($record['Typ']) + ->split('/\s*;\s*/') + ->map(function (string $objectType) use ($locale) { + $key = $this->objectTypeTranslationKeys[$objectType] ?? null; + return $key ? trans("item.object_types.$key", locale: $locale) : null; + }) + ->filter() + ->join('; ') ?: null; + } + + protected function hydrateTopic(array $record, string $locale): ?string + { + if ($locale === 'cs') { + return $record['Námět']; + } + + return str($record['Námět']) + ->split('/\s*;\s*/') + ->map(function (string $topic) use ($locale) { + $key = $this->topicTranslationKeys[$topic] ?? null; + return $key ? trans("item.topics.$key", locale: $locale) : null; + }) + ->filter() + ->join('; ') ?: null; + } + protected function hydratePlace(array $record, string $locale): ?string { if (!in_array($locale, ['cs', 'sk'])) { diff --git a/app/Item.php b/app/Item.php index b77eb6231..1865fd875 100644 --- a/app/Item.php +++ b/app/Item.php @@ -108,6 +108,7 @@ class Item extends Model implements IndexableModel, TranslatableContract 'exhibition', 'box', 'location', + 'object_type', ]; public static $rules = array( diff --git a/lang/cs/item.php b/lang/cs/item.php index f0c14ec46..be8ea2903 100644 --- a/lang/cs/item.php +++ b/lang/cs/item.php @@ -294,8 +294,12 @@ 'zväčšovanie' => 'zvětšování', 'čiernobiela fotografia' => 'černobílá fotografie', ], + 'object_types' => [ + 'kniha' => 'kniha', + ], 'topics' => [ 'figurálna kompozícia' => 'figurální kompozice', + 'ornament' => 'ornament', ], 'state_editions' => [ 'autorizovaný pozitív' => 'autorizovaný pozitiv', diff --git a/lang/en/item.php b/lang/en/item.php index ff5404e59..a09ecee7b 100644 --- a/lang/en/item.php +++ b/lang/en/item.php @@ -291,8 +291,12 @@ 'zväčšovanie' => 'enlarging', 'čiernobiela fotografia' => 'black-and-white photograph', ], + 'object_types' => [ + 'kniha' => 'book', + ], 'topics' => [ 'figurálna kompozícia' => 'figurative composition', + 'ornament' => 'ornament', ], 'state_editions' => [ 'autorizovaný pozitív' => 'authorized photographic print', diff --git a/lang/sk/item.php b/lang/sk/item.php index ae0634767..09bd12a05 100644 --- a/lang/sk/item.php +++ b/lang/sk/item.php @@ -291,8 +291,12 @@ 'zväčšovanie' => 'zväčšovanie', 'čiernobiela fotografia' => 'čiernobiela fotografia', ], + 'object_types' => [ + 'kniha' => 'kniha', + ], 'topics' => [ 'figurálna kompozícia' => 'figurálna kompozícia', + 'ornament' => 'ornament', ], 'state_editions' => [ 'autorizovaný pozitív' => 'autorizovaný pozitív', diff --git a/tests/Importers/UpmImporterTest.php b/tests/Importers/UpmImporterTest.php index 35357c326..358a904ac 100644 --- a/tests/Importers/UpmImporterTest.php +++ b/tests/Importers/UpmImporterTest.php @@ -56,11 +56,21 @@ public function testImport() $this->assertEquals('ze souboru', $item->translate('cs')->relationship_type); $this->assertEquals('collection', $item->translate('en')->relationship_type); $this->assertEquals('Sbírka užité grafiky', $item->translate('cs')->related_work); - $this->assertEquals('užité umění;grafický design', $item->translate('cs')->work_type); // todo translate - $this->assertEquals('celokožená vazba, zlacení', $item->translate('cs')->technique); // todo translate - $this->assertEquals('kniha', $item->translate('cs')->object_type); // todo translate - $this->assertEquals('kůže;papír', $item->translate('cs')->medium); // todo translate - $this->assertEquals('ornament', $item->translate('cs')->topic); // todo translate + $this->assertEquals('úžitkové umenie; grafický dizajn', $item->translate('sk')->work_type); + $this->assertEquals('užité umění;grafický design', $item->translate('cs')->work_type); + $this->assertEquals('applied arts; graphic design', $item->translate('en')->work_type); + $this->assertEquals('kresba', $item->translate('sk')->technique); + $this->assertEquals('kresba', $item->translate('cs')->technique); + $this->assertEquals('drawing', $item->translate('en')->technique); + $this->assertEquals('kniha', $item->translate('sk')->object_type); + $this->assertEquals('kniha', $item->translate('cs')->object_type); + $this->assertEquals('book', $item->translate('en')->object_type); + $this->assertEquals('papier', $item->translate('sk')->medium); + $this->assertEquals('papír', $item->translate('cs')->medium); + $this->assertEquals('paper', $item->translate('en')->medium); + $this->assertEquals('ornament', $item->translate('sk')->topic); + $this->assertEquals('ornament', $item->translate('cs')->topic); + $this->assertEquals('ornament', $item->translate('en')->topic); $this->assertEquals('1928', $item->translate('cs')->dating); $this->assertEquals('Praha', $item->translate('cs')->place); $this->assertEquals('Rösller', $item->translate('cs')->inscription); @@ -96,8 +106,8 @@ private function fakeData(array $overrides = []): array "Do" => "1928", "Výtvarný druh" => "užité umění;grafický design", "Typ" => "kniha", - "Materiál" => "kůže;papír", - "Technika" => "celokožená vazba, zlacení", + "Materiál" => "papír", + "Technika" => "kresba", "Rozměry" => "v=16,5cm (konvice čajová s víčkem větší); v=13,5-14cm (konvice čajová s víčkem menší)", "Námět" => "ornament", "tagy" => "",