Skip to content

Commit

Permalink
fix: Multilingual setup jskherman#11
Browse files Browse the repository at this point in the history
Add possibility to have more languages than en (de for now)
  • Loading branch information
573 committed Jan 10, 2025
1 parent 8d0a4c5 commit 950c21f
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 52 deletions.
84 changes: 49 additions & 35 deletions cv.typ
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
#import "utils.typ"

#let i18n = yaml("i18n.yml")

#let setstrings(uservars) = {
let strings
if uservars.lang == "en" {
strings = i18n.en
} else if uservars.lang == "de" {
strings = i18n.de
}

strings
}

// set rules
#let setrules(uservars, doc) = {
set text(
font: uservars.bodyfont,
size: uservars.fontsize,
hyphenate: false,
lang: uservars.lang,
)

set list(
Expand All @@ -28,7 +42,7 @@
): it => block(width: 100%)[
#v(uservars.sectionspacing)
#set align(left)
#set text(font: uservars.headingfont, size: 1em, weight: "bold")
#set text(font: uservars.headingfont, size: 1em, weight: "bold", lang: uservars.lang)
#if (uservars.at("headingsmallcaps", default:false)) {
smallcaps(it.body)
} else {
Expand All @@ -41,7 +55,7 @@
show heading.where(
level: 1,
): it => block(width: 100%)[
#set text(font: uservars.headingfont, size: 1.5em, weight: "bold")
#set text(font: uservars.headingfont, size: 1.5em, weight: "bold", lang: uservars.lang)
#if (uservars.at("headingsmallcaps", default:false)) {
smallcaps(it.body)
} else {
Expand Down Expand Up @@ -118,9 +132,9 @@
]
}

