Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
corylown committed Mar 5, 2024
2 parents b7a78fb + 5f32540 commit d971e58
Show file tree
Hide file tree
Showing 20 changed files with 240 additions and 41 deletions.
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ source 'https://rubygems.org'
gemspec

gem 'edtf', '>= 2.3', '< 4'
gem 'rake', '~> 13.1'
gem 'rspec', '~> 3.13'
gem 'rubocop', '~> 1.61'
gem 'rubocop-rspec', '~> 2.27'

# Declare any dependencies that are still in development here instead of in
# your gemspec. These might include edge Rails or gems from your path or
Expand Down
4 changes: 2 additions & 2 deletions 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, French, and Italian are supported.
EDTF-humanize supports the use of I18n as well as language specific module overrides for more nuanced control. English, French, German, and Italian are supported.

Examples with current locale `:fr`:

Expand All @@ -128,7 +128,7 @@ Pull requests to add support for additional languages are welcome. You must add
edtf-humanize/lib/edtf/humanize.rb
edtf-humanize/config/locales/fr.edtf.yml
edtf-humanize/lib/edtf/humanize/language/french.rb
edtf-humanize/spec/edtf_humanize_fr_spec.rb
edtf-humanize/spec/edtf/humanize_fr_spec.rb
```

## Contributions
Expand Down
55 changes: 55 additions & 0 deletions config/locales/de.edtf.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
de:
date:
day_names: [Sonntag, Montag, Dienstag, Mittwoch, Donnerstag, Freitag, Samstag]
abbr_day_names: [So, Mo, Di, Mi, Do, Fr, Sa]
# Don't forget the nil at the beginning; there's no such thing as a 0th month
month_names: [~, Januar, Februar, März, April, Mai, Juni, Juli, August, September, Oktober, November, Dezember]
abbr_month_names: [~, Jan, Feb, Mar, Apr, Mai, Jun, Jul, Aug, Sept, Okt, Nov, Dez]
seasons:
spring: "Frühling"
summer: "Sommer"
autumn: "Herbst"
winter: "Winter"
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: ""
decade_suffix: "er Jahre"
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: "bis %{date}"
open_start_interval_with_month: "bis %{date}"
open_start_interval_with_year: "bis %{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: "vor "
set_earlier_prefix_inclusive: "vor "
set_last_date_connector_exclusive: " oder "
set_last_date_connector_inclusive: " und "
set_later_prefix_exclusive: "nach "
set_later_prefix_inclusive: "nach "
set_two_dates_connector_exclusive: " oder "
set_two_dates_connector_inclusive: " eund "
uncertain_date_suffix: " ?"
unknown: "Datum unbekannt"
unspecified_digit_substitute: "x"
formats:
day_precision_strftime_format: "%-d. %B %Y"
month_precision_strftime_format: "%B %Y"
year_precision_strftime_format: "%Y"
10 changes: 3 additions & 7 deletions edtf-humanize.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ Gem::Specification.new do |s|
s.name = 'edtf-humanize'
s.version = Edtf::Humanize::VERSION
s.authors = ['Cory Lown']
s.email = ['cory.lown@duke.edu']
s.homepage = 'https://github.com/duke-libraries/edtf-humanize'
s.email = ['corylown@stanford.edu']
s.homepage = 'https://github.com/corylown/edtf-humanize'
s.summary = 'This gem adds a humanize method to EDTF dates.'
s.description = 'This gem adds a humanize method to EDTF::Decade, ' \
'EDTF::Interval, EDTF::Set, EDTF::Season, EDTF::Unknown, ' \
Expand All @@ -20,14 +20,10 @@ Gem::Specification.new do |s|
s.required_ruby_version = '>= 2.4', '< 4'

s.files = Dir['{app,config,db,lib}/**/*', 'LICENSE.txt', 'README.rdoc']
s.test_files = Dir['spec/**/*']

s.add_dependency 'activesupport', '>= 4'
s.add_dependency 'edtf', '>= 2.3', '< 4'
s.add_dependency 'roman', '~> 0.2.0'

s.add_development_dependency 'rake', '~> 13.0'
s.add_development_dependency 'rspec', '~> 3.9'
s.add_development_dependency 'rubocop', '~> 0.87'
s.add_development_dependency 'rubocop-rspec', '~> 1.39'
s.metadata['rubygems_mfa_required'] = 'true'
end
4 changes: 3 additions & 1 deletion lib/edtf/humanize.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ module Humanize
require 'edtf/humanize/language/english'
require 'edtf/humanize/language/french'
require 'edtf/humanize/language/italian'
require 'edtf/humanize/language/german'

EDTF::Decade.include Edtf::Humanize::Decade
EDTF::Century.include Edtf::Humanize::Century
Expand Down Expand Up @@ -51,7 +52,8 @@ def initialize
default: Edtf::Humanize::Language::Default,
en: Edtf::Humanize::Language::English,
fr: Edtf::Humanize::Language::French,
it: Edtf::Humanize::Language::Italian
it: Edtf::Humanize::Language::Italian,
de: Edtf::Humanize::Language::German
}
end

Expand Down
2 changes: 1 addition & 1 deletion lib/edtf/humanize/language/default/century.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module Century

def humanizer(date)
"#{date.begin.year}" \
"#{I18n.t('edtf.terms.century_suffix', default: 's')}"
"#{I18n.t('edtf.terms.century_suffix', default: 's')}"
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/edtf/humanize/language/default/decade.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ module Decade

def humanizer(date)
"#{I18n.t('edtf.terms.decade_prefix', default: '')}" \
"#{date.begin.year}" \
"#{I18n.t('edtf.terms.decade_suffix', default: 's')}"
"#{date.begin.year}" \
"#{I18n.t('edtf.terms.decade_suffix', default: 's')}"
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/edtf/humanize/language/default/formats.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ def apply_if_uncertain(date)
# '198u' => 198x
def apply_if_unspecified_year(date)
display = date_precision(date)
if date.respond_to?(:unspecified?) && date.unspecified?(:year)
if date.respond_to?(:unspecified?) && (date.unspecified? :year)
year_substitute =
date.year_precision.edtf.gsub(
/u/,
'u',
I18n.t('edtf.terms.unspecified_digit_substitute',
default: 'x')
)
Expand Down
10 changes: 5 additions & 5 deletions lib/edtf/humanize/language/default/interval.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ def humanizer(date)
open_interval(date)
else
"#{interval_prefix(date)}" \
"#{formatted_date(date.from)}" \
"#{interval_connector(date)}" \
"#{formatted_date(date.to)}"
"#{formatted_date(date.from)}" \
"#{interval_connector(date)}" \
"#{formatted_date(date.to)}"
end
end

Expand Down Expand Up @@ -70,8 +70,8 @@ def open_end_interval(formatted_date:, precision:)

def formatted_date(date)
"#{apply_prefix_if_approximate(date)}" \
"#{date_format(date)}" \
"#{apply_suffix_if_approximate(date)}"
"#{date_format(date)}" \
"#{apply_suffix_if_approximate(date)}"
end

def interval_prefix(date)
Expand Down
4 changes: 2 additions & 2 deletions lib/edtf/humanize/language/default/iso_date.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ module IsoDate

def humanizer(date)
"#{apply_prefix_if_approximate(date)}" \
"#{date_format(date)}" \
"#{apply_suffix_if_approximate(date)}"
"#{date_format(date)}" \
"#{apply_suffix_if_approximate(date)}"
end
end
end
Expand Down
8 changes: 4 additions & 4 deletions lib/edtf/humanize/language/default/season.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ module Season
extend self

def humanizer(date)
"#{apply_prefix_if_approximate(date)}"\
"#{translate_season(date.season)} #{date.year}"\
"#{apply_suffix_if_approximate(date)}"\
"#{apply_if_uncertain(date)}"
"#{apply_prefix_if_approximate(date)}" \
"#{translate_season(date.season)} #{date.year}" \
"#{apply_suffix_if_approximate(date)}" \
"#{apply_if_uncertain(date)}"
end

private
Expand Down
16 changes: 8 additions & 8 deletions lib/edtf/humanize/language/default/set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@ def default_word_connector(date)

def format_set_entries(dates)
dates.entries.map.with_index do |date, index|
"#{apply_if_earlier(dates, index)}"\
"#{apply_if_later(dates, index)}"\
"#{apply_prefix_if_approximate(date)}"\
"#{date_format(date)}"\
"#{apply_suffix_if_approximate(date)}"\
"#{apply_if_earlier(dates, index)}" \
"#{apply_if_later(dates, index)}" \
"#{apply_prefix_if_approximate(date)}" \
"#{date_format(date)}" \
"#{apply_suffix_if_approximate(date)}" \
end
end

# '[..1760-12-03]' => on or before December 3, 1760
def apply_if_earlier(dates, index)
return earlier_prefix(dates) if dates.earlier? && index.zero?
earlier_prefix(dates) if dates.earlier? && index.zero?
end

def earlier_prefix(dates)
Expand All @@ -55,8 +55,8 @@ def earlier_prefix_default(dates)

# '[1760-12..]' => on or after December 1760
def apply_if_later(dates, index)
return later_prefix(dates) if dates.later? &&
(index + 1) == dates.size
later_prefix(dates) if dates.later? &&
(index + 1) == dates.size
end

def later_prefix(dates)
Expand Down
6 changes: 3 additions & 3 deletions lib/edtf/humanize/language/french.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ module Century

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

private
Expand Down
32 changes: 32 additions & 0 deletions lib/edtf/humanize/language/german.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# frozen_string_literal: true

module Edtf
module Humanize
module Language
module German
include Default

module Century
extend self

def humanizer(date)
"#{(date.year.abs / 100) + 1}." \
"#{century_number_suffix}"
end

private

def century_number_suffix
' Jahrhundert'
end

def century_sign_suffix(date)
return ' v. Chr.' if date.year.negative?

''
end
end
end
end
end
end
6 changes: 3 additions & 3 deletions lib/edtf/humanize/language/italian.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ module Century

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

private
Expand Down
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.1.0'
VERSION = '2.2.0'
end
end
Loading

0 comments on commit d971e58

Please sign in to comment.