1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2024-11-30 09:16:47 +02:00

Added a view basic translation functions + tranlation file

This commit is contained in:
mjarkk 2018-08-13 15:33:45 +02:00
parent 1571e6b962
commit 62fc831407
4 changed files with 66 additions and 7 deletions

View File

@ -39,4 +39,4 @@
[[constraint]]
name = "gopkg.in/src-d/go-git.v4"
revision = "43d17e14b714665ab5bc2ecc220b6740779d733f"
revision = "43d17e14b714665ab5bc2ecc220b6740779d733f"

12
gui.go
View File

@ -157,7 +157,7 @@ func layout(g *gocui.Gui) error {
if err != gocui.ErrUnknownView {
return err
}
v.Title = "Status"
v.Title = ShortLocalize("StatusTitle", "Status")
v.FgColor = gocui.ColorWhite
}
@ -167,7 +167,7 @@ func layout(g *gocui.Gui) error {
return err
}
filesView.Highlight = true
filesView.Title = "Files"
filesView.Title = ShortLocalize("FilesTitle", "Files")
v.FgColor = gocui.ColorWhite
}
@ -175,7 +175,7 @@ func layout(g *gocui.Gui) error {
if err != gocui.ErrUnknownView {
return err
}
v.Title = "Branches"
v.Title = ShortLocalize("BranchesTitle", "Branches")
v.FgColor = gocui.ColorWhite
}
@ -183,7 +183,7 @@ func layout(g *gocui.Gui) error {
if err != gocui.ErrUnknownView {
return err
}
v.Title = "Commits"
v.Title = ShortLocalize("CommitsTitle", "Commits")
v.FgColor = gocui.ColorWhite
}
@ -191,7 +191,7 @@ func layout(g *gocui.Gui) error {
if err != gocui.ErrUnknownView {
return err
}
v.Title = "Stash"
v.Title = ShortLocalize("StashTitle", "Stash")
v.FgColor = gocui.ColorWhite
}
@ -210,7 +210,7 @@ func layout(g *gocui.Gui) error {
return err
}
g.SetViewOnBottom("commitMessage")
commitMessageView.Title = "Commit message"
commitMessageView.Title = ShortLocalize("CommitMessage", "Commit message")
commitMessageView.FgColor = gocui.ColorWhite
commitMessageView.Editable = true
}

40
i18n.go Normal file
View File

@ -0,0 +1,40 @@
package main
import (
"github.com/BurntSushi/toml"
"github.com/nicksnyder/go-i18n/v2/i18n"
"golang.org/x/text/language"
)
// the function to setup the localizer
func getlocalizer() *i18n.Localizer {
// TODO: currently the system language issn't detected
// I'm not sure how to detect it
var i18nObject = &i18n.Bundle{DefaultLanguage: language.English}
i18nObject.RegisterUnmarshalFunc("toml", toml.Unmarshal)
i18nObject.MustLoadMessageFile("i18n/nl.toml")
return i18n.NewLocalizer(i18nObject)
}
// setup the localizer for later use
var localizer = getlocalizer()
// MustLocalize handels the translations
// expects i18n.LocalizeConfig as input: https://godoc.org/github.com/nicksnyder/go-i18n/v2/i18n#Localizer.MustLocalize
// output: translated string
func MustLocalize(config *i18n.LocalizeConfig) string {
return localizer.MustLocalize(config)
}
// ShortLocalize is for 1 line localizations
// ID: The id that is used in the .toml translation files
// Other: the default message it needs to return if there is no translation found or the system is english
func ShortLocalize(ID string, Other string) string {
return MustLocalize(&i18n.LocalizeConfig{
DefaultMessage: &i18n.Message{
ID: ID,
Other: Other,
},
})
}

19
i18n/nl.toml Normal file
View File

@ -0,0 +1,19 @@
# The dutch translation for this program
[FilesTitle]
other = "Bestanden"
[BranchesTitle]
other = "Branches"
[CommitsTitle]
other = "Commits"
[StashTitle]
other = "Stash"
[CommitMessage]
other = "Commit Bericht"
[StatusTitle]
other = "Status"