decidim-voca 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 37eafb4af1d2c2d27c438544d49918d07eb144410824fadd75845ff0dae9fca6
4
- data.tar.gz: 467421a8e93e2eb35bfa80cc819e63fa01761544831197eb9f59222bea8797ed
3
+ metadata.gz: 71968465d5ce7e12cd8c869283e0c1d96f07ec40c2dd7b3253bbb03250da1985
4
+ data.tar.gz: efaebadd99dbc8aee6c4d6b26d99d2c696522afefaefbbb095433cee930ca340
5
5
  SHA512:
6
- metadata.gz: e7e5d5648ed52699aa1c5d9be2ab2194110a68fd9165a9834aefb1d8db3b0a83a7da5f571dad7f958b4be80668bed2d5d4d760b218a5cebf92fbb986613b296d
7
- data.tar.gz: 0fd05933447d6c133ca05a425970c553b44c6986d26b950ba24e121ed0a17d8f2a3abe0a92f978127f06ececfe86c274005a21c3c4a9849c4a95139835f2699f
6
+ metadata.gz: 8d2b19bbfbe4fe38bdc018c0713bcec0cec85049121d61aa919905669a7b3181f89007a5e840761706ece9659c4ca91d438783aefeb82ac6b1f322575b7072b8
7
+ data.tar.gz: 175d5907ca4cd67194a4dba7745d72037ce5b7e3b5e9a923163c36f8c98e6b978709fdbd494e8e719d035c4d4f7fe0abb3719583caae6e96da2729121f72252d
@@ -1,10 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Add a flag on main.main to indicate the current organization is using admin
4
- # with machine translation enabled.
5
- # This will be used to hide the language chooser and the language tabs in text fields.
6
- #
7
- # :original = SHA1(match) without whitespace (Deface); Decidim 0.29.7 admin templates.
3
+ # Flag admin chrome when machine translation is on (hide locale tabs via CSS).
4
+ # :original = SHA1(match) without whitespace (Deface); Decidim 0.32.3 admin templates.
8
5
 
9
6
  module AdminAddMachineTranslationFlag
10
7
  Deface::Override.new(
@@ -15,7 +12,7 @@ module AdminAddMachineTranslationFlag
15
12
  "data-machine-translated" => "<%= current_organization.enable_machine_translations? %>",
16
13
  "data-minimalistic-deepl" => "<%= current_organization.minimalistic_deepl? %>"
17
14
  },
18
- original: "9e9359026457bb1a289c94b183011e814d64893d"
15
+ original: "b691cc5c0af33ea6e44463a9babbb4879befe3e5"
19
16
  )
20
17
 
21
18
  Deface::Override.new(
@@ -26,15 +23,14 @@ module AdminAddMachineTranslationFlag
26
23
  "data-machine-translated" => "<%= current_organization.enable_machine_translations? %>",
27
24
  "data-minimalistic-deepl" => "<%= current_organization.minimalistic_deepl? %>"
28
25
  },
29
- original: "978289390dedd19463db6ac36784ca94ae4a7d30"
26
+ original: "52bec115fe4908d0778f2d1092b3eada49eb8d3d"
30
27
  )
31
28
 
32
- # Force admin to manage only default locale, and let machine translation do the rest.
33
29
  Deface::Override.new(
34
30
  virtual_path: "layouts/decidim/admin/_js_configuration",
35
31
  name: "admin_voca_force_only_default_locale",
36
32
  insert_after: "script",
37
33
  partial: "decidim/voca/deepl/overrides/admin_machine_translation_alert",
38
- original: "387d0b7c5fc52d2ee5e5c6d4b276791d69b4432e"
34
+ original: "a155309c8e8c62b10deaacd56093d1eea96e846f"
39
35
  )
40
36
  end
@@ -8,15 +8,15 @@ module InsertWeglotScripts
8
8
  partial: "decidim/voca/weglot/js_configuration"
9
9
  )
10
10
 
