Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge locale and country #97

Merged
merged 12 commits into from
Nov 21, 2023
Merged

Merge locale and country #97

merged 12 commits into from
Nov 21, 2023

Conversation

lauft
Copy link
Member

@lauft lauft commented Nov 21, 2023

This PR contains a major overhaul of the internal structure. The external interface via the bin/holidata script stays the same.

The biggest change is the transfer of the holiday definitions from the locales to the respective country. Before, there had to be a locale class for each locale, defining the holidays partially as class docstring, partially as dedicated functions. For Belgium (BE) the (abridged) locale in French (fr) looked like this:

class fr_BE(Locale):
    """
    01-01: [NF] Nouvel An
    05-01: [NF] Fête du Travail
    07-21: [NF] Fête nationale
...
    """
...

For Belgium, there were two more locale classes, for languages de and nl. As the holiday data is identical except for the respective language, this means duplication.
Instead of defining the holidays in each locale, they are now defined centrally for all (available) languages in the corresponding country. The definitions for the example Belgium now looks like this:

class BE(Country):
    id = "BE"
    languages = ["de", "fr", "nl"]
    easter_type = EASTER_WESTERN

    def __init__(self):
        super().__init__()

        self.define_holiday() \
            .with_names({
                "de": "Neujahr",
                "fr": "Nouvel An",
                "nl": "Nieuwjaar",
            }) \
            .on("01-01") \
            .with_flags("NF")

        self.define_holiday() \
            .with_names({
                "de": "Tag der Arbeit",
                "fr": "Fête du Travail",
                "nl": "Dag van de arbeid",
            }) \
            .on("05-01") \
            .with_flags("NF")
...

Instead of docstring and functions, holidays are now defined via a DSL, which allows to specify all required information.

Also, it is now also possible to specify holidays for regions in separate classes, intended to simplify the handling of regional holidays. This has been applied to the holidays of Spain (ES) which is now a subpackage (see src/holidata/holidays/ES/init.py).

Instead of re-naming a holiday, the old one ceases to exist and a new one takes its place.

Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
Has to be an array

Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
With this, all different translations of a holiday are combined in its definition.
This unifies all locales into their respective country.

Added 'LocaleWrapper' for transition phase.

Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
Before, order seemed too dependent on call order

Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
Holidays are now defined uniformly via a DSL.

Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
Language id can be given in upper or lower case in the main script.
Internally, the language id is handled in lower case.

Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
@lauft lauft mentioned this pull request Nov 21, 2023
@lauft lauft merged commit a8c92de into main Nov 21, 2023
10 checks passed
@lauft lauft deleted the feature/merge-locale-and-country branch November 21, 2023 22:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant