Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 0 additions & 22 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -301,14 +301,6 @@ GEM
rack-test (>= 0.6.3)
regexp_parser (>= 1.5, < 3.0)
xpath (~> 3.2)
carrierwave (2.2.6)
activemodel (>= 5.0.0)
activesupport (>= 5.0.0)
addressable (~> 2.6)
image_processing (~> 1.1)
marcel (~> 1.0.0)
mini_mime (>= 0.1.3)
ssrf_filter (~> 1.0)
cells (4.1.8)
declarative-builder (~> 0.2.0)
declarative-option (< 0.2.0)
Expand Down Expand Up @@ -409,23 +401,13 @@ GEM
activemodel (>= 3.2)
mime-types (>= 1.0)
flamegraph (0.9.5)
fog-aws (3.21.0)
fog-core (~> 2.1)
fog-json (~> 1.1)
fog-xml (~> 0.1)
fog-core (2.6.0)
builder
excon (~> 1.0)
formatador (>= 0.2, < 2.0)
mime-types
fog-json (1.2.0)
fog-core
multi_json (~> 1.10)
fog-local (0.8.0)
fog-core (>= 1.27, < 3.0)
fog-xml (0.1.4)
fog-core
nokogiri (>= 1.5.11, < 2.0.0)
formatador (1.1.0)
foundation_rails_helper (4.0.1)
actionpack (>= 4.1, < 7.1)
Expand Down Expand Up @@ -532,7 +514,6 @@ GEM
mini_mime (1.1.5)
minitest (5.25.1)
msgpack (1.7.5)
multi_json (1.15.0)
multi_xml (0.7.1)
bigdecimal (~> 3.1)
net-http (0.5.0)
Expand Down Expand Up @@ -813,7 +794,6 @@ GEM
spring-watcher-listen (2.1.0)
listen (>= 2.7, < 4.0)
spring (>= 4)
ssrf_filter (1.1.2)
stackprof (0.2.26)
stringio (3.1.2)
temple (0.10.3)
Expand Down Expand Up @@ -892,7 +872,6 @@ DEPENDENCIES
brakeman (~> 6.1)
bullet
byebug (~> 11.0)
carrierwave
dalli
decidim-accountability!
decidim-admin!
Expand All @@ -914,7 +893,6 @@ DEPENDENCIES
decidim-verifications!
dotenv-rails (~> 2.7)
flamegraph
fog-aws
letter_opener_web (~> 2.0)
listen (~> 3.1)
memory_profiler
Expand Down
3 changes: 3 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,8 @@ class Application < Rails::Application
#
# config.time_zone = "Central Time (US & Canada)"
# config.eager_load_paths << Rails.root.join("extras")
config.after_initialize do # run after the initialization of the framework itself, engines, and all the application's initializers in config/initializers
require "extends/forms/decidim/proposals/proposal_form_extends"
end
end
end
185 changes: 185 additions & 0 deletions config/i18n-tasks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
# i18n-tasks finds and manages missing and unused translations: https://github.com/glebm/i18n-tasks

# The "main" locale.
base_locale: en
## All available locales are inferred from the data by default. Alternatively, specify them explicitly:
# locales: [es, fr]
## Reporting locale, default: en. Available: en, ru.
# internal_locale: en

# Read and write translations.
data:
## Translations are read from the file system. Supported format: YAML, JSON.
## Provide a custom adapter:
# adapter: I18n::Tasks::Data::FileSystem

# Locale files or `Dir.glob` patterns where translations are read from:
read:
## Default:
# - config/locales/%{locale}.yml
## More files:
# - config/locales/**/*.%{locale}.yml

# Locale files to write new keys to, based on a list of key pattern => file rules. Matched from top to bottom:
# `i18n-tasks normalize -p` will force move the keys according to these rules
write:
## For example, write devise and simple form keys to their respective files:
# - ['{devise, simple_form}.*', 'config/locales/\1.%{locale}.yml']
## Catch-all default:
# - config/locales/%{locale}.yml

# External locale data (e.g. gems).
# This data is not considered unused and is never written to.
external:
## Example (replace %#= with %=):
# - "<%#= %x[bundle info vagrant --path].chomp %>/templates/locales/%{locale}.yml"

## Specify the router (see Readme for details). Valid values: conservative_router, pattern_router, or a custom class.
# router: conservative_router

