2
1
Fork
You've already forked SimplyTranslate
0

Add LibreTranslate engine #9

Merged
Ghost merged 1 commit from add-libretranslate into main 2022年09月05日 21:52:02 +02:00

(削除) Please don't merge this yet, there are still some things I'd like to discuss and think about a bit more. Feel free to leave a review though. (削除ここまで) This is pretty much ready.

~~Please don't merge this yet, there are still some things I'd like to discuss and think about a bit more. Feel free to leave a review though.~~ This is pretty much ready.
@ -0,0 +31,4 @@
deferresponse.Body.Close()
ifresponse.StatusCode>=400{

Why do >= 400 instead of checking only if it's not 200 ?

Why do `>= 400` instead of checking only if it's not 200 ?

https://developer.mozilla.org/en-US/docs/Web/HTTP/Status states that only status codes >=400 convey errors, so it doesn't make sense to assume that anything that's not 200 is an error.

https://developer.mozilla.org/en-US/docs/Web/HTTP/Status states that only status codes >=400 convey errors, so it doesn't make sense to assume that anything that's not 200 is an error.

it makes sense to only listen for the reply that you are expecting and that is documented, everything else is unexpected behavior and could very well lead to errors as the code progresses with a faulty reply

it makes sense to only listen for the reply that you are expecting and that is documented, everything else is unexpected behavior and could very well lead to errors as the code progresses with a faulty reply

Like.. everything between 300 and 399 are redirection messages. It doesn't make sense to progress here like normal, this should result in a different behavior than the standard progression of code.

Like.. everything between 300 and 399 are redirection messages. It doesn't make sense to progress here like normal, this should result in a different behavior than the standard progression of code.

Okay, I changed the conditions to check for status code 200 only.

Okay, I changed the conditions to check for status code 200 only.
Ghost marked this conversation as resolved
@ -0,0 +32,4 @@
deferresponse.Body.Close()
ifresponse.StatusCode>=400{
returnnil,fmt.Errorf("Got status code %d from LibreTranslate API",response.StatusCode)
First-time contributor

Error strings should not be capitalized https://github.com/golang/go/wiki/CodeReviewComments#error-strings (same thing for other error strings in this MR)

Error strings should not be capitalized https://github.com/golang/go/wiki/CodeReviewComments#error-strings (same thing for other error strings in this MR)
Ghost marked this conversation as resolved
@ -0,0 +10,4 @@
typeLibreTranslateEnginestruct{
InstanceURLstring
ApiKeystring
First-time contributor
should be `APIKey` https://github.com/golang/go/wiki/CodeReviewComments#initialisms
Ghost marked this conversation as resolved
Ghost force-pushed add-libretranslate from f5b35a1c57 to 3f1041d6d5 2022年08月12日 18:24:26 +02:00 Compare
Ghost force-pushed add-libretranslate from 3f1041d6d5 to b19a0aff3f 2022年08月24日 12:18:18 +02:00 Compare

I added some documentation to LibreTranslateEngine and its fields (and also made a small modification to one of the error messages). Please take a look.

I added some documentation to `LibreTranslateEngine` and its fields (and also made a small modification to one of the error messages). Please take a look.
Ghost force-pushed add-libretranslate from b19a0aff3f to b031077f23 2022年08月25日 17:22:23 +02:00 Compare

@Lomanic @metalune please review this PR and leave an approval if this looks good to you, I want to get this merged.

@Lomanic @metalune please review this PR and leave an approval if this looks good to you, I want to get this merged.
Ghost force-pushed add-libretranslate from b031077f23 to ed0cdfa15c 2022年08月26日 10:05:38 +02:00 Compare
Ghost changed title from (削除) WIP: Add LibreTranslate engine (削除ここまで) to Add LibreTranslate engine 2022年08月26日 10:05:50 +02:00
Ghost left a comment

Other from those few rather stylistic comments I have, this looks good to me :)

Other from those few rather stylistic comments I have, this looks good to me :)
@ -0,0 +23,4 @@
APIKeystring
}
func(_*LibreTranslateEngine)InternalName()string{return"libre"}

Why not make the next two lines variables/static variables? I see no reason for those to be functions

Why not make the next two lines variables/static variables? I see no reason for those to be functions

These are required for the TranslationEngine interface, and interfaces can only have methods, not variables/properties/whatever you want to call them. This kind of property-as-method thing is not actually all that uncommon. https://go.dev/doc/effective_go#Getters is relevant. Same thing below.

These are required for the `TranslationEngine` interface, and interfaces can only have methods, not variables/properties/whatever you want to call them. This kind of property-as-method thing is not actually all that uncommon. https://go.dev/doc/effective_go#Getters is relevant. Same thing below.

I see, I feel like there should be a better way, but this is fine for now :)

I see, I feel like there should be a better way, but this is fine for now :)

See my edit, this is actually idiomatic Go style.

See my edit, this is actually idiomatic Go style.
Ghost marked this conversation as resolved
@ -0,0 +65,4 @@
func(e*LibreTranslateEngine)TargetLanguages()([]Language,error){returne.getLangs()}
func(_*LibreTranslateEngine)SupportsAutodetect()bool{returntrue}

Why not have this be a variable too?

Why not have this be a variable too?
Ghost marked this conversation as resolved
@ -0,0 +67,4 @@
func(_*LibreTranslateEngine)SupportsAutodetect()bool{returntrue}
typelibreDetectResponse[]struct{

shouldn't all type definitions be at the top of the page? Not sure what the golang style guide says about this, but I feel like it would be more logical to have them at the top of the page

shouldn't all type definitions be at the top of the page? Not sure what the golang style guide says about this, but I feel like it would be more logical to have them at the top of the page

To me, it makes more sense to have these internal types close to where they are used, especially given that each is used in one function only. I'm fine with moving them to the top though.

To me, it makes more sense to have these internal types close to where they are used, especially given that each is used in one function only. I'm fine with moving them to the top though.

Alright, I'd say move everything like that to the top, all type defintions and the only thing left at the bottom should be the functions. Other than that this is great.

Alright, I'd say move everything like that to the top, all type defintions and the only thing left at the bottom should be the functions. Other than that this is great.

I went ahead and took a look at the source of a "standard" Go package net/url, and type declarations are interspersed through the code, not at the top. Please take a look, and make of that what you will.

I went ahead and took a look at [the source of a "standard" Go package `net/url`](https://cs.opensource.google/go/go/+/refs/tags/go1.19:src/net/url/url.go), and type declarations are interspersed through the code, not at the top. Please take a look, and make of that what you will.

I see, I guess we'll leave it at "define it where you need it, except when you need something more than once across different functions, then define it at the top" because that way one can easily glance at the types that are available in the document

I see, I guess we'll leave it at "define it where you need it, except when you need something more than once across different functions, then define it at the top" because that way one can easily glance at the types that are available in the document

I think it's more nuanced than that (the types in the file I linked to are used by multiple functions but are not at the top), but that's a discussion for another time. :)

bikeshedding for the win

I think it's more nuanced than that (the types in the file I linked to _are_ used by multiple functions but are not at the top), but that's a discussion for another time. :) <sub>bikeshedding for the win</sub>
Ghost marked this conversation as resolved
Ghost deleted branch add-libretranslate 2022年09月05日 21:52:02 +02:00
Commenting is not possible because the repository is archived.
No reviewers
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
2 participants Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
SimpleWeb/SimplyTranslate!9
Reference in a new issue
SimpleWeb/SimplyTranslate
No description provided.
Delete branch "add-libretranslate"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?