GothenburgBitFactory / holidata

Holidata is the core of holidata.net, a no-nonsense, ad-free provider of international holiday data.
https://holidata.net
MIT License
43 stars 11 forks source link

Merge locale and country #97

Closed lauft closed 7 months ago

lauft commented 7 months ago

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).