-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f73a26b
commit 3018927
Showing
7 changed files
with
234 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,18 @@ | ||
# redis-desktop | ||
# Redis Desktop | ||
a redis-cli with gui. | ||
|
||
![demo](screenshoot/tabpage.png) | ||
|
||
|
||
# features | ||
# Features | ||
* [x] save sessions | ||
* [x] multi tabpages | ||
* [x] no any dependencies | ||
* [x] i18n | ||
* [ ] batch exec commands | ||
* [ ] other charming features..... | ||
|
||
# thanks | ||
# Thanks | ||
the project is powered by [walk](https://github.com/lxn/walk) and [redigo](https://github.com/gomodule/redigo) | ||
|
||
# license | ||
# License | ||
the porject is under [MIT license](LICENSE) which can be found in LICENSE file. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package i18n | ||
|
||
func init() { | ||
AddLang(en_us) | ||
} | ||
|
||
var en_us = Lang{ | ||
name: "en_us", | ||
Translation: &Translation{ | ||
sections: make([]string, 0), | ||
words: map[string]string{ | ||
"mainwindow.title": "Redis Cli Desktop", | ||
"mainwindow.menu.file": "File", | ||
"mainwindow.menu.file.export": "export", | ||
"mainwindow.menu.file.import": "import", | ||
"mainwindow.menu.edit": "Edit", | ||
"mainwindow.menu.edit.clear": "clear", | ||
"mainwindow.menu.setting": "Setting", | ||
"mainwindow.menu.setting.theme": "theme", | ||
"mainwindow.menu.logpath": "Log Path", | ||
"mainwindow.menu.run": "Run", | ||
"mainwindow.menu.run.batch": "run batch command", | ||
"mainwindow.menu.help": "Help", | ||
"mainwindow.menu.help.source": "view source code", | ||
"mainwindow.menu.help.bug": "new issue", | ||
"mainwindow.menu.help.donate": "donate", | ||
"mainwindow.LBsessions.menu.deletesession": "delete session", | ||
"mainwindow.labelhost": "Host", | ||
"mainwindow.labelport": "Port", | ||
"mainwindow.labelpassword": "Password", | ||
"mainwindow.PBconnect": "Connect", | ||
}, | ||
}, | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
package i18n | ||
|
||
import ( | ||
"fmt" | ||
"reflect" | ||
"strings" | ||
) | ||
|
||
type Lang struct { | ||
name string | ||
*Translation | ||
} | ||
|
||
type langStore struct { | ||
defaultLang Lang | ||
langs map[string]Lang | ||
} | ||
|
||
var defaultStore = langStore{ | ||
langs: make(map[string]Lang), | ||
} | ||
|
||
func SetDefaultLang(lang Lang) { | ||
defaultStore.defaultLang = lang | ||
} | ||
|
||
func AddLang(lang Lang) error { | ||
if _, ok := defaultStore.langs[strings.ToLower(lang.name)]; ok { | ||
return fmt.Errorf("the lang `%s` already exist", lang.name) | ||
} | ||
defaultStore.langs[strings.ToLower(lang.name)] = lang | ||
if defaultStore.defaultLang.name == "" { | ||
defaultStore.defaultLang = lang | ||
} | ||
return nil | ||
} | ||
|
||
func GetLang(name string) (Lang, bool) { | ||
if lang, ok := defaultStore.langs[strings.ToLower(name)]; ok { | ||
return lang, true | ||
} | ||
return Lang{}, false | ||
} | ||
|
||
func (l Lang) Tr(format string, args ...interface{}) string { | ||
return Tr(l.name, format, args...) | ||
} | ||
|
||
type Translation struct { | ||
sections []string | ||
words map[string]string | ||
} | ||
|
||
func (t *Translation) clone() *Translation { | ||
secs := make([]string, len(t.sections)) | ||
copy(secs, t.sections) | ||
return &Translation{ | ||
sections: secs, | ||
words: t.words, | ||
} | ||
} | ||
|
||
func (t *Translation) Section(sec string) *Translation { | ||
t0 := t.clone() | ||
t0.sections = append(t0.sections, sec) | ||
return t0 | ||
} | ||
|
||
func (t *Translation) Get(name string) (string, bool) { | ||
sections := t.sections | ||
sections = append(sections, name) | ||
key := strings.Join(sections, ".") | ||
v, ok := t.words[key] | ||
return v, ok | ||
} | ||
|
||
// Tr translates content to target language. | ||
func Tr(lang, format string, args ...interface{}) string { | ||
language, ok := defaultStore.langs[lang] | ||
if !ok { | ||
language = defaultStore.defaultLang | ||
} | ||
|
||
value, ok := language.Get(format) | ||
if ok { | ||
format = value | ||
} else { | ||
// try default language | ||
value, ok = defaultStore.defaultLang.Get(format) | ||
if ok { | ||
format = value | ||
} | ||
} | ||
|
||
if len(args) > 0 { | ||
params := make([]interface{}, 0, len(args)) | ||
for _, arg := range args { | ||
if arg == nil { | ||
continue | ||
} | ||
|
||
val := reflect.ValueOf(arg) | ||
if val.Kind() == reflect.Slice { | ||
for i := 0; i < val.Len(); i++ { | ||
params = append(params, val.Index(i).Interface()) | ||
} | ||
} else { | ||
params = append(params, arg) | ||
} | ||
} | ||
return fmt.Sprintf(format, params...) | ||
} | ||
return format | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,34 @@ | ||
package i18n | ||
|
||
func init() { | ||
AddLang(zh_ch) | ||
} | ||
|
||
var zh_ch = Lang{ | ||
name: "zh_cn", | ||
Translation: &Translation{ | ||
sections: make([]string, 0), | ||
words: map[string]string{ | ||
"mainwindow.title": "redis命令行工具", | ||
"mainwindow.menu.file": "文件", | ||
"mainwindow.menu.file.export": "导出会话", | ||
"mainwindow.menu.file.import": "导入会话", | ||
"mainwindow.menu.edit": "编辑", | ||
"mainwindow.menu.edit.clear": "清屏", | ||
"mainwindow.menu.setting": "设置", | ||
"mainwindow.menu.setting.theme": "主题", | ||
"mainwindow.menu.logpath": "日志路径", | ||
"mainwindow.menu.run": "运行", | ||
"mainwindow.menu.run.batch": "批量运行命令", | ||
"mainwindow.menu.help": "帮助", | ||
"mainwindow.menu.help.source": "查看源码", | ||
"mainwindow.menu.help.bug": "提bug", | ||
"mainwindow.menu.help.donate": "捐赠", | ||
"mainwindow.LBsessions.menu.deletesession": "删除会话", | ||
"mainwindow.labelhost": "主机", | ||
"mainwindow.labelport": "端口", | ||
"mainwindow.labelpassword": "密码", | ||
"mainwindow.PBconnect": "连接", | ||
}, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.