11
- # Add a locale switcher for weglot
11
+ # 0.32: one partial for desktop + mobile (footer/_main_language_chooser removed).
12
12
  Deface::Override.new(
13
- virtual_path: "layouts/decidim/footer/_main_language_chooser",
13
+ virtual_path: "layouts/decidim/header/_main_language_chooser",
14
14
  name: "insert_weglot_locale_switcher",
15
15
  surround: "erb[silent]:contains('available_locales.length > 1')",
16
16
  closing_selector: "erb[silent]:contains('end')",
17
17
  text: <<~ERB
18
18
  <% if current_organization.weglot? %>
19
- <%= render partial: "decidim/voca/weglot/locale_switcher", locals: { switcher_id: "desktop" } %>
19
+ <%= render partial: "decidim/voca/weglot/locale_switcher", locals: { switcher_id: id.to_s.include?("mobile") ? "mobile" : "desktop" } %>
20
20
  <% end %>
21
21
  <div class="voca-js--original-language-chooser" data-weglot-active="<%= current_organization.weglot? %>">
22
22
  <%= render_original %>
@@ -24,35 +24,11 @@ module InsertWeglotScripts
24
24
  ERB
25
25
  )
26
26
 
27
- # layouts/decidim/header/_mobile_language_chooser
28
- Deface::Override.new(
29
- virtual_path: "layouts/decidim/header/_mobile_language_choose",
30
- name: "insert_weglot_mobile_language_chooser",
31
- surround: "erb[silent]:contains('available_locales.length > 1')",
32
- closing_selector: "erb[silent]:contains('end')",
33
- text: <<~ERB
34
- <% if current_organization.weglot? %>
35
- <%= render partial: "decidim/voca/weglot/locale_switcher_mobile", locals: { switcher_id: "mobile" } %>
36
- <% end %>
37
- <div class="voca-js--original-language-chooser" data-weglot-active="<%= current_organization.weglot? %>">
38
- <%= render_original %>
39
- </div>
40
- ERB
41
- )
42
-
43
- Deface::Override.new(
44
- virtual_path: "layouts/decidim/header/_main_links_desktop",
45
- name: "insert_weglot_main_links_desktop_classes",
46
- set_attributes: "div:has(erb[loud]:contains('decidim.pages_path'))",
47
- attributes: {
48
- class: "main-bar__links-desktop__item-wrapper"
49
- }
50
- )
51
-
27
+ # Help / pages links left main_links_desktop in 0.32; inject next to login / menu.
52
28
  Deface::Override.new(
53
29
  virtual_path: "layouts/decidim/header/_main_links_desktop",
54
30
  name: "insert_weglot_main_links_desktop",
55
- insert_bottom: "div:has(erb[loud]:contains('decidim.pages_path'))",
31
+ insert_top: "div.flex.items-center",
56
32
  text: <<~ERB
57
33
  <%= render partial: "decidim/voca/weglot/topbar_locale_switcher" %>
58
34
  ERB
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Voca
5
+ # Prefix for the Memcached key. decidim-apartment appends Apartment::Tenant.current
6
+ # after this. That tenant is the distribution key for the request, not ENV DISTRIBUTION_KEY.
7
+ module CacheNamespace
8
+ module_function
9
+
10
+ def value
11
+ raw = if defined?(::CredentialsOverlay)
12
+ ::CredentialsOverlay.fetch(:cache, :namespace)
13
+ else
14
+ ENV.fetch("CACHE__NAMESPACE", nil)
15
+ end
16
+ sanitized = raw.to_s.gsub(/[^a-zA-Z0-9_-]/, "_")
17
+ sanitized.empty? ? nil : sanitized
18
+ end
19
+ end
20
+ end
21
+ end
@@ -63,10 +63,8 @@ module Decidim
63
63
  # Wire model hooks and overrides that must be loaded after the app is initialized.
64
64
  # @param config [Rails::Application] host app (+Rails.application+; first block arg of +initializer+)
65
65
  def initialize!
66
- if Decidim::Voca::Installation.deepl_enabled?
67
- configure_deepl!
68
- configure_machine_translation!
69
- end
66
+ configure_deepl!
67
+ configure_machine_translation!
70
68
  Rails.application.config.middleware.use ::Decidim::Voca::DeepL::Middleware
71
69
 
72
70
  ActiveSupport.on_load(:active_job) { include Decidim::Voca::DeepL::ActiveJobContext }
@@ -161,9 +159,9 @@ module Decidim
161
159
  def configure_deepl!
162
160
  require "deepl"
163
161
  ::DeepL.configure do |deepl|
164
- deepl.auth_key = Decidim::Voca::DeepL::Settings.api_key
165
- deepl.host = Decidim::Voca::DeepL::Settings.host
166
- deepl.version = Decidim::Voca::DeepL::Settings.version
162
+ deepl.auth_key = ENV.fetch("DECIDIM_DEEPL_API_KEY", "")
163
+ deepl.host = ENV.fetch("DECIDIM_DEEPL_HOST", "https://api.deepl.com")
164
+ deepl.version = ENV.fetch("DECIDIM_DEEPL_VERSION", "v2")
167
165
  end
168
166
  end
169
167
 
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "deepl/settings"
4
3
  require_relative "deepl/deepl_active_job_context"
5
4
  require_relative "deepl/deepl_context"
6
5
  require_relative "deepl/deepl_form_builder_overrides"
@@ -111,7 +111,7 @@ module Decidim
111
111
  # Overrides
112
112
  config.to_prepare do
113
113
  # Set retry on Decidim::ApplicationJob
114
- good_job_retry = ENV.fetch("VOCA_GOOD_JOB_RETRY", "5").to_i
114
+ good_job_retry = Decidim::Voca::GoodJobSettings.retry
115
115
  ::Decidim::ApplicationJob.retry_on StandardError, attempts: good_job_retry
116
116
 
117
117
  # Overrides ResourcePresenter
@@ -170,9 +170,7 @@ module Decidim
170
170
  cache_store = Rails.application.config.cache_store
171
171
  next unless cache_store.present? && cache_store != :null_store
172
172
 
173
- cache_namespace = ENV.fetch("MASTER_ID", nil).presence
174
- # Sanitize namespace: remove special characters, keep alphanumeric, dash, underscore
175
- cache_namespace = cache_namespace.to_s.gsub(/[^a-zA-Z0-9_-]/, "_")
173
+ cache_namespace = Decidim::Voca::CacheNamespace.value
176
174
  next if cache_namespace.blank?
177
175
 
178
176
  cache_store_config = Array(cache_store)
@@ -207,12 +205,12 @@ module Decidim
207
205
  # Execution mode is configurable, to adapt on demand:
208
206
  # - async_server: when your installation is small and want to run all in same server (but a new thread)
209
207
  # - external: when you run your own process with ``
210
- execution_mode = ENV.fetch("VOCA_ACTIVE_JOB_EXECUTION_MODE", "async_server").to_sym
211
- good_job_max_threads = ENV.fetch("VOCA_GOOD_JOB_MAX_THREADS", "5").to_i
212
- good_job_poll_interval = ENV.fetch("VOCA_GOOD_JOB_POLL_INTERVAL", 30).to_i
213
- good_job_shutdown_timeout = ENV.fetch("VOCA_GOOD_JOB_SHUTDOWN_TIMEOUT", 120).to_i
214
- good_job_retry = ENV.fetch("VOCA_GOOD_JOB_RETRY", "5").to_i
215
- good_job_queues = ENV.fetch("VOCA_GOOD_JOB_QUEUES", "*")
208
+ execution_mode = Decidim::Voca::GoodJobSettings.execution_mode
209
+ good_job_max_threads = Decidim::Voca::GoodJobSettings.max_threads
210
+ good_job_poll_interval = Decidim::Voca::GoodJobSettings.poll_interval
211
+ good_job_shutdown_timeout = Decidim::Voca::GoodJobSettings.shutdown_timeout
212
+ good_job_retry = Decidim::Voca::GoodJobSettings.retry
213
+ good_job_queues = Decidim::Voca::GoodJobSettings.queues
216
214
  supported_execution_modes = [:async_server, :external]
217
215
  unless supported_execution_modes.include?(execution_mode)
218
216
  raise "Unsupported execution mode: #{execution_mode}. Supported modes are: #{supported_execution_modes.join(", ")}"
@@ -0,0 +1,74 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Voca
5
+ # Good Job settings. Credentials path is good_job.*.
6
+ # Env name is GOOD_JOB__* (ENV, then credentials). VOCA_* is used only when that value is blank.
7
+ module GoodJobSettings
8
+ DEFAULTS = {
9
+ execution_mode: "async_server",
10
+ max_threads: 5,
11
+ poll_interval: 30,
12
+ shutdown_timeout: 120,
13
+ retry: 5,
14
+ queues: "*"
15
+ }.freeze
16
+
17
+ LEGACY_ENV = {
18
+ execution_mode: "VOCA_ACTIVE_JOB_EXECUTION_MODE",
19
+ max_threads: "VOCA_GOOD_JOB_MAX_THREADS",
20
+ poll_interval: "VOCA_GOOD_JOB_POLL_INTERVAL",
21
+ shutdown_timeout: "VOCA_GOOD_JOB_SHUTDOWN_TIMEOUT",
22
+ retry: "VOCA_GOOD_JOB_RETRY",
23
+ queues: "VOCA_GOOD_JOB_QUEUES"
24
+ }.freeze
25
+
26
+ module_function
27
+
28
+ def execution_mode
29
+ fetch(:execution_mode).to_sym
30
+ end
31
+
32
+ def max_threads
33
+ fetch(:max_threads).to_i
34
+ end
35
+
36
+ def poll_interval
37
+ fetch(:poll_interval).to_i
38
+ end
39
+
40
+ def shutdown_timeout
41
+ fetch(:shutdown_timeout).to_i
42
+ end
43
+
44
+ def retry
45
+ fetch(:retry).to_i
46
+ end
47
+
48
+ def queues
49
+ fetch(:queues).to_s
50
+ end
51
+
52
+ def fetch(key)
53
+ value = canonical(key)
54
+ value = ENV.fetch(LEGACY_ENV.fetch(key), nil) if blank?(value)
55
+ blank?(value) ? DEFAULTS.fetch(key) : value
56
+ end
57
+
58
+ def canonical(key)
59
+ if defined?(::CredentialsOverlay)
60
+ from_env = ENV.fetch(::CredentialsOverlay.env_for(:good_job, key), nil)
61
+ return from_env unless blank?(from_env)
62
+
63
+ ::CredentialsOverlay.dig(:good_job, key)
64
+ else
65
+ ENV.fetch("GOOD_JOB__#{key.to_s.upcase}", nil)
66
+ end
67
+ end
68
+
69
+ def blank?(value)
70
+ value.nil? || value == ""
71
+ end
72
+ end
73
+ end
74
+ end
@@ -26,7 +26,7 @@ module Decidim
26
26
  end
27
27
 
28
28
  def deepl_enabled?
29
- deepl_installed? && Decidim::Voca::DeepL::Settings.api_key.present?
29
+ deepl_installed? && ::Decidim::Env.new("DECIDIM_DEEPL_API_KEY", "").present?
30
30
  end
31
31
  end
32
32
  end
@@ -5,7 +5,7 @@ module Decidim
5
5
  MODULE_NAME = "decidim_voca"
6
6
 
7
7
  def self.version
8
- "0.1.1" # DO NOT UPDATE MANUALLY
8
+ "0.1.2" # DO NOT UPDATE MANUALLY
9
9
  end
10
10
 
11
11
  def self.decidim_version
data/lib/decidim/voca.rb CHANGED
@@ -1,7 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative "voca/version"
3
4
  require_relative "voca/installation"
4
5
  require_relative "voca/deepl"
6
+ require_relative "voca/cache_namespace"
7
+ require_relative "voca/good_job_settings"
5
8
 
6
9
  require_relative "voca/engine"
7
10
  require_relative "voca/overrides/mod_secure/user_profile_verification_override"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: decidim-voca
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hadrien Froger
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2026-11-25 00:00:00.000000000 Z
12
+ date: 2026-11-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: decidim-admin
@@ -228,6 +228,7 @@ files:
228
228
  - lib/decidim/voca.rb
229
229
  - lib/decidim/voca/awesome_menu_label_machine_translation.rb
230
230
  - lib/decidim/voca/awesome_menu_labels.rb
231
+ - lib/decidim/voca/cache_namespace.rb
231
232
  - lib/decidim/voca/code_census.rb
232
233
  - lib/decidim/voca/code_census/admin_engine.rb
233
234
  - lib/decidim/voca/code_census/engine.rb
@@ -245,13 +246,13 @@ files:
245
246
  - lib/decidim/voca/deepl/deepl_machine_translator.rb
246
247
  - lib/decidim/voca/deepl/deepl_middleware.rb
247
248
  - lib/decidim/voca/deepl/engine_config.rb
248
- - lib/decidim/voca/deepl/settings.rb
249
249
  - lib/decidim/voca/deepl/translation_bar_overrides.rb
250
250
  - lib/decidim/voca/engine.rb
251
251
  - lib/decidim/voca/export/comment_serializer_localized_csv.rb
252
252
  - lib/decidim/voca/export/csv_with_locale_transformer.rb
253
253
  - lib/decidim/voca/export/proposal_serializer_localized_csv.rb
254
254
  - lib/decidim/voca/export/user_answers_serializer_localized_csv.rb
255
+ - lib/decidim/voca/good_job_settings.rb
255
256
  - lib/decidim/voca/installation.rb
256
257
  - lib/decidim/voca/machine_translation/translate_string.rb
257
258
  - lib/decidim/voca/machine_translation_human_source.rb
@@ -1,75 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Decidim
4
- module Voca
5
- module DeepL
6
- # Resolve DeepL client settings: host CredentialsOverlay when present,
7
- # otherwise credentials dig then ENV (canonical __ names, legacy _ fallback).
8
- module Settings
9
- PATH_PREFIX = :decidim
10
- DEFAULT_HOST = "https://api.deepl.com"
11
- DEFAULT_VERSION = "v2"
12
- LEGACY_KEYS = [:deepl_api_key, :deepl_host, :deepl_version].freeze
13
-
14
- module_function
15
-
16
- def api_key
17
- fetch(:deepl_api_key, default: "")
18
- end
19
-
20
- def host
21
- fetch(:deepl_host, default: DEFAULT_HOST)
22
- end
23
-
24
- def version
25
- fetch(:deepl_version, default: DEFAULT_VERSION)
26
- end
27
-
28
- def fetch(key, default: nil)
29
- path = [PATH_PREFIX, key]
30
- return overlay_fetch(*path, default:) if defined?(CredentialsOverlay)
31
-
32
- value = credentials_dig(*path)
33
- value = env_value(*path) if blank?(value)
34
- blank?(value) ? default : value
35
- end
36
-
37
- def overlay_fetch(*path, default: nil)
38
- CredentialsOverlay.fetch(*path, default:)
39
- end
40
-
41
- def credentials_dig(*path)
42
- return nil unless defined?(Rails) && Rails.application
43
-
44
- Rails.application.credentials.dig(*path)
45
- rescue ActiveSupport::EncryptedFile::MissingKeyError,
46
- ActiveSupport::EncryptedFile::MissingContentError
47
- nil
48
- end
49
-
50
- def env_value(*path)
51
- canonical = env_name(*path)
52
- legacy = legacy_env_name(*path)
53
- value = ENV.fetch(canonical, nil)
54
- value = ENV.fetch(legacy, nil) if blank?(value) && legacy
55
- value
56
- end
57
-
58
- def env_name(*path)
59
- path.map { |part| part.to_s.upcase }.join("__")
60
- end
61
-
62
- # Single-underscore names used before nested __ convention (CI/compose).
63
- def legacy_env_name(*path)
64
- return unless path.size == 2 && path[0] == PATH_PREFIX && LEGACY_KEYS.include?(path[1])
65
-
66
- path.map { |part| part.to_s.upcase }.join("_")
67
- end
68
-
69
- def blank?(value)
70
- value.nil? || value == ""
71
- end
72
- end
73
- end
74
- end
75
- end