From a286b61c5881dad85e94919150846ac995b30d44 Mon Sep 17 00:00:00 2001 From: Jarno Rankinen Date: Sat, 10 Feb 2024 14:54:20 +0200 Subject: [PATCH] Translations & certificates - Translation system, possibility to define different language using meta.language setting - Only en-EN and fi-FI implemented - Added certificates section, for miscellaneous certs and licences --- main.go | 13 +++++++++-- resume.go | 39 ++++++++++++++++++--------------- static/css/dark-style.css | 3 +++ static/css/dark-style.scss | 4 ++++ strings.go | 34 ++++++++++++++++++++++++++++ templates/index.html | 45 +++++++++++++++++++++++++++++--------- 6 files changed, 108 insertions(+), 30 deletions(-) create mode 100644 strings.go diff --git a/main.go b/main.go index ec210b3..a7502dd 100644 --- a/main.go +++ b/main.go @@ -17,8 +17,10 @@ import ( var static embed.FS var templates map[string]*template.Template var configFile string +var strs map[string]map[string]string func main() { + loadStrings() cfgFile := flag.String("config", "./data/resume.yaml", "Path to the configuration YAML") flag.Parse() @@ -53,7 +55,9 @@ func home(w http.ResponseWriter, r *http.Request) { "templates/metatag.html", "templates/githubCorner.html", } - tmpl, err := template.ParseFS(static, templateFiles...) + var err error + tmpl := template.New("index").Funcs(templateFunctions()) + tmpl, err = tmpl.ParseFS(static, templateFiles...) if err != nil { slog.Error(err.Error()) http.Error(w, "Server error", http.StatusInternalServerError) @@ -69,7 +73,6 @@ func home(w http.ResponseWriter, r *http.Request) { data.Theme = urlSlice[len(urlSlice)-1] } data.Year = time.Now().Format("2006") - tmpl.Funcs(templateFunctions()) err = tmpl.Execute(w, *data) if err != nil { slog.Error(err.Error()) @@ -82,5 +85,11 @@ func templateFunctions() template.FuncMap { "html": func(raw string) template.HTML { return template.HTML(raw) }, + "translate": func(label, lang string) string { + if strs[lang][label] == "" { + return label + " (no translation)" + } + return strs[lang][label] + }, } } diff --git a/resume.go b/resume.go index 865ea45..39c7568 100644 --- a/resume.go +++ b/resume.go @@ -13,19 +13,20 @@ type Resume struct { } type Profile struct { - Name string `yaml:"name"` - Title string `yaml:"title"` - City string `yaml:"city"` - Phone string `yaml:"phone"` - Email string `yaml:"email"` - Socials Socials `yaml:"socials"` - Photo string `yaml:"photo"` - Summary string `yaml:"summary"` - Experience []Job `yaml:"experience"` - Education []Education `yaml:"education"` - Skills []Skill `yaml:"skills"` - Projects any `yaml:"projects"` - Languages []Language `yaml:"languages"` + Name string `yaml:"name"` + Title string `yaml:"title"` + City string `yaml:"city"` + Phone string `yaml:"phone"` + Email string `yaml:"email"` + Socials Socials `yaml:"socials"` + Photo string `yaml:"photo"` + Summary string `yaml:"summary"` + Experience []Job `yaml:"experience"` + Education []Education `yaml:"education"` + Skills []Skill `yaml:"skills"` + Projects any `yaml:"projects"` + Languages []Language `yaml:"languages"` + Certificates []Certificate `yaml:"certificates"` } func (p *Profile) GetTagWidth(t string) string { @@ -47,9 +48,9 @@ func (p *Profile) GetTagWidth(t string) string { return fmt.Sprintf("%dch", l) } -func (job *Job) html(raw string) template.HTML { - return template.HTML(raw) -} +//func (job *Job) html(raw string) template.HTML { +// return template.HTML(raw) +//} type Job struct { Company string `yaml:"company"` @@ -92,8 +93,6 @@ func (language *Language) VisualLevel(level int) template.HTML { return _visualLevel(level) } -type skills []Skill - type Social struct { Media string `yaml:"media"` UserId string `yaml:"userId"` @@ -116,3 +115,7 @@ type Language struct { Name string `yaml:"name"` Level int `yaml:"level"` } + +type Certificate struct { + Name string `yaml:"name"` +} diff --git a/static/css/dark-style.css b/static/css/dark-style.css index 0db26d8..1b94f96 100644 --- a/static/css/dark-style.css +++ b/static/css/dark-style.css @@ -11,3 +11,6 @@ .subtitle { color: var(--subtitle-color); } + +.tag:not(body).is-primary { + color: #2f2f2f; } diff --git a/static/css/dark-style.scss b/static/css/dark-style.scss index 1568ee6..20db250 100644 --- a/static/css/dark-style.scss +++ b/static/css/dark-style.scss @@ -14,4 +14,8 @@ .subtitle { color: var(--subtitle-color); +} + +.tag:not(body).is-primary { + color: #2f2f2f; } \ No newline at end of file diff --git a/strings.go b/strings.go new file mode 100644 index 0000000..f7ac568 --- /dev/null +++ b/strings.go @@ -0,0 +1,34 @@ +package main + +func loadStrings() { + strs = make(map[string]map[string]string) + strs["en-EN"] = make(map[string]string) + strs["en-EN"] = map[string]string{ + "summary": "SUMMARY", + "experience": "EXPERIENCE", + "education": "EDUCATION", + "projects": "PROJECTS", + "skills": "SKILLS", + "languages": "LANGUAGES", + "certificates": "CERTIFICATES, LICENSES ETC", + "see_dark": "See Dark Theme", + "see_light": "See Light Theme", + "all_rights_reserved": "All Rights Reserved.", + "powered_by": "Powered by go-resume", + } + + strs["fi-FI"] = make(map[string]string) + strs["fi-FI"] = map[string]string{ + "summary": "YLEISTÄ", + "experience": "TYÖKOKEMUS", + "education": "KOULUTUS", + "projects": "PROJEKTIT", + "skills": "TAIDOT", + "languages": "KIELITAITO", + "certificates": "LUVAT, TODISTUKSET YM.", + "see_dark": "Tumma teema", + "see_light": "Vaalea teema", + "all_rights_reserved": "Kaikki oikeudet pidätetään.", + "powered_by": "Luotu käyttäen sovellusta go-resume", + } +} diff --git a/templates/index.html b/templates/index.html index 385479d..c22c9f3 100644 --- a/templates/index.html +++ b/templates/index.html @@ -1,3 +1,7 @@ +{{ define "index" }} + +{{ $lang := .Meta.Language }} + @@ -71,7 +75,7 @@
- SUMMARY + {{ translate "summary" $lang }}
{{ .Profile.Summary }}
@@ -79,7 +83,7 @@ {{ with .Profile.Experience }}
- EXPERIENCE + {{ translate "experience" $lang }}
@@ -113,7 +117,7 @@ {{ with .Profile.Education }}
- EDUCATION + {{ translate "education" $lang }}
{{ range . }} @@ -141,9 +145,10 @@ {{ with .Profile.Projects }}
- PROJECTS + {{ translate "projects" $lang }}
+ <% content.data.projects.forEach(function(proj){ %>
@@ -160,7 +165,7 @@ {{ with .Profile.Skills }}
- SKILLS + {{ translate "skills" $lang }}
{{ range . }} @@ -182,7 +187,7 @@ {{ with .Profile.Languages }}
- LANGUAGES + {{ translate "languages" $lang }}
{{ range . }} @@ -200,6 +205,25 @@
{{ end }} + + {{ with .Profile.Certificates }} +
+
+ {{ translate "certificates" $lang }} +
+ + {{ range . }} +
+
+
+ {{ .Name }} +
+ +
+
+ {{ end }} +
+ {{ end }}
{{ end }}
@@ -209,14 +233,14 @@ @@ -225,3 +249,4 @@ +{{ end }} \ No newline at end of file