yaml:
write:
# do not wrap lines at 80 characters
line_width: -1

## Pretty-print JSON:
# json:
# write:
# indent: ' '
# space: ' '
# object_nl: "\n"
# array_nl: "\n"

# Find translate calls
search:
## Paths or `Find.find` patterns to search in:
# paths:
# - app/

## Root directories for relative keys resolution.
# relative_roots:
# - app/controllers
# - app/helpers
# - app/mailers
# - app/presenters
# - app/views

## Directories where method names which should not be part of a relative key resolution.
# By default, if a relative translation is used inside a method, the name of the method will be considered part of the resolved key.
# Directories listed here will not consider the name of the method part of the resolved key
#
# relative_exclude_method_name_paths:
# -

## Files or `File.fnmatch` patterns to exclude from search. Some files are always excluded regardless of this setting:
## *.jpg *.jpeg *.png *.gif *.svg *.ico *.eot *.otf *.ttf *.woff *.woff2 *.pdf *.css *.sass *.scss *.less
## *.yml *.json *.zip *.tar.gz *.swf *.flv *.mp3 *.wav *.flac *.webm *.mp4 *.ogg *.opus *.webp *.map *.xlsx
exclude:
- app/assets/images
- app/assets/fonts
- app/assets/videos
- app/assets/builds

## Alternatively, the only files or `File.fnmatch patterns` to search in `paths`:
## If specified, this settings takes priority over `exclude`, but `exclude` still applies.
# only: ["*.rb", "*.html.slim"]

## If `strict` is `false`, guess usages such as t("categories.#{category}.title"). The default is `true`.
# strict: true

## Allows adding ast_matchers for finding translations using the AST-scanners
## The available matchers are:
## - RailsModelMatcher
## Matches ActiveRecord translations like
## User.human_attribute_name(:email) and User.model_name.human
## - DefaultI18nSubjectMatcher
## Matches ActionMailer's default_i18n_subject method
##
## To implement your own, please see `I18n::Tasks::Scanners::AstMatchers::BaseMatcher`.
# ast_matchers:
# - 'I18n::Tasks::Scanners::AstMatchers::RailsModelMatcher'
# - 'I18n::Tasks::Scanners::AstMatchers::DefaultI18nSubjectMatcher'

## Multiple scanners can be used. Their results are merged.
## The options specified above are passed down to each scanner. Per-scanner options can be specified as well.
## See this example of a custom scanner: https://github.com/glebm/i18n-tasks/wiki/A-custom-scanner-example

## Translation Services
# translation:
# # Google Translate
# # Get an API key and set billing info at https://code.google.com/apis/console to use Google Translate
# google_translate_api_key: "AbC-dEf5"
# # DeepL Pro Translate
# # Get an API key and subscription at https://www.deepl.com/pro to use DeepL Pro
# deepl_api_key: "48E92789-57A3-466A-9959-1A1A1A1A1A1A"
# # deepl_host: "https://api.deepl.com"
# # deepl_version: "v2"
# # deepl_glossary_ids:
# # - f28106eb-0e06-489e-82c6-8215d6f95089
# # - 2c6415be-1852-4f54-9e1b-d800463496b4
# # add additional options to the DeepL.translate call: https://www.deepl.com/docs-api/translate-text/translate-text/
# deepl_options:
# formality: prefer_less
# # OpenAI
# openai_api_key: "sk-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
# # openai_model: "gpt-3.5-turbo" # see https://platform.openai.com/docs/models
# # may contain `%{from}` and `%{to}`, which will be replaced by source and target locale codes, respectively (using `Kernel.format`)
# # openai_system_prompt: >-
# # You are a professional translator that translates content from the %{from} locale
# # to the %{to} locale in an i18n locale array.
# #
# # The array has a structured format and contains multiple strings. Your task is to translate
# # each of these strings and create a new array with the translated strings.
# #
# # HTML markups (enclosed in < and > characters) must not be changed under any circumstance.
# # Variables (starting with %%{ and ending with }) must not be changed under any circumstance.
# #
# # Keep in mind the context of all the strings for a more accurate translation.

## Do not consider these keys missing:
ignore_missing:
- time.buttons.select
- decidim.admin.models.assembly.fields.promoted
# - 'errors.messages.{accepted,blank,invalid,too_short,too_long}'
# - '{devise,simple_form}.*'