#let cvwork(info, title: "Work Experience", isbreakable: true) = {
#let cvwork(info, strings, isbreakable: true) = {
if ("work" in info) and (info.work != none) {block[
== #title
== #strings.work
#for w in info.work {
block(width: 100%, breakable: isbreakable)[
// Line 1: Company and Location
Expand All @@ -136,8 +150,8 @@
if index != 0 {v(0.6em)}
block(width: 100%, breakable: isbreakable, above: 0.6em)[
// Parse ISO date strings into datetime objects
#let start = utils.strpdate(p.startDate)
#let end = utils.strpdate(p.endDate)
#let start = utils.strpdate(p.startDate, strings)
#let end = utils.strpdate(p.endDate, strings)
// Line 2: Position and Date Range
#text(style: "italic")[#p.position] #h(1fr)
#utils.daterange(start, end) \
Expand All @@ -152,16 +166,16 @@
]}
}

#let cveducation(info, title: "Education", isbreakable: true) = {
#let cveducation(info, strings, isbreakable: true) = {
if ("education" in info) and (info.education != none) {block[
== #title
== #strings.education
#for edu in info.education {
let start = utils.strpdate(edu.startDate)
let end = utils.strpdate(edu.endDate)
let start = utils.strpdate(edu.startDate, strings)
let end = utils.strpdate(edu.endDate, strings)

let edu-items = ""
if ("honors" in edu) and (edu.honors != none) {edu-items = edu-items + "- *Honors*: " + edu.honors.join(", ") + "\n"}
if ("courses" in edu) and (edu.courses != none) {edu-items = edu-items + "- *Courses*: " + edu.courses.join(", ") + "\n"}
if ("honors" in edu) and (edu.honors != none) {edu-items = edu-items + "- *" + strings.honors + "*: " + edu.honors.join(", ") + "\n"}
if ("courses" in edu) and (edu.courses != none) {edu-items = edu-items + "- *" + strings.courses + "*: " + edu.courses.join(", ") + "\n"}
if ("highlights" in edu) and (edu.highlights != none) {
for hi in edu.highlights {
edu-items = edu-items + "- " + hi + "\n"
Expand Down Expand Up @@ -190,13 +204,13 @@
]}
}

#let cvaffiliations(info, title: "Leadership and Activities", isbreakable: true) = {
#let cvaffiliations(info, strings, isbreakable: true) = {
if ("affiliations" in info) and (info.affiliations != none) {block[
== #title
== #strings.leadership
#for org in info.affiliations {
// Parse ISO date strings into datetime objects
let start = utils.strpdate(org.startDate)
let end = utils.strpdate(org.endDate)
let start = utils.strpdate(org.startDate, strings)
let end = utils.strpdate(org.endDate, strings)

// Create a block layout for each affiliation entry
block(width: 100%, breakable: isbreakable)[
Expand All @@ -220,13 +234,13 @@
]}
}

#let cvprojects(info, title: "Projects", isbreakable: true) = {
#let cvprojects(info, strings, isbreakable: true) = {
if ("projects" in info) and (info.projects != none) {block[
== #title
== #strings.projects
#for project in info.projects {
// Parse ISO date strings into datetime objects
let start = utils.strpdate(project.startDate)
let end = utils.strpdate(project.endDate)
let start = utils.strpdate(project.startDate, strings)
let end = utils.strpdate(project.endDate, strings)
// Create a block layout for each project entry
block(width: 100%, breakable: isbreakable)[
// Line 1: Project Name
Expand All @@ -246,12 +260,12 @@
]}
}

#let cvawards(info, title: "Honors and Awards", isbreakable: true) = {
#let cvawards(info, strings, isbreakable: true) = {
if ("awards" in info) and (info.awards != none) {block[
== #title
== #strings.awards
#for award in info.awards {
// Parse ISO date strings into datetime objects
let date = utils.strpdate(award.date)
let date = utils.strpdate(award.date, strings)
// Create a block layout for each award entry
block(width: 100%, breakable: isbreakable)[
// Line 1: Award Title and Location
Expand All @@ -273,13 +287,13 @@
]}
}

#let cvcertificates(info, title: "Licenses and Certifications", isbreakable: true) = {
#let cvcertificates(info, strings, isbreakable: true) = {
if ("certificates" in info) and (info.certificates != none) {block[
== #title
== #strings.certificates

#for cert in info.certificates {
// Parse ISO date strings into datetime objects
let date = utils.strpdate(cert.date)
let date = utils.strpdate(cert.date, strings)
// Create a block layout for each certificate entry
block(width: 100%, breakable: isbreakable)[
// Line 1: Certificate Name and ID (if applicable)
Expand All @@ -299,12 +313,12 @@
]}
}

#let cvpublications(info, title: "Research and Publications", isbreakable: true) = {
#let cvpublications(info, strings, isbreakable: true) = {
if ("publications" in info) and (info.publications != none) {block[
== #title
== #strings.publications
#for pub in info.publications {
// Parse ISO date strings into datetime objects
let date = utils.strpdate(pub.releaseDate)
let date = utils.strpdate(pub.releaseDate, strings)
// Create a block layout for each publication entry
block(width: 100%, breakable: isbreakable)[
// Line 1: Publication Title
Expand All @@ -324,30 +338,30 @@
]}
}

#let cvskills(info, title: "Skills, Languages, Interests", isbreakable: true) = {
#let cvskills(info, strings, isbreakable: true) = {
if (("languages" in info) or ("skills" in info) or ("interests" in info)) and ((info.languages != none) or (info.skills != none) or (info.interests != none)) {block(breakable: isbreakable)[
== #title
== #strings.skills
#if ("languages" in info) and (info.languages != none) [
#let langs = ()
#for lang in info.languages {
langs.push([#lang.language (#lang.fluency)])
}
- *Languages*: #langs.join(", ")
- *#strings.languages*: #langs.join(", ")
]
#if ("skills" in info) and (info.skills != none) [
#for group in info.skills [
- *#group.category*: #group.skills.join(", ")
]
]
#if ("interests" in info) and (info.interests != none) [
- *Interests*: #info.interests.join(", ")
- *#strings.interests*: #info.interests.join(", ")
]
]}
}

