-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added a view basic translation functions and translation file #137
Conversation
Looks good to me! I've got a couple questions though: Does this require the translation file to be sitting in the user's computer at runtime, or is it baked into the binary at compile time? If it's the former, I'm not sure how best to install that. If the user installs via go-get, that's easy, but it's harder for e.g. direct download from the binary. I'm not sure what the general pattern is for non-english speakers when it comes to these things. Is there usually a translation file that is available alongside the release for the user to download and store somewhere? Or is there some other approach |
IMHO these should be translated too, as well as the error messages. |
@jesseduffield Most programs have all translations in the binary by default. @ponsfrilus Thx for the suggestions i'll see what i can do |
@mjarkk this is fantastic work man I really appreciate the effort. I've just merged a big refactor PR #132 into master, meaning you might need to shuffle some things around to make it mergeable. It's only the first step of the refactor process so it's got some flaws but it removes things like global constants and generally improves the structure of the project. Let me know if you need any help merging with the new master branch |
I have fixed all the merge conflicts |
pkg/i18n/i18n.go
Outdated
@@ -9,12 +9,16 @@ import ( | |||
// the function to setup the localizer | |||
func getlocalizer() *i18n.Localizer { | |||
|
|||
// detect the user's language | |||
userLang, _ := jibber_jabber.DetectLanguage() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIIIICE!
@mjarkk I've just pulled down this branch and have made a couple of changes so that it conforms to the project structure, namely attaching the localizer to the App and Gui structs so that we're not depending on global variables at runtime. Otherwise fantastic job! I'll push my changes now |
I've just realised that we need localization for error messages too. I think that's fixed by just attaching them to the gui as well which I can make a start on now |
Updated to latest master
I've just had to do some reading because I considered just switching back to the package-scoped localizer variable that was there initially so that we can still define our errors at the package level. After that reading it looks like it's still a bad idea to go down that route because functions are far more testable when their only input is their arguments and the properties of their structs. But that means we need to fix up how errors work right now. I think that as a general pattern we should just define errors inline and in the event that we use errors as sentinel values we'll need to define it on the gui struct (ideally we want to minimise use of sentinel errors) the articles I've been reading are I've just pushed some more changes. I'm thinking that now that we can't define our error messages on the package-scope, maybe we should consider using a i18n bundle for storing defaults rather than stating the default in the localize function, otherwise we'll be duplicating a lot of text. edit: if I get the time I'll switch to checking on error type like in here https://github.com/golang/go/wiki/Errors rather than storing these on the Gui |
Not to hijack the thread, but there is something else to take into consideration. Both #95 and #89 are due to indexing on bytes instead of runes in https://github.com/jesseduffield/lazygit/blob/master/pkg/git/branch_list_builder.go#L144. This can be remedied quite easily, but then you must also provide a localization for |
The |
The English translation file as a template is a great idea! Thanks for doing that! |
Jup that's what i thought to :) |
Is it possible to use some kind of translation management system like https://weblate.org with this translation implemetation? |
I'm not sure i need to look into that. I have switched from Toml files for translation to just Go files because they are included in the build binaries because of that it (probably) isn't possible to use a translation service It might be possible to do some magic with a file converter to convert all the .toml files to .go files but that would create 2 copies of everything |
I have maybe found a solution to include Toml files inside the build binaries |
I would go for first solution: .go files. But we need to think about maintainability. Translators would need to be notified somehow about new entries available to translate (maybe permament github issue?). |
Fantastic work man. I agree with using an english translation file, but I think we should take it one step further and not have defaults against the inline-translations. This means if we ever use the same message in different places (as is the case with some error messages) we don't need to duplicate the default string in two places: we can just say gui.Tr.SLocalize(key) and we'll ensure the key is in the english (default) translation file. Then when at startup we initialize the localizer we'll merge the default into whatever specific localization file we're using. What are people's thoughts on this approach? |
Removed all inline translations from gui.Tr.SLocalize and gui.Tr.TemplateLocalize |
pkg/gui/branches_panel.go
Outdated
gui.createPromptPanel(g, v, "New Branch Name (Branch is off of "+branch.Name+")", func(g *gocui.Gui, v *gocui.View) error { | ||
message := gui.Tr.TemplateLocalize( | ||
"NewBranchNameBranchOff", | ||
map[string]interface{}{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this need to be map[string]interface{}
? Are we able to say map[string]string
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Acording to go-i18n yes: https://github.com/nicksnyder/go-i18n#package-i18n-
But i haven't tested something else
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can create a custom type to use:
type Template map[string]interface{}
pkg/gui/files_panel.go
Outdated
} | ||
sub, err := gui.GitCommand.AddPatch(file.Name) | ||
if err != nil { | ||
return err | ||
} | ||
gui.SubProcess = sub | ||
return ErrSubProcess | ||
return nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we make this return gui.Errors.ErrSubProcess
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll test that out and see if the go checker doesn't spam me with errors
pkg/gui/files_panel.go
Outdated
@@ -222,15 +223,15 @@ func (gui *Gui) PrepareSubProcess(g *gocui.Gui, commands ...string) error { | |||
} | |||
gui.SubProcess = sub | |||
g.Update(func(g *gocui.Gui) error { | |||
return ErrSubProcess | |||
return nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same thing here
pkg/gui/files_panel.go
Outdated
@@ -241,7 +242,7 @@ func (gui *Gui) genericFileOpen(g *gocui.Gui, v *gocui.View, open func(string) ( | |||
} | |||
if sub != nil { | |||
gui.SubProcess = sub | |||
return ErrSubProcess | |||
return nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left a couple comments. After those are addressed, I'm happy to merge :)
I hope this fixes this things you asked for :) |
pkg/gui/gui.go
Outdated
@@ -49,6 +49,9 @@ func (gui *Gui) GenerateSentinelErrors() { | |||
} | |||
} | |||
|
|||
// Teml is short for template used to make the required map[string]interface{} shorter when using gui.Tr.SLocalize and gui.Tr.TemplateLocalize |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we put this in the i18n package and then call it as i18n.Temp, just incase we need to call it from another package as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just one thing :)
} | ||
} | ||
|
||
// Teml is short for template used to make the required map[string]interface{} shorter when using gui.Tr.SLocalize and gui.Tr.TemplateLocalize |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we move this to the i18n package and then call it like i18n.Teml
so that we can can access it from any package, not just gui?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed it
@mjarkk thanks again for all the effort you put into this PR it is fantastic work |
NP i really like you're project :) |
What do you think of this way of translations?
Currently it doesn't auto detect the system language because i don't know how to detect that but the translation works when you change the language.English to language.Dutch