diff --git a/src/srv/mt/aliyun/ali_mt.go b/src/srv/mt/aliyun/ali_mt.go index 68c231a..d5b3601 100644 --- a/src/srv/mt/aliyun/ali_mt.go +++ b/src/srv/mt/aliyun/ali_mt.go @@ -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() } @@ -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 { diff --git a/src/ui/ui.go b/src/ui/ui.go index ddbe511..d3daab7 100644 --- a/src/ui/ui.go +++ b/src/ui/ui.go @@ -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" @@ -52,7 +53,6 @@ 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 @@ -60,7 +60,7 @@ func (aw *AppWindow) newMainWindow() error { var tencentIdEdit *walk.TextEdit var tencentKeyEdit *walk.TextEdit - var tencentRegionEdit *walk.TextEdit + var tencentRegionComboBox *walk.ComboBox var fromLanguageComboBox *walk.ComboBox var toLanguageComboBox *walk.ComboBox @@ -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 邮箱: speauty@163.com", Alignment: AlignHCenterVCenter}, + Label{Text: "版本号: 1.1.9 作者: speauty 邮箱: speauty@163.com", Alignment: AlignHCenterVCenter}, GroupBox{ Layout: HBox{}, Children: []Widget{ @@ -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{ @@ -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{ @@ -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{ @@ -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{}, }, }, @@ -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()} @@ -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) @@ -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{}, diff --git a/src/util/region/region.go b/src/util/region/region.go new file mode 100644 index 0000000..aab8d6d --- /dev/null +++ b/src/util/region/region.go @@ -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 "" + } +} diff --git a/src/util/region/tencent.go b/src/util/region/tencent.go new file mode 100644 index 0000000..23d959e --- /dev/null +++ b/src/util/region/tencent.go @@ -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", + } +)