diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index efe4600..8271114 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -24,7 +24,7 @@ jobs: run: | git config --global user.name 'github-actions' git config --global user.email 'github-actions@github.com' - TAG="v0.0.6-$(date +'%Y%m%d%H%M%S')" + TAG="v0.0.7-$(date +'%Y%m%d%H%M%S')" git tag $TAG git push origin $TAG env: diff --git a/cmd/main.go b/cmd/main.go index 8f0a07f..9f11813 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -92,7 +92,7 @@ func main() { } if strings.ToLower(testMethod) == "origin" { if url != "" && parseType != "" { - sp.CustomSpeedTest(url, parseType, num) + sp.CustomSpeedTest(url, parseType, num, language) } else { fmt.Println("-opt/-pf with wrong operator.") } @@ -100,14 +100,14 @@ func main() { err := sp.OfficialAvailableTest() if err == nil { if url != "" && parseType != "" { - sp.OfficialCustomSpeedTest(url, parseType, num) + sp.OfficialCustomSpeedTest(url, parseType, num, language) } else { fmt.Println("-opt/-pf with wrong operator.") } } else { fmt.Println("Can not match speedtest command, switch to use origin test") if url != "" && parseType != "" { - sp.CustomSpeedTest(url, parseType, num) + sp.CustomSpeedTest(url, parseType, num, language) } else { fmt.Println("-opt/-pf with wrong operator.") } diff --git a/model/model.go b/model/model.go index 1fe9692..e9330e4 100644 --- a/model/model.go +++ b/model/model.go @@ -1,6 +1,6 @@ package model -const SpeedTestVersion = "v0.0.6" +const SpeedTestVersion = "v0.0.7" var EnableLoger = false var ( diff --git a/sp/sp.go b/sp/sp.go index 12c4c05..058bc11 100644 --- a/sp/sp.go +++ b/sp/sp.go @@ -65,7 +65,7 @@ func OfficialNearbySpeedTest() { } } -func OfficialCustomSpeedTest(url, byWhat string, num int) { +func OfficialCustomSpeedTest(url, byWhat string, num int, language string) { if model.EnableLoger { InitLogger() defer Logger.Sync() @@ -129,7 +129,17 @@ func OfficialCustomSpeedTest(url, byWhat string, num int) { } } if Latency != "" && DLStr != "" && UPStr != "" && PacketLoss != "" { - fmt.Print(formatString(serverName, 16)) + if language == "zh" { + fmt.Print(formatString(serverName, 16)) + } else if language == "en" { + name := serverName + name = strings.ReplaceAll(name, "中国香港", "HongKong") + name = strings.ReplaceAll(name, "洛杉矶", "LosAngeles") + name = strings.ReplaceAll(name, "日本东京", "Tokyo,Japan") + name = strings.ReplaceAll(name, "新加坡", "Singapore") + name = strings.ReplaceAll(name, "法兰克福", "Frankfurt") + fmt.Print(formatString(name, 16)) + } fmt.Print(formatString(UPStr, 16)) fmt.Print(formatString(DLStr, 16)) fmt.Print(formatString(Latency, 16)) @@ -182,7 +192,7 @@ func NearbySpeedTest() { } } -func CustomSpeedTest(url, byWhat string, num int) { +func CustomSpeedTest(url, byWhat string, num int, language string) { if model.EnableLoger { InitLogger() defer Logger.Sync() @@ -253,7 +263,17 @@ func CustomSpeedTest(url, byWhat string, num int) { server.Context.Reset() continue } - fmt.Print(formatString(server.Name, 16)) + if language == "zh" { + fmt.Print(formatString(server.Name, 16)) + } else if language == "en" { + name := server.Name + name = strings.ReplaceAll(name, "中国香港", "HongKong") + name = strings.ReplaceAll(name, "洛杉矶", "LosAngeles") + name = strings.ReplaceAll(name, "日本东京", "Tokyo,Japan") + name = strings.ReplaceAll(name, "新加坡", "Singapore") + name = strings.ReplaceAll(name, "法兰克福", "Frankfurt") + fmt.Print(formatString(name, 16)) + } fmt.Print(formatString(fmt.Sprintf("%-8s", fmt.Sprintf("%.2f", server.ULSpeed.Mbps())+" Mbps"), 16)) fmt.Print(formatString(fmt.Sprintf("%-8s", fmt.Sprintf("%.2f", server.DLSpeed.Mbps())+" Mbps"), 16)) fmt.Print(formatString(fmt.Sprintf("%s", server.Latency), 16))