Skip to content
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

Merged
merged 8 commits into from
Dec 7, 2023
Merged

Update MG importer #926

merged 8 commits into from
Dec 7, 2023

Conversation

rastislav-chynoransky
Copy link
Contributor

Copy link
Contributor

@eronisko eronisko left a 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:

  1. I'd prefer using the standard Laravel trans helper unless a specific custom behaviour is required
  2. 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)

Comment on lines 90 to 92
throw $e;
$import_record->import->status = Import::STATUS_ERROR;
$import_record->import->save();
Copy link
Contributor

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

Comment on lines 210 to 212
if ($this->isBiennial($record)) {
return $this->translator->get('importer.mg.related_work.biennal_brno', locale: $locale);
}
Copy link
Contributor

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)

Suggested change
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:

Suggested change
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.

app/Importers/MgImporter.php Show resolved Hide resolved
@@ -55,44 +56,7 @@ class MgImporter extends AbstractImporter
'Te' => 'textil',
];
Copy link
Contributor

@eronisko eronisko Nov 30, 2023

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)

Comment on lines 106 to 112
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);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit pick

Suggested change
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);

tests/WithoutSearchIndexing.php Show resolved Hide resolved
Comment on lines +62 to +74
public static function mediumProvider()
{
return [
'medium' => [
'papír',
null,
[
'cs' => 'papír',
'sk' => 'papier',
'en' => 'paper',
],
],
'unexistingMedium' => [
Copy link
Contributor

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.

Copy link
Contributor

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?

Copy link
Contributor Author

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
Copy link
Contributor

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.

@rastislav-chynoransky
Copy link
Contributor Author

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.

Copy link
Contributor

@eronisko eronisko left a 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.

@@ -29,6 +29,7 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
extensions: :psr
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's this for?

Copy link
Contributor

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.

Copy link
Contributor

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?

Suggested change
extensions: :psr

e.g. https://github.com/SlovakNationalGallery/webumenia.sk/actions/runs/7059939917/job/19401362324

@rastislav-chynoransky rastislav-chynoransky merged commit a90b452 into develop Dec 7, 2023
1 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants