Skip to content

Commit

Permalink
优化地域输入;
Browse files Browse the repository at this point in the history
取消阿里云的地域,实用性不是很大;
  • Loading branch information
speauty committed Mar 4, 2023
1 parent 2d9846f commit 7bf730a
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 26 deletions.
6 changes: 2 additions & 4 deletions src/srv/mt/aliyun/ali_mt.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ func (m *ALiMT) Init(_ context.Context, cfg interface{}) error {
if m.cfg != nil { // 拒绝重复初始化
return nil
}
if cfg.(*Cfg).Endpoint == "" { // 拼接域名
cfg.(*Cfg).Endpoint = fmt.Sprintf("mt.%s.aliyuncs.com", cfg.(*Cfg).Location)
}
cfg.(*Cfg).Endpoint = "mt.aliyuncs.com"
m.cfg = cfg.(*Cfg)
return m.initClient()
}
Expand Down Expand Up @@ -103,7 +101,7 @@ func (m *ALiMT) GetId() mt.Id {
}

func (m *ALiMT) GetName() string {
return "阿里云机器翻译"
return mt.EngineALiYun.GetZH()
}

func (m *ALiMT) initClient() error {
Expand Down
42 changes: 20 additions & 22 deletions src/ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"gui.subtitle/src/srv/mt/tencent"
"gui.subtitle/src/srv/mt/youdao"
"gui.subtitle/src/util/lang"
"gui.subtitle/src/util/region"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -52,15 +53,14 @@ func (aw *AppWindow) newMainWindow() error {

var aLiIdEdit *walk.TextEdit
var aLiKeyEdit *walk.TextEdit
var aLiLocationEdit *walk.TextEdit

var bdIdEdit *walk.TextEdit
var bdKeyEdit *walk.TextEdit
var bdApiVersionComboBox *walk.ComboBox

var tencentIdEdit *walk.TextEdit
var tencentKeyEdit *walk.TextEdit
var tencentRegionEdit *walk.TextEdit
var tencentRegionComboBox *walk.ComboBox

var fromLanguageComboBox *walk.ComboBox
var toLanguageComboBox *walk.ComboBox
Expand All @@ -82,7 +82,7 @@ func (aw *AppWindow) newMainWindow() error {
Layout: VBox{},
Children: []Widget{
Label{Text: "***** 译名 *****", Alignment: AlignHCenterVCenter, Font: Font{Bold: true, PointSize: 10}},
Label{Text: "版本号: 1.1.8 作者: speauty 邮箱: [email protected]", Alignment: AlignHCenterVCenter},
Label{Text: "版本号: 1.1.9 作者: speauty 邮箱: [email protected]", Alignment: AlignHCenterVCenter},
GroupBox{
Layout: HBox{},
Children: []Widget{
Expand All @@ -98,8 +98,8 @@ func (aw *AppWindow) newMainWindow() error {
},
},
GroupBox{
MinSize: Size{Height: 110},
MaxSize: Size{Height: 110},
MinSize: Size{Height: 80},
MaxSize: Size{Height: 80},
Layout: VBox{},
Visible: Bind("mtEngineComboBox.CurrentIndex == 0"),
Children: []Widget{
Expand All @@ -117,19 +117,12 @@ func (aw *AppWindow) newMainWindow() error {
HSpacer{},
},
},
HSplitter{
Children: []Widget{
Label{Text: "访问地域", ToolTipText: "AccessKeySecret"},
TextEdit{AssignTo: &aLiLocationEdit},
HSpacer{},
},
},
VSpacer{},
},
},
GroupBox{
MinSize: Size{Height: 110},
MaxSize: Size{Height: 110},
MinSize: Size{Height: 100},
MaxSize: Size{Height: 100},
Layout: VBox{},
Visible: Bind("mtEngineComboBox.CurrentIndex == 1"),
Children: []Widget{
Expand Down Expand Up @@ -172,8 +165,8 @@ func (aw *AppWindow) newMainWindow() error {
},
},
GroupBox{
MinSize: Size{Height: 110},
MaxSize: Size{Height: 110},
MinSize: Size{Height: 100},
MaxSize: Size{Height: 100},
Layout: VBox{},
Visible: Bind(fmt.Sprintf("mtEngineComboBox.CurrentIndex == %d", mt.EngineTencent)),
Children: []Widget{
Expand All @@ -193,8 +186,13 @@ func (aw *AppWindow) newMainWindow() error {
},
HSplitter{
Children: []Widget{
Label{Text: "访问地域", ToolTipText: "AccessKeySecret"},
TextEdit{AssignTo: &tencentRegionEdit},
Label{Text: "访问地域"},
ComboBox{
MinSize: Size{Width: 40}, MaxSize: Size{Width: 40},
AssignTo: &tencentRegionComboBox,
Model: region.T_AP_BeiJing.GetZhMaps(mt.IdTencent),
CurrentIndex: region.T_AP_BeiJing.ToInt(),
},
HSpacer{},
},
},
Expand Down Expand Up @@ -386,7 +384,7 @@ func (aw *AppWindow) newMainWindow() error {
var cfg interface{}

if currentMTEngine == mt.EngineALiYun {
cfg = &aliyun.Cfg{AccessKeyId: aLiIdEdit.Text(), AccessKeySecret: aLiKeyEdit.Text(), Location: aLiLocationEdit.Text()}
cfg = &aliyun.Cfg{AccessKeyId: aLiIdEdit.Text(), AccessKeySecret: aLiKeyEdit.Text()}
mtEngine = new(aliyun.ALiMT)
} else if currentMTEngine == mt.EngineBaiDu {
cfg = &bd.Cfg{AppId: bdIdEdit.Text(), AppSecret: bdKeyEdit.Text()}
Expand All @@ -395,7 +393,7 @@ func (aw *AppWindow) newMainWindow() error {
} else if currentMTEngine == mt.EngineYouDao {
mtEngine = new(youdao.MT)
} else if currentMTEngine == mt.EngineTencent {
cfg = &tencent.Cfg{SecretId: tencentIdEdit.Text(), SecretKey: tencentKeyEdit.Text(), Region: tencentRegionEdit.Text()}
cfg = &tencent.Cfg{SecretId: tencentIdEdit.Text(), SecretKey: tencentKeyEdit.Text(), Region: region.T_AP_BeiJing.FromInt(tencentRegionComboBox.CurrentIndex()).GetEn(mt.IdTencent)}
mtEngine = new(tencent.MT)
} else {
walk.MsgBox(aw, "提示", fmt.Sprintf("当前翻译引擎[%s]暂未接入, 尽情期待", currentMTEngine.GetZH()), walk.MsgBoxIconWarning)
Expand Down Expand Up @@ -429,12 +427,12 @@ func (aw *AppWindow) newMainWindow() error {
},
TextEdit{
AssignTo: &stateLabel, Visible: false, ReadOnly: true, VScroll: true,
MinSize: Size{Height: 40}, MaxSize: Size{Height: 40},
MinSize: Size{Height: 40, Width: 80}, MaxSize: Size{Height: 40, Width: 80},
Font: Font{PointSize: 8},
},
TextEdit{
Visible: false, ReadOnly: true, VScroll: true,
AssignTo: &logLabel, MinSize: Size{Height: 120, Width: 100}, MaxSize: Size{Height: 120, Width: 100},
AssignTo: &logLabel, MinSize: Size{Height: 120, Width: 80}, MaxSize: Size{Height: 120, Width: 80},
},

VSpacer{},
Expand Down
42 changes: 42 additions & 0 deletions src/util/region/region.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package region

import (
"gui.subtitle/src/srv/mt"
)

type Region int

func (r Region) FromInt(num int) Region {
return Region(num)
}

func (r Region) ToInt() int {
return int(r)
}

func (r Region) GetZh(id mt.Id) string {
switch id {
case mt.IdTencent:
return tencentZHMaps[r]
default:
return ""
}
}

func (r Region) GetZhMaps(id mt.Id) []string {
switch id {
case mt.IdTencent:
return tencentZHMaps
default:
return []string{}
}
}

func (r Region) GetEn(id mt.Id) string {
switch id {
case mt.IdTencent:
return tencentENMaps[r]
default:
return ""
}
}
37 changes: 37 additions & 0 deletions src/util/region/tencent.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package region

const (
T_AP_BeiJing Region = iota
T_AP_ChengDu
T_AP_ChongQing
T_AP_GuangZhou
T_AP_ShangHai
T_AP_ShangHai_FSI
T_AP_ShenZhen_FSI
T_AP_HongKong
T_AP_Mumbai
T_AP_Seoul
T_AP_Bangkok
T_AP_Singapore
T_AP_Tokyo
T_AP_EU_Frankfurt
T_AP_NA_Ashburn
T_AP_Siliconvalley
T_AP_Torronto
)

var (
tencentZHMaps = []string{
"华北地区-北京", "西南地区-成都", "西南地区-重庆", "华南地区-广州", "华东地区-上海",
"华东地区-上海金融", "华南地区-深圳金融", "港澳台地区-中国香港",
"亚太南部-孟买", "亚太东北-首尔", "亚太东南-曼谷", "亚太东南-新加坡", "亚太东北-东京",
"欧洲地区-法兰克福", "美国东部-弗吉尼亚", "美国西部-硅谷", "北美地区-多伦多",
}

tencentENMaps = []string{
"ap-beijing", "ap-chengdu", "ap-chongqing", "ap-guangzhou", "ap-shanghai",
"ap-shanghai-fsi", "ap-shenzhen-fsi", "ap-hongkong",
"ap-mumbai", "ap-seoul", "ap-bangkok", "ap-singapore", "ap-tokyo",
"eu-frankfurt", "na-ashburn", "na-siliconvalley", "na-toronto",
}
)

0 comments on commit 7bf730a

Please sign in to comment.