Skip to content

Commit

Permalink
Merge branch 'release-2.0.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
Cory Lown committed Aug 14, 2020
2 parents 94fb76f + 59c5eab commit ccc5797
Show file tree
Hide file tree
Showing 10 changed files with 209 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ require 'edtf-humanize'

## Internationalization

EDTF-humanize supports the use of I18n as well as language specific module overrides for more nuanced control. English and French are supported.
EDTF-humanize supports the use of I18n as well as language specific module overrides for more nuanced control. English, French and Italian are supported.

Examples with current locale `:fr`:

Expand Down
55 changes: 55 additions & 0 deletions config/locales/it.edtf.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
it:
date:
day_names: [domenica, lunedì, martedì, mercoledì, giovedì, venerdì, sabato]
abbr_day_names: [dom, lun, mar, mer, gio, ven, sab]
# Don't forget the nil at the beginning; there's no such thing as a 0th month
month_names: [~, gennaio, febbraio, marzo, aprile, maggio, giugno, luglio, agosto, settembre, ottobre, novembre, dicembre]
abbr_month_names: [~, gen, feb, mar, apr, mag, giu, lug, ago, set, ott, nov, dic]
seasons:
spring: "primavera"
summer: "estate"
autumn: "autunno"
winter: "inverno"
edtf:
terms:
approximate_date_prefix_day: "circa "
approximate_date_prefix_month: "circa "
approximate_date_prefix_year: "circa "
approximate_date_suffix_day: ""
approximate_date_suffix_month: ""
approximate_date_suffix_year: ""
decade_prefix: "anni "
decade_suffix: ""
century_suffix: ""
interval_prefix_day: ""
interval_prefix_month: ""
interval_prefix_year: ""
interval_connector_approximate: " - "
interval_connector_open: " - "
interval_connector_day: " - "
interval_connector_month: " - "
interval_connector_year: " - "
interval_unspecified_suffix: ""
open_start_interval_with_day: "fino a %{date}"
open_start_interval_with_month: "fino a %{date}"
open_start_interval_with_year: "fino a %{date}"
open_end_interval_with_day: "%{date} - "
open_end_interval_with_month: "%{date} - "
open_end_interval_with_year: "%{date} - "
set_dates_connector_exclusive: ", "
set_dates_connector_inclusive: ", "
set_earlier_prefix_exclusive: "prima di "
set_earlier_prefix_inclusive: "prima di "
set_last_date_connector_exclusive: " o "
set_last_date_connector_inclusive: " e "
set_later_prefix_exclusive: "dopo "
set_later_prefix_inclusive: "dopo "
set_two_dates_connector_exclusive: " o "
set_two_dates_connector_inclusive: " e "
uncertain_date_suffix: " ?"
unknown: "data sconosciuta"
unspecified_digit_substitute: "x"
formats:
day_precision_strftime_format: "%-d %B %Y"
month_precision_strftime_format: "%B %Y"
year_precision_strftime_format: "%Y"
2 changes: 1 addition & 1 deletion lib/edtf-humanize.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
require 'edtf/humanize'

I18n.load_path +=
Dir.glob(File.dirname(__FILE__) + '/../config/locales/*.{rb,yml}')
Dir.glob("#{File.dirname(__FILE__)}/../config/locales/*.{rb,yml}")
4 changes: 3 additions & 1 deletion lib/edtf/humanize.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ module Humanize
require 'edtf/humanize/language/default'
require 'edtf/humanize/language/english'
require 'edtf/humanize/language/french'
require 'edtf/humanize/language/italian'

EDTF::Decade.include Edtf::Humanize::Decade
EDTF::Century.include Edtf::Humanize::Century
Expand All @@ -49,7 +50,8 @@ def initialize
@language_strategies = {
default: Edtf::Humanize::Language::Default,
en: Edtf::Humanize::Language::English,
fr: Edtf::Humanize::Language::French
fr: Edtf::Humanize::Language::French,
it: Edtf::Humanize::Language::Italian
}
end

Expand Down
1 change: 0 additions & 1 deletion lib/edtf/humanize/language/default/formats.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ def apply_if_unspecified_year(date)
)
display.gsub!(date.year.to_s, year_substitute)
end
elsif date
end
display
end
Expand Down
34 changes: 34 additions & 0 deletions lib/edtf/humanize/language/italian.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# frozen_string_literal: true

module Edtf
module Humanize
module Language
module Italian
include Default

module Century
extend self

