From 320ea6aef5b0a69fa7c7a95181c39d7da11152a8 Mon Sep 17 00:00:00 2001 From: koilebeit Date: Mon, 4 Mar 2024 21:53:10 +0100 Subject: [PATCH 1/6] Add support for German --- config/locales/de.edtf.yml | 55 ++++++++++++++ lib/edtf/humanize.rb | 4 +- lib/edtf/humanize/language/german.rb | 32 ++++++++ spec/edtf_humanize_de_spec.rb | 110 +++++++++++++++++++++++++++ 4 files changed, 200 insertions(+), 1 deletion(-) create mode 100644 config/locales/de.edtf.yml create mode 100644 lib/edtf/humanize/language/german.rb create mode 100644 spec/edtf_humanize_de_spec.rb diff --git a/config/locales/de.edtf.yml b/config/locales/de.edtf.yml new file mode 100644 index 0000000..ee1db80 --- /dev/null +++ b/config/locales/de.edtf.yml @@ -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" diff --git a/lib/edtf/humanize.rb b/lib/edtf/humanize.rb index f584497..feb58e8 100644 --- a/lib/edtf/humanize.rb +++ b/lib/edtf/humanize.rb @@ -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 @@ -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 diff --git a/lib/edtf/humanize/language/german.rb b/lib/edtf/humanize/language/german.rb new file mode 100644 index 0000000..33e52c1 --- /dev/null +++ b/lib/edtf/humanize/language/german.rb @@ -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 diff --git a/spec/edtf_humanize_de_spec.rb b/spec/edtf_humanize_de_spec.rb new file mode 100644 index 0000000..14aecf3 --- /dev/null +++ b/spec/edtf_humanize_de_spec.rb @@ -0,0 +1,110 @@ +# frozen_string_literal: true + +require 'edtf-humanize' + +RSpec.describe Edtf::Humanize do + before do + I18n.locale = :de + 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('1990er Jahre') + end + end + + context 'with a century' do + it 'returns a humanized century string' do + expect(Date.edtf('19xx').humanize).to eq('20. Jahrhundert') + 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. Juli 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('Sommer 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 oder 1983') + ) + end + + it 'returns a humanized inclusive set string' do + expect(Date.edtf('{1980, 1981, 1983}').humanize).to( + eq('1980, 1981 und 1983') + ) + end + + it 'returns a humanized open (before) exclusive set string' do + expect(Date.edtf('[..1980]').humanize).to( + eq('vor 1980') + ) + end + + it 'returns a humanized open (after) exclusive set string' do + expect(Date.edtf('[1980..]').humanize).to( + eq('nach 1980') + ) + end + + it 'returns a humanized open (before) inclusive set string' do + expect(Date.edtf('{..1980}').humanize).to( + eq('vor 1980') + ) + end + + it 'returns a humanized open (after) inclusive set string' do + expect(Date.edtf('{1980..}').humanize).to( + eq('nach 1980') + ) + end + end + + context 'with an unknown value' do + it 'returns a humanized unknown string' do + expect(Date.edtf('uuuu').humanize).to eq('Datum unbekannt') + end + end +end From d49338c995ffcf4b77a2681a69b9a70c5f271597 Mon Sep 17 00:00:00 2001 From: Cory Lown Date: Mon, 4 Mar 2024 16:07:12 -0500 Subject: [PATCH 2/6] Update contact info in edtf-humanize.gemspec --- edtf-humanize.gemspec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/edtf-humanize.gemspec b/edtf-humanize.gemspec index 07b23ac..f885025 100644 --- a/edtf-humanize.gemspec +++ b/edtf-humanize.gemspec @@ -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, ' \ From ec431efc4154ffe0fe3b52ea3d62a902b1f9a7b2 Mon Sep 17 00:00:00 2001 From: Cory Lown Date: Mon, 4 Mar 2024 17:47:24 -0500 Subject: [PATCH 3/6] Bump version --- lib/edtf/humanize/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/edtf/humanize/version.rb b/lib/edtf/humanize/version.rb index 8f06173..f03a9a0 100644 --- a/lib/edtf/humanize/version.rb +++ b/lib/edtf/humanize/version.rb @@ -2,6 +2,6 @@ module Edtf module Humanize - VERSION = '2.1.0.pre' + VERSION = '2.2.0.pre' end end From 4a4fc238cfee2521dd6610b5f8d1db2f0e0c3d1a Mon Sep 17 00:00:00 2001 From: Cory Lown Date: Mon, 4 Mar 2024 17:53:46 -0500 Subject: [PATCH 4/6] Run rubocop autocorrect --- Gemfile | 5 ++++- edtf-humanize.gemspec | 6 +----- lib/edtf/humanize/language/default/century.rb | 2 +- lib/edtf/humanize/language/default/decade.rb | 4 ++-- lib/edtf/humanize/language/default/formats.rb | 18 ++++++++---------- lib/edtf/humanize/language/default/interval.rb | 10 +++++----- lib/edtf/humanize/language/default/iso_date.rb | 4 ++-- lib/edtf/humanize/language/default/season.rb | 8 ++++---- lib/edtf/humanize/language/default/set.rb | 16 ++++++++-------- lib/edtf/humanize/language/french.rb | 6 +++--- lib/edtf/humanize/language/german.rb | 4 ++-- lib/edtf/humanize/language/italian.rb | 6 +++--- .../humanize_de_spec.rb} | 0 .../humanize_en_spec.rb} | 0 .../humanize_fr_spec.rb} | 0 .../humanize_it_spec.rb} | 0 16 files changed, 43 insertions(+), 46 deletions(-) rename spec/{edtf_humanize_de_spec.rb => edtf/humanize_de_spec.rb} (100%) rename spec/{edtf_humanize_en_spec.rb => edtf/humanize_en_spec.rb} (100%) rename spec/{edtf_humanize_fr_spec.rb => edtf/humanize_fr_spec.rb} (100%) rename spec/{edtf_humanize_it_spec.rb => edtf/humanize_it_spec.rb} (100%) diff --git a/Gemfile b/Gemfile index b46a7cb..615c0f0 100644 --- a/Gemfile +++ b/Gemfile @@ -8,7 +8,10 @@ source 'https://rubygems.org' gemspec gem 'edtf', '>= 2.3', '< 4' - +gem 'rake', '~> 13.0' +gem 'rspec', '~> 3.9' +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 # Git. Remember to move these dependencies to your gemspec before releasing diff --git a/edtf-humanize.gemspec b/edtf-humanize.gemspec index f885025..569cd70 100644 --- a/edtf-humanize.gemspec +++ b/edtf-humanize.gemspec @@ -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 diff --git a/lib/edtf/humanize/language/default/century.rb b/lib/edtf/humanize/language/default/century.rb index 549ceba..22dccaa 100644 --- a/lib/edtf/humanize/language/default/century.rb +++ b/lib/edtf/humanize/language/default/century.rb @@ -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 diff --git a/lib/edtf/humanize/language/default/decade.rb b/lib/edtf/humanize/language/default/decade.rb index d6ddc78..6203fed 100644 --- a/lib/edtf/humanize/language/default/decade.rb +++ b/lib/edtf/humanize/language/default/decade.rb @@ -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 diff --git a/lib/edtf/humanize/language/default/formats.rb b/lib/edtf/humanize/language/default/formats.rb index fc3a506..31c1f60 100644 --- a/lib/edtf/humanize/language/default/formats.rb +++ b/lib/edtf/humanize/language/default/formats.rb @@ -94,16 +94,14 @@ def apply_if_uncertain(date) # '198u' => 198x def apply_if_unspecified_year(date) display = date_precision(date) - if date.respond_to? :unspecified? - if date.unspecified? :year - year_substitute = - date.year_precision.edtf.gsub( - /u/, - I18n.t('edtf.terms.unspecified_digit_substitute', - default: 'x') - ) - display.gsub!(date.year.to_s, year_substitute) - end + if date.respond_to?(:unspecified?) && (date.unspecified? :year) + year_substitute = + date.year_precision.edtf.gsub( + 'u', + I18n.t('edtf.terms.unspecified_digit_substitute', + default: 'x') + ) + display.gsub!(date.year.to_s, year_substitute) end display end diff --git a/lib/edtf/humanize/language/default/interval.rb b/lib/edtf/humanize/language/default/interval.rb index d7b3b04..d68c198 100644 --- a/lib/edtf/humanize/language/default/interval.rb +++ b/lib/edtf/humanize/language/default/interval.rb @@ -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 @@ -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) diff --git a/lib/edtf/humanize/language/default/iso_date.rb b/lib/edtf/humanize/language/default/iso_date.rb index c449e26..5ab47a6 100644 --- a/lib/edtf/humanize/language/default/iso_date.rb +++ b/lib/edtf/humanize/language/default/iso_date.rb @@ -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 diff --git a/lib/edtf/humanize/language/default/season.rb b/lib/edtf/humanize/language/default/season.rb index 0332d05..1ff0c55 100644 --- a/lib/edtf/humanize/language/default/season.rb +++ b/lib/edtf/humanize/language/default/season.rb @@ -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 diff --git a/lib/edtf/humanize/language/default/set.rb b/lib/edtf/humanize/language/default/set.rb index 2f485d3..27f776b 100644 --- a/lib/edtf/humanize/language/default/set.rb +++ b/lib/edtf/humanize/language/default/set.rb @@ -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) @@ -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) diff --git a/lib/edtf/humanize/language/french.rb b/lib/edtf/humanize/language/french.rb index 199b04c..23e77ce 100644 --- a/lib/edtf/humanize/language/french.rb +++ b/lib/edtf/humanize/language/french.rb @@ -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 diff --git a/lib/edtf/humanize/language/german.rb b/lib/edtf/humanize/language/german.rb index 33e52c1..979d690 100644 --- a/lib/edtf/humanize/language/german.rb +++ b/lib/edtf/humanize/language/german.rb @@ -10,8 +10,8 @@ module Century extend self def humanizer(date) - "#{(date.year.abs / 100 + 1)}." \ - "#{century_number_suffix}" + "#{(date.year.abs / 100) + 1}." \ + "#{century_number_suffix}" end private diff --git a/lib/edtf/humanize/language/italian.rb b/lib/edtf/humanize/language/italian.rb index 5346fc8..f2ba9ad 100644 --- a/lib/edtf/humanize/language/italian.rb +++ b/lib/edtf/humanize/language/italian.rb @@ -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 diff --git a/spec/edtf_humanize_de_spec.rb b/spec/edtf/humanize_de_spec.rb similarity index 100% rename from spec/edtf_humanize_de_spec.rb rename to spec/edtf/humanize_de_spec.rb diff --git a/spec/edtf_humanize_en_spec.rb b/spec/edtf/humanize_en_spec.rb similarity index 100% rename from spec/edtf_humanize_en_spec.rb rename to spec/edtf/humanize_en_spec.rb diff --git a/spec/edtf_humanize_fr_spec.rb b/spec/edtf/humanize_fr_spec.rb similarity index 100% rename from spec/edtf_humanize_fr_spec.rb rename to spec/edtf/humanize_fr_spec.rb diff --git a/spec/edtf_humanize_it_spec.rb b/spec/edtf/humanize_it_spec.rb similarity index 100% rename from spec/edtf_humanize_it_spec.rb rename to spec/edtf/humanize_it_spec.rb From 37b36b85af2a2b9308ef4c75664573e273d8ca1f Mon Sep 17 00:00:00 2001 From: Cory Lown Date: Tue, 5 Mar 2024 07:40:33 -0500 Subject: [PATCH 5/6] Bump development dependency versions --- Gemfile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index 615c0f0..9916d00 100644 --- a/Gemfile +++ b/Gemfile @@ -8,10 +8,11 @@ source 'https://rubygems.org' gemspec gem 'edtf', '>= 2.3', '< 4' -gem 'rake', '~> 13.0' -gem 'rspec', '~> 3.9' +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 # Git. Remember to move these dependencies to your gemspec before releasing From 5f3254026f55dc7f026c532c67b8331307381366 Mon Sep 17 00:00:00 2001 From: Cory Lown Date: Tue, 5 Mar 2024 07:50:28 -0500 Subject: [PATCH 6/6] Update readme --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 845965e..5a5bb95 100644 --- a/README.md +++ b/README.md @@ -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`: @@ -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