From 62fc831407239172f183f7f491222a3aad9d2afa Mon Sep 17 00:00:00 2001 From: mjarkk Date: Mon, 13 Aug 2018 15:33:45 +0200 Subject: [PATCH] Added a view basic translation functions + tranlation file --- Gopkg.toml | 2 +- gui.go | 12 ++++++------ i18n.go | 40 ++++++++++++++++++++++++++++++++++++++++ i18n/nl.toml | 19 +++++++++++++++++++ 4 files changed, 66 insertions(+), 7 deletions(-) create mode 100644 i18n.go create mode 100644 i18n/nl.toml diff --git a/Gopkg.toml b/Gopkg.toml index a47fe5e93..16fd76083 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -39,4 +39,4 @@ [[constraint]] name = "gopkg.in/src-d/go-git.v4" - revision = "43d17e14b714665ab5bc2ecc220b6740779d733f" + revision = "43d17e14b714665ab5bc2ecc220b6740779d733f" \ No newline at end of file diff --git a/gui.go b/gui.go index 589dabea3..f41f2891b 100644 --- a/gui.go +++ b/gui.go @@ -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 } diff --git a/i18n.go b/i18n.go new file mode 100644 index 000000000..a82c29255 --- /dev/null +++ b/i18n.go @@ -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, + }, + }) +} diff --git a/i18n/nl.toml b/i18n/nl.toml new file mode 100644 index 000000000..7d2d3a9a1 --- /dev/null +++ b/i18n/nl.toml @@ -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" \ No newline at end of file