Skip to content

Commit

Permalink
Merge pull request #103 from expertanalytics/norwegian-fields
Browse files Browse the repository at this point in the history
Norwegian fields
  • Loading branch information
bzapf committed Jan 12, 2024
2 parents c683b18 + 5ae1bf4 commit 77bafbf
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 16 deletions.
19 changes: 19 additions & 0 deletions cvcreator/data/tech_skills.toml
Expand Up @@ -23,6 +23,25 @@ allowed_labels = [
"GUI", # Creating graphical user interfaces
]

[norwegian_labels]

"Tools" = "Verktøy"
"Languages" = "Språk" # Note that "Programeringsspråk" breaks the table columns
# because it is too long
"ML" = "Maskinlæring"
"Modelling" = "Modellering"
"Organize" = "Organisering"
"Cloud" = "Sky"
"Databases" = "Databaser"
"Web" = "Nett"
"Platforms" = "Platformer"
"Testing" = "Testing"
"Visualization" = "Visualisering"
"Office" = "Office"
"Math" = "Matematikk"
"File formats" = "Filformater"
"Editors" = "Editors"
"GUI" = "GUI"

# If we want to group some labels together.
[short_map]
Expand Down
8 changes: 4 additions & 4 deletions cvcreator/templates/vitae.tex
Expand Up @@ -95,10 +95,10 @@
\begin{tabular}{LR}
\BLOCK{for s in education}
\BLOCK{if s.start}\VAR{s.start} -- \VAR{s.end}\BLOCK{else}\VAR{s.end}\BLOCK{endif} &
\BLOCK{if s.degree}{\bf \VAR{s.degree} in \BLOCK{if s.specialization}\VAR{s.specialization}\BLOCK{else}\VAR{s.topic}\BLOCK{endif}}\
\BLOCK{else}\VAR{s.specialization} -- \VAR{s.description}\BLOCK{endif} \
\BLOCK{if s.department or s.university or s.country} at \VAR{[s.department, s.university, s.country]|select()|join(", ")}.\BLOCK{endif} \
\BLOCK{if s.thesis_title}Thesis title: ``\VAR{s.thesis_title}''.\BLOCK{endif} \
\BLOCK{if s.degree}{\bf \VAR{s.degree} \VAR{s.what} \BLOCK{if s.specialization}\VAR{s.specialization}\BLOCK{else}\VAR{s.topic}\BLOCK{endif}}\
\BLOCK{else}\VAR{s.specialization} -- \VAR{s.description}\BLOCK{endif}\
\BLOCK{if s.department or s.university or s.country} \VAR{s.fromwhere} \VAR{[s.department, s.university, s.country]|select()|join(", ")}.\BLOCK{endif} \
\BLOCK{if s.thesis_title}\VAR{s.title}: ``\VAR{s.thesis_title}''.\BLOCK{endif} \
\BLOCK{if s.degree}\VAR{s.description}\BLOCK{endif} \\
\BLOCK{endfor}
\end{tabular}
Expand Down
20 changes: 15 additions & 5 deletions cvcreator/vitae/content.py
Expand Up @@ -2,8 +2,9 @@
from typing import Any, List, Sequence

import toml
from .schema import VitaeContent, SectionTitles, ProjectSubtitles, PublicationSubtitles, Titles
from .tech_skills import make_skill_groups
from .schema import VitaeContent, NorwegianVitaeContent
from .schema import TechnicalSkill
from .tech_skills import make_skill_groups, get_skills_data

CURDIR = f"{os.path.dirname(__file__)}{os.path.sep}"

