Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Currently the translator plugin contains number of methods connecting to gengo service which is not really its responsibility. We should move these methods to a separate connector class and use that internally.
Comments
Comment #1
blueminds CreditAttribution: blueminds commentedPlease see the patch.
Comment #2
BerdirLooks good!
What's the property for if it's hardcoded here?
Do we want to default to GET? Or maybe have get()/post() methods?
Given that this supports multiple jobs, does it really return an object?
@param string $method, when we're fixing all of those anyway...
Does it make sense to add the $method to the watchdog log? e.g., sending GET/POST request to gengo at ...
Comment #3
blueminds CreditAttribution: blueminds commentedall implemented
it always returns and object - for that case it is $object->jobs where you get jobs.
Comment #4
bforchhammer CreditAttribution: bforchhammer commentedAwesome issue in terms of improving code quality and readability. Thanks for working on this! :)
This comment may come a bit late given that there's already a full patch, but have you considered using the official Gengo PHP library instead of a custom connector class? I could be wrong, but from a quick glance it looks like they do pretty much the same thing.
Comment #5
BerdirWe discussed that for OHT already, the problem are licensing questions.
No idea what kind of license that is but it's not GPL and external libraries aren't allowed on d.o, even if it were. So we would have to require our users to manually download that and put it in a libraries folder.
Comment #6
BerdirOk, had a look at the new plugin.inc file in the editor, looks a lot better already.
- There are two methods remaining that start with gengo, can we rename gengoFetchCommits to just fetchCommits()? It's the gengo translator plugin, it's quite obvious that it's not going to fetch OHT comments ;)
- Same for gengoSendJob(), I think just sendJob() is fine. What we should do instead is mark methods that are not supposed to be called from outside with protected. There are of course some methods that are, e.g. from the page callback. We could also refactor it to not actually send a request but only transform the $job to the data that we want to submit and then submit from within requestTranslation()/getQuote(). The only tricky part is the duplicated check handling, that would unfortunately still require the $quote argument. Still waiting on feedback from them if we can safely rely on their duplicated items response.
- Some methods are missing a docblock, .e.g getDefaultRemoteLanguagesMappings(). That should get the standard Implements ... header so that we know that this is an implementation of the interface and not a custom method.
- getGengoLanguagePairs() has support for a $target_language filter but that does not seem to be used anywhere, possibly a left-over of my refactoring for the supported remote languages? We might even just inline it into getSupportedTargetLanguages() because I don't think we actually need the static caching logic there, that's handled already in the translator entity for us.
- The mapping related methods can be cleaned up when converting that to use the core mapping API.
Comment #7
blueminds CreditAttribution: blueminds commentedSo, did a major refactoring, also little cleanup with languages/language_pairs.
Moved most of the helper methods out of the translator plugin class mostly into the UI controller. The only two remaining are sendJob() and saveTranslation(). I would leave these two as they are as they basically handle special gengo stuff. The special logic is then fine encapsulated and you can call them anywhere you need it. What do you think?
Comment #8
blueminds CreditAttribution: blueminds commentedAnd yes... diff against recent 7.x-1.x branch + update of changelog
Comment #9
BerdirShould be at the top, newest entries in a change log are always at the top.
Why is this removed? :)
Looks great, not sure about moving the functions to the UI controller but the actual API is the connector class now I guess, so if you want to re-use it somehow, just call that...
Comment #10
blueminds CreditAttribution: blueminds commentedPlease see the patch.
The UI methods - I would say they are UI helpers that process the response obtained from connector and handle errors. Yes, the logic inside could be inline part of the form builder methods, but this way I think it is cleaner. Anyway, if you have any suggestions for improvements/changes let's do it.
Comment #11
blueminds CreditAttribution: blueminds commentedand once again
Comment #12
blueminds CreditAttribution: blueminds commentedinterdiff
Comment #13
BerdirGreat, commited and pushed.