-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update MG importer #926
Update MG importer #926
Conversation
e205871
to
d98570a
Compare
8e032ae
to
3780fed
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've gone over the code and I'm providing my suggestions. I'd be happy to discuss any of the points with you in more detail.
In summary:
- I'd prefer using the standard Laravel
trans
helper unless a specific custom behaviour is required - I'm opposed to storing translations and/or topic/medium/work type/etc hierarchy in the database.
I'm expaning on the reasons for 2. in the comments below, but in short:
- I believe the translations and hierarchies are of static nature
- Having them stored in the database will make development more difficult -- all developers will have to have the same set of translations/hierarchies stored locally (because they're static)
- I don't think the benefit of not having to edit a static file every now and then outweighs the drawbacks of managing and distributing the files. (I think we have a pretty good deployment flow set up right now & we can get things fixed & released very quickly)
app/Importers/AbstractImporter.php
Outdated
throw $e; | ||
$import_record->import->status = Import::STATUS_ERROR; | ||
$import_record->import->save(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this right? I don't think the bottom two lines will get executed
app/Importers/MgImporter.php
Outdated
if ($this->isBiennial($record)) { | ||
return $this->translator->get('importer.mg.related_work.biennal_brno', locale: $locale); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need to use any custom translators here. Using something like $this->translator
(rather than the stock trans
helper) implies that there's some kind of special behaviour needed & I will have to look up the implementation of the custom translator if I want to understand what's going on.
On the other hand something like this is immediately obvious to me (or any Laravel developer)
if ($this->isBiennial($record)) { | |
return $this->translator->get('importer.mg.related_work.biennal_brno', locale: $locale); | |
} | |
if ($this->isBiennial($record)) { | |
return trans('importer.mg.related_work.biennal_brno', $locale); | |
} |
In this case, I'd even argue that this is not a case for lang files. Because the 'encoding' of the titles is a property of the data source → of the importer, I'd be OK with this as well:
if ($this->isBiennial($record)) { | |
return $this->translator->get('importer.mg.related_work.biennal_brno', locale: $locale); | |
} | |
if ($this->isBiennial($record)) { | |
return Arr::get([ | |
'sk' => 'Bienále Brno', | |
'cz' => 'Bienále Brno', | |
'en' => 'Biennal Brno', | |
], $locale) | |
} |
In the latter case, there's nothing to look up and everything is very explicit.
@@ -55,44 +56,7 @@ class MgImporter extends AbstractImporter | |||
'Te' => 'textil', | |||
]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually really like(d) this -- I'd just translate it to Slovak instead of Czech and then use that as a basis for translations into other locales. (Using EN as the basis would be OK too but for us I think SK is more suitable)
app/Importers/MgImporter.php
Outdated
if ($record['Titul'] !== null) { | ||
return in_array($locale, ['sk', 'cs']) ? $record['Titul'] : null; | ||
} elseif ($record['Předmět'] !== null) { | ||
return in_array($locale, ['sk', 'cs']) ? $record['Předmět'] : null; | ||
} else { | ||
return $this->translator->get('item.untitled', locale: $locale); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit pick
if ($record['Titul'] !== null) { | |
return in_array($locale, ['sk', 'cs']) ? $record['Titul'] : null; | |
} elseif ($record['Předmět'] !== null) { | |
return in_array($locale, ['sk', 'cs']) ? $record['Předmět'] : null; | |
} else { | |
return $this->translator->get('item.untitled', locale: $locale); | |
} | |
if ($record['Titul'] !== null) { | |
return in_array($locale, ['sk', 'cs']) ? $record['Titul'] : null; | |
} | |
if ($record['Předmět'] !== null) { | |
return in_array($locale, ['sk', 'cs']) ? $record['Předmět'] : null; | |
} | |
return trans('item.untitled', $locale); |
public static function mediumProvider() | ||
{ | ||
return [ | ||
'medium' => [ | ||
'papír', | ||
null, | ||
[ | ||
'cs' => 'papír', | ||
'sk' => 'papier', | ||
'en' => 'paper', | ||
], | ||
], | ||
'unexistingMedium' => [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is why I'm not a fan of database-based translations. You have to fill the database just in order to test a piece of fairly trivial functionality. It'll also make it difficult to do any development -- we'd have to maintain the same set of translations for each developer.
In my opinion, there is nothing inherently dynamic about these translations. "Paper" will always be "papier"/"papír" for any gallery, in any environment. So I think these belong into a static form, preferably lang files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rastislav-chynoransky are these data providers still needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like to keep those as the behavior might change for tree structures, i.e. providing at least part of the tree.
app/Medium.php
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as with the translations. I don't think the hierarchy of media/techniques/topics is dynamic by nature and therefore they do not belong in the database but should be statically defined instead.
For example, we could define the hierarchy like this:
[
'name' => 'plátno'
'children' => [
[
'name' => 'plátno na lepenke'
],
[
'name' => 'plátno na preglejke'
],
]
]
Or like this
[
[
'name' => 'plátno'
],
[
'name' => 'plátno na lepenke'
'parent' => 'plátno'
],
[
'name' => 'plátno na preglejke'
'parent' => 'plátno'
],
]
and that'd capture the same information. Note this would only need to exist for one locale, the translations for other locales would be handled in translation files.
Getting the equivalent of getFullName
would be straightforward, without even needing to hit the database.
Thanks for the thorough review. The reason for storing the filter values in the database is to keep track of missing translations so why not to use them to ease the process of translating new ones. We could still have the translations defined in lang files and use them to populate the entities but that seems a bit redundant. I don't think you actually need them in dev mode; some exemplary could still be defined in seeders. |
This reverts commit 1b3772d.
d65227b
to
dd9133f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this a lot! Please check the dataProviders in tests/Importers/MgImporterTest.php
, otherwise this is good to go, thank you.
.github/workflows/_test.yml
Outdated
@@ -29,6 +29,7 @@ jobs: | |||
uses: shivammathur/setup-php@v2 | |||
with: | |||
php-version: '8.1' | |||
extensions: :psr |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's this for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see now, weird... Looks like something broke upstream?
Could you add a comment explaining the extension addition please? It seems like a temporary requirement to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like it's been fixed already, so I guess it could be removed?
extensions: :psr |
e.g. https://github.com/SlovakNationalGallery/webumenia.sk/actions/runs/7059939917/job/19401362324
279ae04
to
dd9133f
Compare
https://jira.sng.sk/browse/MG-14