Expand Down Expand Up @@ -62,20 +63,29 @@ def load_vitae(
assert str(path).endswith(".toml"), (
"must be TOML files with .toml extension.")
with open(path) as src:
content = VitaeContent(**toml.load(src))
if norwegian:
content = NorwegianVitaeContent(**toml.load(src))
else:
content = VitaeContent(**toml.load(src))

# filter projects and publications (as this can not be done in template)
content.project = filter_(projects, content.project)
content.publication = filter_(publications, content.publication)
if norwegian:
content.change_to_norwegian_titles()

# remove potential duplicates from technical skills
content.technical_skill = list(set(content.technical_skill))

# place technical skills into groups
content.technical_skill = make_skill_groups(content.technical_skill)

if norwegian:
norwegian_labels = get_skills_data()["norwegian_labels"]
norwegian_skills = []
for skill in content.technical_skill:
norwegian_skills.append(TechnicalSkill(title=norwegian_labels[skill.title], values=skill.values))

content.technical_skill = norwegian_skills

if badges:
for skill in content.technical_skill:
for idx, value in enumerate(skill.values):
Expand Down
56 changes: 50 additions & 6 deletions cvcreator/vitae/schema.py
Expand Up @@ -77,6 +77,24 @@ class LanguageSkill(StrictModel):
language: Language
proficiency: Literal["Native", "Fluent", "Intermediate", "Basic"]

class NorwegianLanguageSkill(StrictModel):
"""Language skill and proficiency."""

# In principal, it should be possible to map a language name from english to norwegian
# using the following code snippet (which generates a list of language names in norwegian):
# no = gettext.translation("iso639-3", pycountry.LOCALES_DIR,languages=["nb"])
# exceptions = {"English": "Engelsk"}
# LANGUAGE_NAMES_NO = tuple(exceptions[language.name] if language.name in exceptions \
# else no.gettext(language.name)
# for language in pycountry.languages if not no.gettext(language.name) == language.name)
# LanguagesNorwegian = Literal[LANGUAGE_NAMES_NO]
# The problem, however, is that not all language names are translated in the data base, and hence one would have to
# treat that. Thus for now, the user has to enter the correct norwegian name for the language in the toml file
# and type(language) is str.
language: str
proficiency: Literal["Morsmål", "Flytende", "Middels", "Grunnleggende"]



class PersonalSkill(StrictModel):
"""A personal skill and description."""
Expand Down Expand Up @@ -110,8 +128,32 @@ class Education(StrictModel):
university: str = ""
country: Country = ""
description: str = ""
title: str = "Thesis title" # used for printing the education in latex
what : str = "in" # used for printing the education in latex
fromwhere : str = "at" # used for printing the education in latex


class NorwegianEducation(StrictModel):
"""Completed educational degree."""

start: int = 0
end: int = 0
degree: Literal["Mastergrad", "PhD",
""] = ""
topic: Literal["Fysikk", "Scientific Computing", "Mekanikk",
"Matematikk", "Engineering", "Kjemi",
"Geologi og Geofysikk", "informatikk", "Musikk",
] = ""
specialization: str = ""
thesis_title: str = ""
department: str = ""
university: str = ""
country: Country = ""
description: str = ""
title: str = "Avhandlingens tittel" # used for printing the education in latex
what : str = "innen" # used for printing the education in latex
fromwhere : str = "fra" # used for printing the education in latex

class Work(StrictModel):
"""Previous work experience."""

Expand Down Expand Up @@ -169,8 +211,8 @@ class SectionTitles(StrictModel):
technical_skills: str = "Technical Skills"
languages: str = "Languages"
personal_skills: str = "Personal Skills"
hobbies: str = "Interests and hobbies"
projects: str = "Extended description of selected projects"
hobbies: str = "Interests and Hobbies"
projects: str = "Extended Description of Selected Projects"
publications: str = "Publications"


Expand Down Expand Up @@ -234,12 +276,14 @@ class VitaeContent(StrictModel):
project: List[Project] = Field(default_factory=list)
publication: List[Publications] = Field(default_factory=list)

def change_to_norwegian_titles(self):
self.titles = _create_norwegian_titles()

class NorwegianVitaeContent(VitaeContent):

language_skill: List[NorwegianLanguageSkill] = Field(default_factory=list)

education: List[NorwegianEducation] = Field(default_factory=list)

def _create_norwegian_titles() -> Titles:
return Titles(
titles: Titles = Titles(
section_titles=SectionTitles(
professional_experience="Arbeidserfaring",
education="Utdanning",
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
@@ -1,6 +1,6 @@
[tool.poetry]
name = "cvcreator"
version = "1.1.12"
version = "1.1.14"
description = "An automated tool for creating CVs on the fly."
authors = ["Jonathan Feinberg <jonathf@gmail.com>"]
license = "mit"
Expand Down
6 changes: 6 additions & 0 deletions test/test_tech_skills.py
Expand Up @@ -34,3 +34,9 @@ def test_short_maps(skills_data):
unknown_vals = set(skills_data["short_map"].values()).difference(skills_data["skills"])
assert not unknown_vals, f"Shortmap value not recognized: {unknown_vals}"


def test_skill_translation(skills_data):

norwegian_labels = get_skills_data()["norwegian_labels"]
for label in skills_data["allowed_labels"]:
assert label in norwegian_labels.keys()

0 comments on commit 77bafbf

Please sign in to comment.