## Consider these keys used:
ignore_unused:
- decidim.admin.models.assembly.fields.promoted
- time.buttons.select
- decidim.components.proposals.settings.global.require_category
- decidim.components.proposals.settings.global.require_scope

# - 'activerecord.attributes.*'
# - '{devise,kaminari,will_paginate}.*'
# - 'simple_form.{yes,no}'
# - 'simple_form.{placeholders,hints,labels}.*'
# - 'simple_form.{error_notification,required}.:'

## Exclude these keys from the `i18n-tasks eq-base' report:
# ignore_eq_base:
# all:
# - common.ok
# fr,es:
# - common.brand

## Exclude these keys from the `i18n-tasks check-consistent-interpolations` report:
# ignore_inconsistent_interpolations:
# - 'activerecord.attributes.*'

## Ignore these keys completely:
# ignore:
# - kaminari.*

## Sometimes, it isn't possible for i18n-tasks to match the key correctly,
## e.g. in case of a relative key defined in a helper method.
## In these cases you can use the built-in PatternMapper to map patterns to keys, e.g.:
#
# <%# I18n::Tasks.add_scanner 'I18n::Tasks::Scanners::PatternMapper',
# only: %w(*.html.haml *.html.slim),
# patterns: [['= title\b', '.page_title']] %>
#
# The PatternMapper can also match key literals via a special %{key} interpolation, e.g.:
#
# <%# I18n::Tasks.add_scanner 'I18n::Tasks::Scanners::PatternMapper',
# patterns: [['\bSpree\.t[( ]\s*%{key}', 'spree.%{key}']] %>
7 changes: 7 additions & 0 deletions config/initializers/decidim.rb
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,13 @@
Decidim::Proposals.configure do |config|
config.participatory_space_highlighted_proposals_limit = Rails.application.secrets.dig(:decidim, :proposals, :participatory_space_highlighted_proposals_limit).presence || 4
config.process_group_highlighted_proposals_limit = Rails.application.secrets.dig(:decidim, :proposals, :process_group_highlighted_proposals_limit).presence || 3
config.require_category = true # Default
config.require_scope = true # Default
end

Decidim.find_component_manifest(:proposals).settings(:global) do |settings|
settings.attribute :require_category, type: :boolean, default: Decidim::Proposals.config.require_category
settings.attribute :require_scope, type: :boolean, default: Decidim::Proposals.config.require_scope
end
end

Expand Down
9 changes: 8 additions & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
---
en:
decidim:
admin:
models:
assembly:
fields:
promoted: "Promoted"
promoted: Promoted
components:
proposals:
settings:
global:
require_category: Category is required
require_scope: Scope is required
10 changes: 9 additions & 1 deletion config/locales/fr.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
---
fr:
decidim:
components:
proposals:
settings:
global:
require_category: La catégorie est obligatoire
require_scope: Le secteur est obligatoire
time:
buttons:
select: Sélectionner
select: Sélectionner
45 changes: 45 additions & 0 deletions lib/extends/forms/decidim/proposals/proposal_form_extends.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# frozen_string_literal: true

require "active_support/concern"

module ProposalFormExtends
extend ActiveSupport::Concern

included do
attribute :require_category, :boolean, default: Decidim::Proposals.config.require_category
attribute :require_scope, :boolean, default: Decidim::Proposals.config.require_scope

validates :category_id, presence: true, if: ->(form) { form.require_category? }
validates :scope_id, presence: true, if: ->(form) { form.require_scope? }
validate :check_category, if: ->(form) { form.require_category? }
validate :check_scope, if: ->(form) { form.require_scope? }

def categories_enabled?
categories&.any?
end

def scopes_enabled?
current_component.scopes_enabled? && current_component.has_subscopes?
end

def require_category?
current_component.settings.require_category && categories_enabled?
end

def require_scope?
current_component.settings.require_scope && scopes_enabled?
end

private

def check_category
errors.add(:category, :blank) if category_id.blank? && require_category?
end

def check_scope
errors.add(:scope, :blank) if scope_id.blank? && require_scope?
end
end
end

Decidim::Proposals::ProposalForm.include(ProposalFormExtends)
1 change: 1 addition & 0 deletions spec/factories.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true

require "decidim/core/test/factories"
require "decidim/proposals/test/factories"
Loading
Loading