mirror of
https://github.com/rendercv/rendercv.git
synced 2025-12-23 21:47:55 -05:00
fix locale_catalog (#275)
This commit is contained in:
@@ -4,4 +4,4 @@ as a PDF from a YAML file with Markdown syntax support and complete control over
|
||||
$\\LaTeX$ code.
|
||||
"""
|
||||
|
||||
__version__ = "1.17"
|
||||
__version__ = "1.18"
|
||||
|
||||
@@ -16,8 +16,6 @@ class LocaleCatalog(RenderCVBaseModelWithoutExtraKeys):
|
||||
updates the `locale_catalog` dictionary.
|
||||
"""
|
||||
|
||||
model_config = pydantic.ConfigDict(validate_default=True)
|
||||
|
||||
phone_number_format: Optional[Literal["national", "international", "E164"]] = (
|
||||
pydantic.Field(
|
||||
default="national",
|
||||
|
||||
@@ -36,7 +36,7 @@ class RenderCVDataModel(RenderCVBaseModelWithoutExtraKeys):
|
||||
),
|
||||
)
|
||||
locale_catalog: LocaleCatalog = pydantic.Field(
|
||||
default=LocaleCatalog(),
|
||||
default=None, # type: ignore
|
||||
title="Locale Catalog",
|
||||
description=(
|
||||
"The locale catalog of the CV to allow the support of multiple languages."
|
||||
@@ -65,12 +65,15 @@ class RenderCVDataModel(RenderCVBaseModelWithoutExtraKeys):
|
||||
|
||||
return model
|
||||
|
||||
@pydantic.field_validator("locale_catalog")
|
||||
@pydantic.field_validator("locale_catalog", mode="before")
|
||||
@classmethod
|
||||
def update_locale_catalog(cls, _) -> LocaleCatalog:
|
||||
def update_locale_catalog(cls, value) -> LocaleCatalog:
|
||||
"""Update the output folder name in the RenderCV settings."""
|
||||
# Somehow, we need this for `test_if_local_catalog_resets` to pass.
|
||||
return LocaleCatalog()
|
||||
if value is None:
|
||||
return LocaleCatalog()
|
||||
|
||||
return value
|
||||
|
||||
|
||||
rendercv_data_model_fields = tuple(RenderCVDataModel.model_fields.keys())
|
||||
|
||||
@@ -774,3 +774,84 @@ def test_render_pdf_invalid_latex_file(tmp_path):
|
||||
|
||||
with pytest.raises(RuntimeError):
|
||||
renderer.render_a_pdf_from_latex(latex_file_path)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"theme_name",
|
||||
data.available_themes,
|
||||
)
|
||||
@time_machine.travel("2024-01-01")
|
||||
def test_locale_catalog(
|
||||
theme_name,
|
||||
tmp_path,
|
||||
):
|
||||
cv = data.CurriculumVitae(
|
||||
name="Test",
|
||||
sections={
|
||||
"Normal Entries": [
|
||||
data.NormalEntry(
|
||||
name="Test",
|
||||
start_date="2024-01-01",
|
||||
end_date="present",
|
||||
),
|
||||
]
|
||||
},
|
||||
)
|
||||
|
||||
# "The style of the date. The following placeholders can be"
|
||||
# " used:\n-FULL_MONTH_NAME: Full name of the month\n- MONTH_ABBREVIATION:"
|
||||
# " Abbreviation of the month\n- MONTH: Month as a number\n-"
|
||||
# " MONTH_IN_TWO_DIGITS: Month as a number in two digits\n- YEAR: Year as a"
|
||||
# " number\n- YEAR_IN_TWO_DIGITS: Year as a number in two digits\nThe"
|
||||
# ' default value is "MONTH_ABBREVIATION YEAR".'
|
||||
locale_catalog = data.LocaleCatalog(
|
||||
abbreviations_for_months=[
|
||||
"Abbreviation of Jan",
|
||||
"Feb",
|
||||
"Mar",
|
||||
"Apr",
|
||||
"May",
|
||||
"Jun",
|
||||
"Jul",
|
||||
"Aug",
|
||||
"Sep",
|
||||
"Oct",
|
||||
"Nov",
|
||||
"Dec",
|
||||
],
|
||||
full_names_of_months=[
|
||||
"Full name of January",
|
||||
"February",
|
||||
"March",
|
||||
"April",
|
||||
"May",
|
||||
"June",
|
||||
"July",
|
||||
"August",
|
||||
"September",
|
||||
"October",
|
||||
"November",
|
||||
"December",
|
||||
],
|
||||
present="this is present",
|
||||
to="this is to",
|
||||
date_style=(
|
||||
"FULL_MONTH_NAME MONTH_ABBREVIATION MONTH MONTH_IN_TWO_DIGITS YEAR"
|
||||
" YEAR_IN_TWO_DIGITS"
|
||||
),
|
||||
)
|
||||
|
||||
data_model = data.RenderCVDataModel(
|
||||
cv=cv,
|
||||
design={"theme": theme_name},
|
||||
locale_catalog=locale_catalog,
|
||||
)
|
||||
|
||||
latex_file = renderer.create_a_latex_file(data_model, tmp_path)
|
||||
|
||||
latex_file_contents = latex_file.read_text()
|
||||
|
||||
assert "Full name of January" in latex_file_contents
|
||||
assert "Abbreviation of Jan" in latex_file_contents
|
||||
assert "this is present" in latex_file_contents
|
||||
assert "this is to" in latex_file_contents
|
||||
|
||||
Reference in New Issue
Block a user