Skip to content

Commit

Permalink
Adding Romania locale (#52)
Browse files Browse the repository at this point in the history
* Add Romania to the list of locales

* Fixing the `mix holidefs.download` task

It was actually a problem in the compilation process. As we were raising
an exception when there was no file for a given locale, which is the
case when we just added a new locale to the list and we're trying to use
`mix holidefs.download` to download that file.

* Downloading the Romania holiday definitions file

* Logging when a definition file is not present

* Translating Romania's holidays
  • Loading branch information
kelvinst authored Jun 7, 2024
1 parent 5172adb commit 3c50792
Show file tree
Hide file tree
Showing 8 changed files with 284 additions and 17 deletions.
1 change: 1 addition & 0 deletions config/test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ config :holidefs,
:ph,
:pl,
:pt,
:ro,
:rs,
:ru,
:se,
Expand Down
1 change: 1 addition & 0 deletions lib/holidefs.ex
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ defmodule Holidefs do
ph: "Philippines",
pl: "Poland",
pt: "Portugal",
ro: "Romania",
rs: "Serbia",
ru: "Russia",
se: "Sweden",
Expand Down
44 changes: 28 additions & 16 deletions lib/holidefs/definition.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ defmodule Holidefs.Definition do
alias Holidefs.Definition
alias Holidefs.Definition.Rule

require Logger

defstruct [:code, :name, rules: []]

@type t :: %Definition{
Expand All @@ -32,28 +34,38 @@ defmodule Holidefs.Definition do
@doc """
Loads the definition for a locale code and name.
If the file does not exists, it returns `nil`.
If any definition rule is invalid, a `RuntimeError` will be raised
"""
@spec load!(atom, String.t()) :: t
def load!(code, name) do
{:ok, file_data} =
code
|> file_path()
|> to_charlist()
|> YamlElixir.read_from_file()
case read_file(code) do
{:ok, file_data} ->
rules =
file_data
|> Map.get("months")
|> Enum.flat_map(fn {month, rules} ->
for rule <- rules, do: Rule.build(code, month, rule)
end)

rules =
file_data
|> Map.get("months")
|> Enum.flat_map(fn {month, rules} ->
for rule <- rules, do: Rule.build(code, month, rule)
end)
%Definition{
code: code,
name: name,
rules: rules
}

{:error, _} ->
Logger.warn("Definition file for #{code} not found.")
nil
end
end

%Definition{
code: code,
name: name,
rules: rules
}
defp read_file(code) do
code
|> file_path()
|> to_charlist()
|> YamlElixir.read_from_file()
end

@doc """
Expand Down
2 changes: 1 addition & 1 deletion lib/holidefs/definition/store.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ defmodule Holidefs.Definition.Store do

alias Holidefs.Definition

definitions = for {c, n} <- Holidefs.locales(), do: Definition.load!(c, n)
definitions = Holidefs.locales() |> Enum.map(fn {c, n} -> Definition.load!(c, n) end) |> Enum.reject(&is_nil/1)

@doc """
Returns all the loaded definitions with their rules.
Expand Down
174 changes: 174 additions & 0 deletions priv/calendars/definitions/ro.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
# Romanian holiday definitions for the Ruby Holiday gem.
#
# Created: 2013-07-23 by Mihai Târnovan
# Sources:
# - http://ro.wikipedia.org/wiki/S%C4%83rb%C4%83tori_publice_%C3%AEn_Rom%C3%A2nia
# - http://en.wikipedia.org/wiki/Public_holidays_in_Romania
---
months:
0:
- name: Paștele - duminică
regions: [ro]
function: orthodox_easter(year)
- name: Paștele - luni
regions: [ro]
function: orthodox_easter(year)
function_modifier: 1
- name: Rusaliile - 50
regions: [ro]
function: orthodox_easter(year)
function_modifier: 49
- name: Rusaliile - 51
regions: [ro]
function: orthodox_easter(year)
function_modifier: 50
1:
- name: Anul nou
regions: [ro]
mday: 1
- name: Anul nou
regions: [ro]
mday: 2
5:
- name: Ziua muncii
regions: [ro]
mday: 1
8:
- name: Adormirea Maicii Domnului
regions: [ro]
mday: 15
11:
- name: Sfântul Apostol Andrei
regions: [ro]
mday: 30
12:
- name: Ziua Națională
regions: [ro]
mday: 1
- name: Sărbătoarea Nașterii Domnului
regions: [ro]
mday: 25
- name: Sărbătoarea Nașterii Domnului
regions: [ro]
mday: 26

tests:
- given:
date: '1961-04-09'
regions: ["ro"]
options: ["informal"]
expect:
name: "Paștele - duminică"
- given:
date: '1961-04-10'
regions: ["ro"]
options: ["informal"]
expect:
name: "Paștele - luni"
- given:
date: '2013-05-05'
regions: ["ro"]
options: ["informal"]
expect:
name: "Paștele - duminică"
- given:
date: '2013-05-06'
regions: ["ro"]
options: ["informal"]
expect:
name: "Paștele - luni"
- given:
date: '2027-05-02'
regions: ["ro"]
options: ["informal"]
expect:
name: "Paștele - duminică"
- given:
date: '2027-05-03'
regions: ["ro"]
options: ["informal"]
expect:
name: "Paștele - luni"
- given:
date: '2012-06-04'
regions: ["ro"]
options: ["informal"]
expect:
name: "Rusaliile - 51"
- given:
date: '2013-06-23'
regions: ["ro"]
options: ["informal"]
expect:
name: "Rusaliile - 50"
- given:
date: '2013-06-24'
regions: ["ro"]
options: ["informal"]
expect:
name: "Rusaliile - 51"
- given:
date: '1986-06-22'
regions: ["ro"]
options: ["informal"]
expect:
name: "Rusaliile - 50"
- given:
date: '1986-06-23'
regions: ["ro"]
options: ["informal"]
expect:
name: "Rusaliile - 51"
- given:
date: '2009-01-01'
regions: ["ro"]
options: ["informal"]
expect:
name: "Anul nou"
- given:
date: '2014-01-02'
regions: ["ro"]
options: ["informal"]
expect:
name: "Anul nou"
- given:
date: '2009-05-01'
regions: ["ro"]
options: ["informal"]
expect:
name: "Ziua muncii"
- given:
date: '2012-08-15'
regions: ["ro"]
options: ["informal"]
expect:
name: "Adormirea Maicii Domnului"
- given:
date: '2013-11-30'
regions: ["ro"]
options: ["informal"]
expect:
name: "Sfântul Apostol Andrei"
- given:
date: '2013-12-01'
regions: ["ro"]
options: ["informal"]
expect:
name: "Ziua Națională"
- given:
date: '2013-12-25'
regions: ["ro"]
options: ["informal"]
expect:
name: "Sărbătoarea Nașterii Domnului"
- given:
date: '2013-12-26'
regions: ["ro"]
options: ["informal"]
expect:
name: "Sărbătoarea Nașterii Domnului"
- given:
date: '2013-07-23'
regions: ["ro"]
expect:
holiday: false
42 changes: 42 additions & 0 deletions priv/gettext/en/LC_MESSAGES/ro.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
## "msgid"s in this file come from POT (.pot) files.
###
### Do not add, change, or remove "msgid"s manually here as
### they're tied to the ones in the corresponding POT file
### (with the same domain).
###
### Use "mix gettext.extract --merge" or "mix gettext.merge"
### to merge POT files into PO files.
msgid ""
msgstr ""
"Language: en\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"

msgid "Paștele - duminică"
msgstr "Easter - Sunday"

msgid "Paștele - luni"
msgstr "Easter - Monday"

msgid "Rusaliile - 50"
msgstr "Pentecost - 50"

msgid "Rusaliile - 51"
msgstr "Pentecost - 51"

msgid "Anul nou"
msgstr "New Year"

msgid "Ziua muncii"
msgstr "Labor Day"

msgid "Adormirea Maicii Domnului"
msgstr "Assumption of the Virgin Mary"

msgid "Sfântul Apostol Andrei"
msgstr "Saint Andrew the Apostle"

msgid "Ziua Națională"
msgstr "National Day"

msgid "Sărbătoarea Nașterii Domnului"
msgstr "The Feast of the Nativity"
36 changes: 36 additions & 0 deletions priv/gettext/ro.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Generated by `mix holidefs.gettext.extract`
# for the locale RO - Romania
msgid ""
msgstr ""


msgid "Paștele - duminică"
msgstr ""

msgid "Paștele - luni"
msgstr ""

msgid "Rusaliile - 50"
msgstr ""

msgid "Rusaliile - 51"
msgstr ""

msgid "Anul nou"
msgstr ""

msgid "Ziua muncii"
msgstr ""

msgid "Adormirea Maicii Domnului"
msgstr ""

msgid "Sfântul Apostol Andrei"
msgstr ""

msgid "Ziua Națională"
msgstr ""

msgid "Sărbătoarea Nașterii Domnului"
msgstr ""

1 change: 1 addition & 0 deletions test/holidefs_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ defmodule HolidefsTest do
ph: "Philippines",
pl: "Poland",
pt: "Portugal",
ro: "Romania",
rs: "Serbia",
ru: "Russia",
se: "Sweden",
Expand Down

0 comments on commit 3c50792

Please sign in to comment.