def humanizer(date)
require 'roman'
"#{(date.year.abs / 100 + 1).to_roman}" \
"#{century_number_suffix}" \
"#{century_sign_suffix(date)}"
end

private

def century_number_suffix
' secolo'
end

def century_sign_suffix(date)
return ' a. C.' if date.year.negative?

''
end
end
end
end
end
end
2 changes: 1 addition & 1 deletion lib/edtf/humanize/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

module Edtf
module Humanize
VERSION = '2.0.0'
VERSION = '2.0.1'
end
end
4 changes: 2 additions & 2 deletions spec/edtf_humanize_en_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
end
end

context 'with an appoximate interval'
context 'with an approximate interval'
it 'returns a humanized approximate interval string' do
expect(Date.edtf('1970~/1980~').humanize).to(
eq('circa 1970 to circa 1980')
Expand All @@ -52,7 +52,7 @@
end
end

context 'with an unspecfic year iso date' do
context 'with an unspecified year iso date' do
it 'returns a humanized unspecified year ISO date string' do
expect(Date.edtf('197u').humanize).to eq('197x')
end
Expand Down
4 changes: 2 additions & 2 deletions spec/edtf_humanize_fr_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
end
end

context 'with an appoximate interval'
context 'with an approximate interval'
it 'returns a humanized approximate interval string' do
expect(Date.edtf('1970~/1980~').humanize).to(
eq('De 1970 environ à 1980 environ')
Expand All @@ -52,7 +52,7 @@
end
end

context 'with an unspecfic year iso date' do
context 'with an unspecified year iso date' do
it 'returns a humanized unspecified year ISO date string' do
expect(Date.edtf('197u').humanize).to eq('197x')
end
Expand Down
110 changes: 110 additions & 0 deletions spec/edtf_humanize_it_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
# frozen_string_literal: true

require 'edtf-humanize'

RSpec.describe Edtf::Humanize do
before do
I18n.locale = :it
end

it { is_expected.to be_a(Module) }

context 'with a decade' do
it 'returns a humanized decade string' do
expect(Date.edtf('199x').humanize).to eq('anni 1990')
end
end

context 'with a century' do
it 'returns a humanized century string' do
expect(Date.edtf('19xx').humanize).to eq('XX secolo')
end
end

context 'with an interval' do
it 'returns a humanized interval string' do
expect(Date.edtf('1970/1980').humanize).to eq('1970 - 1980')
end
end

context 'with an open interval' do
it 'returns a humanized interval string' do
expect(Date.edtf('1970/open').humanize).to eq('1970 - ')
end
end

context 'with an approximate interval'
it 'returns a humanized approximate interval string' do
expect(Date.edtf('1970~/1980~').humanize).to(
eq('circa 1970 - circa 1980')
)
end

context 'with an iso date' do
it 'returns a humanized ISO date string' do
expect(Date.edtf('1975-07-01').humanize).to eq('1 luglio 1975')
end
end

context 'with an uncertain iso date' do
it 'returns a humanized uncertain ISO date string' do
expect(Date.edtf('1975?').humanize).to eq('1975 ?')
end
end

context 'with an unspecified year iso date' do
it 'returns a humanized unspecified year ISO date string' do
expect(Date.edtf('197u').humanize).to eq('197x')
end
end

context 'with a season' do
it 'returns a humanized season string' do
expect(Date.edtf('1975-22').humanize).to eq('estate 1975')
end
end

context 'with a set' do
it 'returns a humanized exclusive set string' do
expect(Date.edtf('[1980, 1981, 1983]').humanize).to(
eq('1980, 1981 o 1983')
)
end

it 'returns a humanized inclusive set string' do
expect(Date.edtf('{1980, 1981, 1983}').humanize).to(
eq('1980, 1981 e 1983')
)
end

it 'returns a humanized open (before) exclusive set string' do
expect(Date.edtf('[..1980]').humanize).to(
eq('prima di 1980')
)
end

it 'returns a humanized open (after) exclusive set string' do
expect(Date.edtf('[1980..]').humanize).to(
eq('dopo 1980')
)
end

it 'returns a humanized open (before) inclusive set string' do
expect(Date.edtf('{..1980}').humanize).to(
eq('prima di 1980')
)
end

it 'returns a humanized open (after) inclusive set string' do
expect(Date.edtf('{1980..}').humanize).to(
eq('dopo 1980')
)
end
end

context 'with an unknown value' do
it 'returns a humanized unknown string' do
expect(Date.edtf('uuuu').humanize).to eq('data sconosciuta')
end
end
end

0 comments on commit ccc5797

Please sign in to comment.