#let cvreferences(info, title: "References", isbreakable: true) = {
#let cvreferences(info, strings, isbreakable: true) = {
if ("references" in info) and (info.references != none) {block[
== #title
== #strings.references
#for ref in info.references {
block(width: 100%, breakable: isbreakable)[
#if ("url" in ref) and (ref.url != none) [
Expand Down
58 changes: 58 additions & 0 deletions i18n.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
en:
work: Work Experience
present: Present
education: Education
courses: Courses
leadership: Leadership & Activities
projects: Projects
skills: Skills, Languages, Interests
languages: Languages
interests: Interests
awards: Honors and Awards
honors: Honors
certificates: Licenses and Certifications
publications: Research and Publications
references: References
updated: Last updated on
january: January
march: March
february: February
april: April
may: May
june: June
july: July
august: August
september: September
october: October
november: November
december: December

de:
work: Arbeitserfahrungen
present: Jetzt
education: Bildung
courses: Kurse
leadership: Funktionen & Aktivitäten
projects: Projekte
skills: Fähigkeiten, Sprachen, Interessen
languages: Sprachen
interests: Interessen
awards: Titel und Auszeichnungen
honors: Titel
certificates: Lizensen und Zertifizierungen
publications: Forschung und Veröffentlichungen
references: Referenzen
updated: Zuletzt geändert am
january: Januar
march: März
february: Februar
april: April
may: Mai
june: Juni
july: Juli
august: August
september: September
october: Oktober
november: November
december: Dezember

1 change: 1 addition & 0 deletions template/template.typ
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
showTitle: true, // bool
headingsmallcaps: false, // bool
sendnote: false, // bool. set to false to have sideways endnote
lang: en, // format of ISO 639-1/2/3
)

// setrules and showrules can be overridden by re-declaring it here
Expand Down
34 changes: 17 additions & 17 deletions utils.typ
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
// Helper Functions
#let monthname(n, display: "short") = {
#let monthname(n, strings, display: "short") = {
n = int(n)
let month = ""

if n == 1 { month = "January" }
else if n == 3 { month = "March" }
else if n == 2 { month = "February" }
else if n == 4 { month = "April" }
else if n == 5 { month = "May" }
else if n == 6 { month = "June" }
else if n == 7 { month = "July" }
else if n == 8 { month = "August" }
else if n == 9 { month = "September" }
else if n == 10 { month = "October" }
else if n == 11 { month = "November" }
else if n == 12 { month = "December" }
if n == 1 { month = strings.january }
else if n == 3 { month = strings.march }
else if n == 2 { month = strings.february }
else if n == 4 { month = strings.april }
else if n == 5 { month = strings.may }
else if n == 6 { month = strings.june }
else if n == 7 { month = strings.july }
else if n == 8 { month = strings.august }
else if n == 9 { month = strings.september }
else if n == 10 { month = strings.october }
else if n == 11 { month = strings.november }
else if n == 12 { month = strings.december }
else { month = none }
if month != none {
if display == "short" {
month = month.slice(0, 3)
month = month.codepoints().slice(0, 3).join()
} else {
month
}
}
month
}

#let strpdate(isodate) = {
#let strpdate(isodate, strings) = {
let date = ""
if lower(isodate) != "present" {
let year = int(isodate.slice(0, 4))
let month = int(isodate.slice(5, 7))
let day = int(isodate.slice(8, 10))
let monthName = monthname(month, display: "short")
let monthName = monthname(month, strings, display: "short")
date = datetime(year: year, month: month, day: day)
date = monthName + " " + date.display("[year repr:full]")
} else if lower(isodate) == "present" {
date = "Present"
date = strings.present
}
return date
}
Expand Down

0 comments on commit 950c21f

Please sign in to comment.