Skip to content

Commit

Permalink
add get_required_translations.go
Browse files Browse the repository at this point in the history
  • Loading branch information
jesseduffield committed Jul 7, 2019
1 parent df7f9c4 commit cfd47b2
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 18 deletions.
2 changes: 0 additions & 2 deletions pkg/i18n/english.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package i18n

// TranslationSet is a set of localised strings for a given language
type TranslationSet struct {
AddFavourite string
ErrorMessage string
NotEnoughSpace string
ProjectTitle string
MainTitle string
Expand Down
29 changes: 15 additions & 14 deletions pkg/i18n/i18n.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,26 @@ func NewTranslationSet(log *logrus.Entry) *TranslationSet {

log.Info("language: " + userLang)

set := englishSet()
baseSet := englishSet()

if strings.HasPrefix(userLang, "pl") {
_ = mergo.Merge(&set, polishSet(), mergo.WithOverride)
for languageCode, translationSet := range GetTranslationSets() {
if strings.HasPrefix(userLang, languageCode) {
_ = mergo.Merge(&baseSet, translationSet, mergo.WithOverride)
}
}

if strings.HasPrefix(userLang, "nl") {
_ = mergo.Merge(&set, dutchSet(), mergo.WithOverride)
}

if strings.HasPrefix(userLang, "de") {
_ = mergo.Merge(&set, germanSet(), mergo.WithOverride)
}
return &baseSet
}

if strings.HasPrefix(userLang, "tr") {
_ = mergo.Merge(&set, turkishSet(), mergo.WithOverride)
// GetTranslationSets gets all the translation sets, keyed by language code
func GetTranslationSets() map[string]TranslationSet {
return map[string]TranslationSet{
"pl": polishSet(),
"nl": dutchSet(),
"de": germanSet(),
"tr": turkishSet(),
"en": englishSet(),
}

return &set
}

// detectLanguage extracts user language from environment
Expand Down
4 changes: 2 additions & 2 deletions scripts/generate_cheatsheet.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/jesseduffield/lazydocker/pkg/app"
"github.com/jesseduffield/lazydocker/pkg/config"
"github.com/jesseduffield/lazydocker/pkg/gui"
"github.com/jesseduffield/lazydocker/pkg/i18n"
)

type bindingSection struct {
Expand All @@ -25,13 +26,12 @@ type bindingSection struct {
}

func main() {
langs := []string{"pl", "nl", "en"}
mConfig, err := config.NewAppConfig("lazydocker", "", "", "", "", true, nil, "")
if err != nil {
panic(err)
}

for _, lang := range langs {
for lang := range i18n.GetTranslationSets() {
os.Setenv("LC_ALL", lang)
mApp, _ := app.NewApp(mConfig)
file, err := os.Create(getProjectRoot() + "/docs/keybindings/Keybindings_" + lang + ".md")
Expand Down
30 changes: 30 additions & 0 deletions scripts/translations/get_required_translations.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package main

import (
"fmt"
"reflect"

"github.com/jesseduffield/lazydocker/pkg/i18n"
)

func main() {
fmt.Println(getOutstandingTranslations())
}

// adapted from https://github.com/a8m/reflect-examples#read-struct-tags
func getOutstandingTranslations() string {
output := ""
for languageCode, translationSet := range i18n.GetTranslationSets() {
output += languageCode + ":\n"
v := reflect.ValueOf(translationSet)

for i := 0; i < v.NumField(); i++ {
value := v.Field(i).String()
if value == "" {
output += v.Type().Field(i).Name + "\n"
}
}
output += "\n"
}
return output
}

0 comments on commit cfd47b2

Please sign in to comment.