Coverage for rendercv/data/models/locale_catalog.py: 100%
26 statements
« prev ^ index » next coverage.py v7.6.1, created at 2024-12-25 23:06 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2024-12-25 23:06 +0000
1"""
2The `rendercv.models.locale_catalog` module contains the data model of the
3`locale_catalog` field of the input file.
4"""
6from typing import Annotated, Literal, Optional
8import annotated_types as at
9import pydantic
11from .base import RenderCVBaseModelWithoutExtraKeys
14class LocaleCatalog(RenderCVBaseModelWithoutExtraKeys):
15 """This class is the data model of the locale catalog. The values of each field
16 updates the `locale_catalog` dictionary.
17 """
19 model_config = pydantic.ConfigDict(validate_default=True)
21 phone_number_format: Optional[Literal["national", "international", "E164"]] = (
22 pydantic.Field(
23 default="national",
24 title="Phone Number Format",
25 description=(
26 "If 'national', phone numbers are formatted without the country code."
27 " If 'international', phone numbers are formatted with the country"
28 " code. The default value is 'national'."
29 ),
30 )
31 )
32 page_numbering_style: str = pydantic.Field(
33 default="NAME - Page PAGE_NUMBER of TOTAL_PAGES",
34 title="Page Numbering Style",
35 description=(
36 "The style of the page numbering. The following placeholders can be"
37 " used:\n- NAME: The name of the person\n- PAGE_NUMBER: The current page"
38 " number\n- TOTAL_PAGES: The total number of pages\n- TODAY: Today's date"
39 ' with `locale_catalog.date_style`\nThe default value is "NAME -'
40 ' Page PAGE_NUMBER of TOTAL_PAGES".'
41 ),
42 )
43 last_updated_date_style: str = pydantic.Field(
44 default="Last updated in TODAY",
45 title="Last Updated Date Style",
46 description=(
47 "The style of the last updated date. The following placeholders can be"
48 " used:\n- TODAY: Today's date with `locale_catalog.date_style`\nThe"
49 ' default value is "Last updated in TODAY".'
50 ),
51 )
52 date_style: Optional[str] = pydantic.Field(
53 default="MONTH_ABBREVIATION YEAR",
54 title="Date Style",
55 description=(
56 "The style of the date. The following placeholders can be"
57 " used:\n-FULL_MONTH_NAME: Full name of the month\n- MONTH_ABBREVIATION:"
58 " Abbreviation of the month\n- MONTH: Month as a number\n-"
59 " MONTH_IN_TWO_DIGITS: Month as a number in two digits\n- YEAR: Year as a"
60 " number\n- YEAR_IN_TWO_DIGITS: Year as a number in two digits\nThe"
61 ' default value is "MONTH_ABBREVIATION YEAR".'
62 ),
63 )
64 month: Optional[str] = pydantic.Field(
65 default="month",
66 title='Translation of "Month"',
67 description='Translation of the word "month" in the locale.',
68 )
69 months: Optional[str] = pydantic.Field(
70 default="months",
71 title='Translation of "Months"',
72 description='Translation of the word "months" in the locale.',
73 )
74 year: Optional[str] = pydantic.Field(
75 default="year",
76 title='Translation of "Year"',
77 description='Translation of the word "year" in the locale.',
78 )
79 years: Optional[str] = pydantic.Field(
80 default="years",
81 title='Translation of "Years"',
82 description='Translation of the word "years" in the locale.',
83 )
84 present: Optional[str] = pydantic.Field(
85 default="present",
86 title='Translation of "Present"',
87 description='Translation of the word "present" in the locale.',
88 )
89 to: Optional[str] = pydantic.Field(
90 default="–", # NOQA: RUF001
91 title='Translation of "To"',
92 description=(
93 "The word or character used to indicate a range in the locale (e.g.,"
94 ' "2020 - 2021").'
95 ),
96 )
97 abbreviations_for_months: Optional[
98 Annotated[list[str], at.Len(min_length=12, max_length=12)]
99 ] = pydantic.Field(
100 # Month abbreviations are taken from
101 # https://web.library.yale.edu/cataloging/months:
102 default=[
103 "Jan",
104 "Feb",
105 "Mar",
106 "Apr",
107 "May",
108 "June",
109 "July",
110 "Aug",
111 "Sept",
112 "Oct",
113 "Nov",
114 "Dec",
115 ],
116 title="Abbreviations of Months",
117 description="Abbreviations of the months in the locale.",
118 )
119 full_names_of_months: Optional[
120 Annotated[list[str], at.Len(min_length=12, max_length=12)]
121 ] = pydantic.Field(
122 default=[
123 "January",
124 "February",
125 "March",
126 "April",
127 "May",
128 "June",
129 "July",
130 "August",
131 "September",
132 "October",
133 "November",
134 "December",
135 ],
136 title="Full Names of Months",
137 description="Full names of the months in the locale.",
138 )
140 @pydantic.field_validator(
141 "month",
142 "months",
143 "year",
144 "years",
145 "present",
146 "abbreviations_for_months",
147 "to",
148 "full_names_of_months",
149 "phone_number_format",
150 "date_style",
151 )
152 @classmethod
153 def update_locale_catalog(cls, value: str, info: pydantic.ValidationInfo) -> str:
154 """Update the `locale_catalog` dictionary."""
155 if value:
156 LOCALE_CATALOG[info.field_name] = value # type: ignore
158 return value
161# The dictionary below will be overwritten by LocaleCatalog class, which will contain
162# month names, month abbreviations, and other locale-specific strings.
163LOCALE_CATALOG: dict[str, str | list[str]] = {}
165# Initialize even if the RenderCVDataModel is not called (to make `format_date` function
166# work on its own):
167LocaleCatalog()