From 537d4db63c57e57cbc2a0b2e75537b9cff024d8e Mon Sep 17 00:00:00 2001 From: Vera Rojman Date: Mon, 13 Jun 2022 10:47:18 +0200 Subject: [PATCH 1/4] [SMILES] Add locale for Nederlands - Belgium --- app/assets/javascripts/application.js | 1 + .../foundation-datepicker.nl-BE.js | 15 +++++++++++++++ config/initializers/decidim.rb | 2 +- config/locales/nl-BE.yml | 3 +++ 4 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 app/assets/javascripts/datepicker-locales/foundation-datepicker.nl-BE.js create mode 100644 config/locales/nl-BE.yml diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index a857ecd..124548f 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -15,3 +15,4 @@ //= require_tree . //= require decidim //= require smiles.platoniq.net +//= require datepicker-locales/foundation-datepicker.nl-BE.js diff --git a/app/assets/javascripts/datepicker-locales/foundation-datepicker.nl-BE.js b/app/assets/javascripts/datepicker-locales/foundation-datepicker.nl-BE.js new file mode 100644 index 0000000..dc6ce70 --- /dev/null +++ b/app/assets/javascripts/datepicker-locales/foundation-datepicker.nl-BE.js @@ -0,0 +1,15 @@ +/** + * Dutch translation for foundation-datepicker + * Reinier Goltstein + */ +; +(function($) { + $.fn.fdatepicker.dates['nl-BE'] = { + days: ["Zondag", "Maandag", "Dinsdag", "Woensdag", "Donderdag", "Vrijdag", "Zaterdag", "Zondag"], + daysShort: ["Zo", "Ma", "Di", "Wo", "Do", "Vr", "Za", "Zo"], + daysMin: ["Zo", "Ma", "Di", "Wo", "Do", "Vr", "Za", "Zo"], + months: ["Januari", "Februari", "Maart", "April", "Mei", "Juni", "Juli", "Augustus", "September", "Oktober", "November", "December"], + monthsShort: ["Jan", "Feb", "Mrt", "Apr", "Mei", "Jun", "Jul", "Aug", "Sep", "Okt", "Nov", "Dec"], + today: "Vandaag" + }; +}(jQuery)); diff --git a/config/initializers/decidim.rb b/config/initializers/decidim.rb index 3fb17e2..7c7c02e 100644 --- a/config/initializers/decidim.rb +++ b/config/initializers/decidim.rb @@ -6,7 +6,7 @@ # Change these lines to set your preferred locales config.default_locale = :en - config.available_locales = [:en, :ca, :es, :nl, :lv, :el, :pt] + config.available_locales = [:en, :ca, :es, :nl, :lv, :el, :pt, 'nl-BE'] # Geocoder configuration config.maps = { diff --git a/config/locales/nl-BE.yml b/config/locales/nl-BE.yml new file mode 100644 index 0000000..375fcd0 --- /dev/null +++ b/config/locales/nl-BE.yml @@ -0,0 +1,3 @@ +nl-BE: + locale: + name: Nederlands (Belgium) \ No newline at end of file From ccc40395846c3d42629787624e8a8f2ad4c0824a Mon Sep 17 00:00:00 2001 From: Vera Rojman <8806781+verarojman@users.noreply.github.com> Date: Thu, 11 Aug 2022 12:30:50 +0200 Subject: [PATCH 2/4] Add locale to spec --- config/initializers/decidim.rb | 4 ++-- spec/spec_helper.rb | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/config/initializers/decidim.rb b/config/initializers/decidim.rb index 7c7c02e..c10bf16 100644 --- a/config/initializers/decidim.rb +++ b/config/initializers/decidim.rb @@ -6,7 +6,7 @@ # Change these lines to set your preferred locales config.default_locale = :en - config.available_locales = [:en, :ca, :es, :nl, :lv, :el, :pt, 'nl-BE'] + config.available_locales = [:en, :ca, :es, :nl, :lv, :el, :pt, "nl-BE"] # Geocoder configuration config.maps = { @@ -130,4 +130,4 @@ Rails.application.config.i18n.default_locale = Decidim.default_locale Decidim::Api::Schema.max_complexity = 5000 -Decidim::Api::Schema.max_depth = 50 \ No newline at end of file +Decidim::Api::Schema.max_depth = 50 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 90ad617..5695f70 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -96,10 +96,10 @@ config.order = :random config.before do - I18n.available_locales = [:en, :es, :ca, :nl] + I18n.available_locales = [:en, :es, :ca, :nl, "nl-BE"] I18n.default_locale = :en I18n.locale = :en - Decidim.available_locales = [:en, :es, :ca, :nl] + Decidim.available_locales = [:en, :es, :ca, :nl, "nl-BE"] Decidim.default_locale = :en Capybara.server = :puma end From 594721cec8e8e6e86382265b17e58e1230c7d22e Mon Sep 17 00:00:00 2001 From: Vera Rojman <8806781+verarojman@users.noreply.github.com> Date: Thu, 11 Aug 2022 14:04:57 +0200 Subject: [PATCH 3/4] Add bugfix for translatable fields with hyphenated locale --- app/forms/translatable_presence_validator.rb | 31 ++++++++++++++++++++ spec/lib/overrides_spec.rb | 3 +- 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 app/forms/translatable_presence_validator.rb diff --git a/app/forms/translatable_presence_validator.rb b/app/forms/translatable_presence_validator.rb new file mode 100644 index 0000000..2f982eb --- /dev/null +++ b/app/forms/translatable_presence_validator.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +# +# Bugfix backported from https://github.com/decidim/decidim/pull/8795/files +# +# A custom validator to check for presence in I18n-enabled fields. In order to +# use it do the following: +# +# validates :my_i18n_field, translatable_presence: true +# +# This will automatically check for presence for the default locale of the form +# object (or the `default_locale` of the form's organization) for the given field. +class TranslatablePresenceValidator < ActiveModel::EachValidator + def validate_each(record, attribute, _value) + translated_attr = "#{attribute}_#{default_locale_for(record)}".gsub("-", "__") + record.errors.add(translated_attr, :blank) if record.send(translated_attr).blank? + end + + private + + def default_locale_for(record) + return record.default_locale if record.respond_to?(:default_locale) + + if record.current_organization + record.current_organization.default_locale + else + record.errors.add(:current_organization, :blank) + Decidim.default_locale + end + end +end diff --git a/spec/lib/overrides_spec.rb b/spec/lib/overrides_spec.rb index 828289b..a3cea2a 100644 --- a/spec/lib/overrides_spec.rb +++ b/spec/lib/overrides_spec.rb @@ -10,7 +10,8 @@ package: "decidim-core", files: { # layouts - "/app/views/layouts/decidim/_mini_footer.html.erb" => "55a9ca723b65b8d9eadb714818a89bb3" + "/app/views/layouts/decidim/_mini_footer.html.erb" => "55a9ca723b65b8d9eadb714818a89bb3", + "/app/forms/translatable_presence_validator.rb" => "a0dfc39805f27769edb917e9d30a8d67" } }, { From 9903bb3283fc1aaeb6f7b1cff14997a23c06b692 Mon Sep 17 00:00:00 2001 From: Vera Rojman <8806781+verarojman@users.noreply.github.com> Date: Thu, 11 Aug 2022 14:08:17 +0200 Subject: [PATCH 4/4] Remove duplicate line in gemfile --- Gemfile | 2 -- 1 file changed, 2 deletions(-) diff --git a/Gemfile b/Gemfile index d591fc9..2554b3a 100644 --- a/Gemfile +++ b/Gemfile @@ -20,8 +20,6 @@ gem "decidim-time_tracker", git: "https://github.com/Platoniq/decidim-module-tim # gem "deface" gem "bootsnap", "~> 1.4" -# bug in version 1.9 -gem "i18n", "~> 1.8.1" gem "puma", ">= 4.3.5" gem "uglifier", "~> 4.1"