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 appcmds branch to match release #64

Merged
merged 17 commits into from
Mar 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,8 @@ jobs:

- name: Build
run: go build -v ./...
- name: Setup tests
run: |
mkdir ./config/
touch ./config/gcloud.json
echo $GOOGLE_APP_CRED >> ./config/gcloud.json
- name: Test
run: go test ./... -race -covermode=atomic -coverprofile=coverage.txt
run: mkdir ./config/ && touch ./config/gcloud.json && echo $GOOGLE_APP_CRED >> ./config/gcloud.json && go test ./deepl -race -covermode=atomic -coverprofile=coverage.txt
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3.1.0
with:
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@ dist/

/config
/data
.vscode/settings.json
.vscode/settings.json

codecov.*
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
</div>

<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
[![All Contributors](https://img.shields.io/badge/all_contributors-2-orange.svg?style=flat-square)](#contributors-)
[![All Contributors](https://img.shields.io/badge/all_contributors-2-orange.svg?style=for-the-badge)](#contributors-)
<!-- ALL-CONTRIBUTORS-BADGE:END -->
[![Discord Bots](https://top.gg/api/widget/servers/944915663632355388.svg)](https://top.gg/bot/944915663632355388)
[![Discord](https://img.shields.io/discord/847533270630531132?style=for-the-badge)](https://discord.gg/UZRyJrEPTU) ![Codecov](https://img.shields.io/codecov/c/gh/Lucxjo/Diru/branch/release/go?style=for-the-badge&token=SGMB3MJEGB&logo=codecov)
A Discord translation bot written in Go

[![Discord Bots](https://top.gg/api/widget/944915663632355388.svg)](https://top.gg/bot/944915663632355388)
Expand Down
31 changes: 21 additions & 10 deletions deepl/auto-translate_test.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,34 @@
package deepl

import (
deeplgo "github.com/bounoable/deepl"
_ "github.com/joho/godotenv/autoload"
"os"
"testing"

deeplgo "github.com/bounoable/deepl"
)

func TestAutoTranslate(t *testing.T) {
var phrases = []string{
"Hola mundo! Cómo estáis?",
"Hallo verden! Hvordan har du det?",
"Bonjour le monde! Comment allez-vous?",
"Ciao mondo! Come stai?",
"Olá mundo! Como vai você?",
"こんにちは世界!元気ですか?",
}

func TestAutoTranslate(t *testing.T) {
t.Parallel()
dpl_token := os.Getenv("DEEPL_TOKEN")

client := deeplgo.New(dpl_token)
phrase := "Hola Mundo! Cómo estáis?"
expected := "Hello World! How are you?"
actual := AutoTranslate(phrase, client)
if actual != expected {
t.Errorf("AutoTranslate: expected %s, got %s", expected, actual)
} else {
t.Logf("AutoTranslate: expected %s, got %s", expected, actual)
expected := "Hello world! How are you?"

for _, phrase := range phrases {
actual := AutoTranslate(phrase, client)
if actual != expected {
t.Errorf("AutoTranslate: expected %s, got %s", expected, actual)
} else {
t.Logf("AutoTranslate: expected %s, got %s", expected, actual)
}
}
}
28 changes: 28 additions & 0 deletions deepl/lang-code.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ import (
"github.com/bounoable/deepl"
)

const (
NorwegianBokmal deepl.Language = "NB"
Indonesian deepl.Language = "ID"
Korean deepl.Language = "KO"
Turkish deepl.Language = "TR"
Ukrainian deepl.Language = "UK"
)

// GetLang returns the deepl language for a given language code.
func GetLang(langCode string) deepl.Language {
trimmed := strings.TrimSpace(strings.ToUpper(langCode))
Expand Down Expand Up @@ -36,14 +44,20 @@ func GetLang(langCode string) deepl.Language {
return deepl.French
case "HU":
return deepl.Hungarian
case "ID":
return Indonesian
case "IT":
return deepl.Italian
case "JA":
return deepl.Japanese
case "KO":
return Korean
case "LT":
return deepl.Lithuanian
case "LV":
return deepl.Latvian
case "NB":
return NorwegianBokmal
case "NL":
return deepl.Dutch
case "PL":
Expand All @@ -64,6 +78,10 @@ func GetLang(langCode string) deepl.Language {
return deepl.Slovenian
case "SV":
return deepl.Swedish
case "TR":
return Turkish
case "UK":
return Ukrainian
case "ZH":
return deepl.Chinese
default:
Expand Down Expand Up @@ -132,6 +150,16 @@ func CheckCode(langCode string) bool {
return true
case "ZH":
return true
case "NB":
return true
case "ID":
return true
case "KO":
return true
case "TR":
return true
case "UK":
return true
default:
return false
}
Expand Down
7 changes: 7 additions & 0 deletions deepl/lang-code_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,15 @@ var langs = []testCodeStruct{
{"SV", true, deeplgo.Swedish},
{"ZH", true, deeplgo.Chinese},
{"EO", false, deeplgo.EnglishBritish},
{"NB", true, NorwegianBokmal},
{"ID", true, Indonesian},
{"KO", true, Korean},
{"TR", true, Turkish},
{"UK", true, Ukrainian},
}

func TestCheckCode(t *testing.T) {
t.Parallel()

for _, lang := range langs {
if CheckCode(lang.langCode) != lang.expected {
Expand All @@ -56,6 +62,7 @@ func TestCheckCode(t *testing.T) {
}

func TestGetLang(t *testing.T) {
t.Parallel()

for _, lang := range langs {
if GetLang(lang.langCode) != lang.expectedLang {
Expand Down
19 changes: 12 additions & 7 deletions deepl/translate-to_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,23 @@ import (
"testing"

deeplgo "github.com/bounoable/deepl"
_ "github.com/joho/godotenv/autoload"
)

func TestTranslateTo(t *testing.T) {
t.Parallel()

dpl_token := os.Getenv("DEEPL_TOKEN")

client := deeplgo.New(dpl_token)
phrase := "Hola Mundo! Cómo estáis?"
expected := "Hello World! How are you?"
actual := TranslateTo("en", phrase, client)
if actual != expected {
t.Errorf("AutoTranslate: expected %s, got %s", expected, actual)
} else {
t.Logf("AutoTranslate: expected %s, got %s", expected, actual)
expected := "Hello world! How are you?"

for _, phrase := range phrases {
actual := TranslateTo("en", phrase, client)
if actual != expected {
t.Errorf("AutoTranslate: expected %s, got %s", expected, actual)
} else {
t.Logf("AutoTranslate: expected %s, got %s", expected, actual)
}
}
}
50 changes: 24 additions & 26 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,59 +4,57 @@ go 1.17

require (
cloud.google.com/go/pubsub v1.28.0
cloud.google.com/go/translate v1.4.0
github.com/andersfylling/disgord v0.36.0
cloud.google.com/go/translate v1.6.0
github.com/andersfylling/disgord v0.36.1
github.com/bounoable/deepl v0.5.1
github.com/sirupsen/logrus v1.9.0
github.com/spf13/viper v1.14.0
go.mongodb.org/mongo-driver v1.11.1
golang.org/x/text v0.5.0
github.com/spf13/viper v1.15.0
go.mongodb.org/mongo-driver v1.11.2
golang.org/x/text v0.8.0
)

require (
cloud.google.com/go v0.107.0 // indirect
cloud.google.com/go/compute v1.14.0 // indirect
cloud.google.com/go v0.110.0 // indirect
cloud.google.com/go/compute v1.18.0 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
cloud.google.com/go/iam v0.9.0 // indirect
cloud.google.com/go/iam v0.12.0 // indirect
github.com/andersfylling/snowflake/v5 v5.0.1 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/go-stack/stack v1.8.1 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.2.1 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.2.3 // indirect
github.com/googleapis/gax-go/v2 v2.7.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/klauspost/compress v1.15.13 // indirect
github.com/joho/godotenv v1.5.1
github.com/klauspost/compress v1.16.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/montanaflynn/stats v0.6.6 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pelletier/go-toml/v2 v2.0.6 // indirect
github.com/montanaflynn/stats v0.7.0 // indirect
github.com/pelletier/go-toml/v2 v2.0.7 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/spf13/afero v1.9.3 // indirect
github.com/spf13/afero v1.9.5 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.4.1 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
github.com/xdg-go/scram v1.1.2 // indirect
github.com/xdg-go/stringprep v1.0.4 // indirect
github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a // indirect
go.opencensus.io v0.24.0 // indirect
go.uber.org/atomic v1.10.0 // indirect
golang.org/x/crypto v0.4.0 // indirect
golang.org/x/net v0.4.0 // indirect
golang.org/x/oauth2 v0.3.0 // indirect
golang.org/x/crypto v0.7.0 // indirect
golang.org/x/net v0.8.0 // indirect
golang.org/x/oauth2 v0.6.0 // indirect
golang.org/x/sync v0.1.0 // indirect
golang.org/x/sys v0.3.0 // indirect
google.golang.org/api v0.105.0 // indirect
golang.org/x/sys v0.6.0 // indirect
google.golang.org/api v0.111.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20221207170731-23e4bf6bdc37 // indirect
google.golang.org/grpc v1.51.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
google.golang.org/genproto v0.0.0-20230306155012-7f2fa6fef1f4 // indirect
google.golang.org/grpc v1.53.0 // indirect
google.golang.org/protobuf v1.29.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
Loading