decidim-term_customizer 0.17.0 → 0.20.0
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 +4 -4
- data/Rakefile +0 -8
- data/app/assets/config/translation_sets_admin_manifest.js +1 -0
- data/app/assets/javascripts/decidim/term_customizer/admin/translation_sets_admin.js.es6 +3 -1
- data/app/assets/javascripts/decidim/term_customizer/admin/translations_admin.js.es6 +6 -1
- data/app/commands/decidim/term_customizer/admin/create_translation.rb +3 -0
- data/app/commands/decidim/term_customizer/admin/destroy_translations.rb +3 -0
- data/app/commands/decidim/term_customizer/admin/duplicate_translation_set.rb +61 -0
- data/app/commands/decidim/term_customizer/admin/import_set_translations.rb +3 -0
- data/app/commands/decidim/term_customizer/admin/import_translation_keys.rb +3 -0
- data/app/commands/decidim/term_customizer/admin/update_translation.rb +8 -3
- data/app/controllers/decidim/term_customizer/admin/add_translations_controller.rb +2 -1
- data/app/controllers/decidim/term_customizer/admin/translation_sets_controller.rb +29 -7
- data/app/controllers/decidim/term_customizer/admin/translations_controller.rb +21 -4
- data/app/controllers/decidim/term_customizer/admin/translations_destroys_controller.rb +4 -1
- data/app/forms/decidim/term_customizer/admin/translations_destroy_form.rb +3 -3
- data/app/views/decidim/term_customizer/admin/add_translations/index.html.erb +1 -1
- data/app/views/decidim/term_customizer/admin/translation_sets/_form.html.erb +2 -2
- data/app/views/decidim/term_customizer/admin/translation_sets/index.html.erb +8 -0
- data/app/views/decidim/term_customizer/admin/translations/_export_dropdown.html.erb +1 -1
- data/app/views/decidim/term_customizer/admin/translations/_form.html.erb +1 -1
- data/app/views/decidim/term_customizer/admin/translations/index.html.erb +2 -2
- data/app/views/decidim/term_customizer/admin/translations/new_import.html.erb +1 -1
- data/app/views/decidim/term_customizer/admin/translations_destroys/new.html.erb +1 -1
- data/config/locales/ca.yml +8 -1
- data/config/locales/en.yml +8 -1
- data/config/locales/es.yml +8 -1
- data/config/locales/fi.yml +8 -1
- data/config/locales/fr.yml +9 -2
- data/config/locales/sv.yml +8 -1
- data/lib/decidim/term_customizer.rb +17 -0
- data/lib/decidim/term_customizer/admin_engine.rb +2 -1
- data/lib/decidim/term_customizer/context.rb +11 -0
- data/lib/decidim/term_customizer/context/base.rb +33 -0
- data/lib/decidim/term_customizer/context/controller_context.rb +31 -0
- data/lib/decidim/term_customizer/context/job_context.rb +53 -0
- data/lib/decidim/term_customizer/engine.rb +10 -29
- data/lib/decidim/term_customizer/loader.rb +4 -3
- data/lib/decidim/term_customizer/plural_forms_form.rb +23 -0
- data/lib/decidim/term_customizer/plural_forms_manager.rb +103 -0
- data/lib/decidim/term_customizer/version.rb +2 -2
- metadata +22 -16
@@ -57,9 +57,10 @@ module Decidim
|
|
57
57
|
# the resolver.
|
58
58
|
def clear_cache
|
59
59
|
Rails.cache.delete_matched("#{cache_key_base}/*")
|
60
|
-
rescue NotImplementedError
|
61
|
-
# Some cache store, such as `ActiveSupport::Cache::MemCacheStore`
|
62
|
-
# support `delete_matched`.
|
60
|
+
rescue NotImplementedError, NoMethodError
|
61
|
+
# Some cache store, such as `ActiveSupport::Cache::MemCacheStore` or
|
62
|
+
# `ActiveSupport::Cache::DalliStore` do not support `delete_matched`.
|
63
|
+
# Therefore, clear all the possibly existing
|
63
64
|
# cache keys manually for each space and component.
|
64
65
|
|
65
66
|
# Clear all the "organization" translation keys.
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module TermCustomizer
|
5
|
+
module PluralFormsForm
|
6
|
+
private
|
7
|
+
|
8
|
+
def create_plural_forms(translations)
|
9
|
+
plural_forms_manager.fill!(translations)
|
10
|
+
end
|
11
|
+
|
12
|
+
def destroy_plural_forms(translations)
|
13
|
+
plural_forms_manager.destroy!(translations)
|
14
|
+
end
|
15
|
+
|
16
|
+
def plural_forms_manager
|
17
|
+
@plural_forms_manager ||= TermCustomizer::PluralFormsManager.new(
|
18
|
+
form.current_organization
|
19
|
+
)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module TermCustomizer
|
5
|
+
# Checks that all the plural forms are in the database for the given keys.
|
6
|
+
class PluralFormsManager
|
7
|
+
attr_reader :organization
|
8
|
+
|
9
|
+
@plural_keys = [:zero, :one, :few, :other]
|
10
|
+
|
11
|
+
class << self
|
12
|
+
attr_accessor :plural_keys
|
13
|
+
end
|
14
|
+
|
15
|
+
def initialize(organization)
|
16
|
+
@organization = organization
|
17
|
+
@default_locale = organization.default_locale
|
18
|
+
end
|
19
|
+
|
20
|
+
def fill!(translations)
|
21
|
+
each_plural_form(translations) do |translation, key|
|
22
|
+
add_locales_for!(translation, key)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def destroy!(translations)
|
27
|
+
each_plural_form(translations) do |translation, key|
|
28
|
+
destroy_locales_for!(translation, key)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
attr_reader :default_locale
|
35
|
+
|
36
|
+
def each_plural_form(translations)
|
37
|
+
keys = self.class.plural_keys.map(&:to_s)
|
38
|
+
translations.each do |tr|
|
39
|
+
# Check that the last part of the translation key matches with some
|
40
|
+
# of the plural translation keys.
|
41
|
+
next unless tr.key =~ /\.(#{keys.join("|")})$/
|
42
|
+
|
43
|
+
parts = tr.key.split(".")
|
44
|
+
plural_part = parts.pop
|
45
|
+
base_part = parts.join(".")
|
46
|
+
|
47
|
+
# If it's not a hash, it's not a plural translation
|
48
|
+
next unless I18n.exists?(base_part, default_locale)
|
49
|
+
next unless I18n.t(base_part, locale: default_locale).is_a?(Hash)
|
50
|
+
|
51
|
+
keys.each do |plural_key|
|
52
|
+
# Do not check for the translation itself
|
53
|
+
next if plural_part == plural_key
|
54
|
+
|
55
|
+
full_plural_key = "#{base_part}.#{plural_key}"
|
56
|
+
|
57
|
+
# Check that the translation actually exists, no need to process if
|
58
|
+
# it does not exist.
|
59
|
+
next unless I18n.exists?(full_plural_key, default_locale)
|
60
|
+
|
61
|
+
yield tr, full_plural_key
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def add_locales_for!(translation, target_key)
|
67
|
+
organization.available_locales.each do |locale|
|
68
|
+
# Skip adding the plural form for the translation itself
|
69
|
+
next if target_key == translation.key
|
70
|
+
|
71
|
+
# Check that the translation is not already added in the set
|
72
|
+
next if translation.translation_set.translations.where(
|
73
|
+
key: target_key,
|
74
|
+
locale: locale
|
75
|
+
).any?
|
76
|
+
|
77
|
+
# Add the plural form
|
78
|
+
translation.translation_set.translations.create!(
|
79
|
+
key: target_key,
|
80
|
+
locale: locale,
|
81
|
+
value: I18n.t(target_key, locale: locale, default: "")
|
82
|
+
)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def destroy_locales_for!(translation, target_key)
|
87
|
+
organization.available_locales.each do |locale|
|
88
|
+
# Skip deleting the plural form for the translation itself
|
89
|
+
next if target_key == translation.key
|
90
|
+
|
91
|
+
# Find the plural form the plural form
|
92
|
+
target = translation.translation_set.translations.find_by(
|
93
|
+
key: target_key,
|
94
|
+
locale: locale
|
95
|
+
)
|
96
|
+
next unless target
|
97
|
+
|
98
|
+
target.destroy!
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: decidim-term_customizer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.20.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Antti Hukkanen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-03-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: decidim-admin
|
@@ -16,28 +16,28 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.
|
19
|
+
version: 0.20.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.
|
26
|
+
version: 0.20.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: decidim-core
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.
|
33
|
+
version: 0.20.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0.
|
40
|
+
version: 0.20.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: dalli
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -64,56 +64,56 @@ dependencies:
|
|
64
64
|
requirements:
|
65
65
|
- - "~>"
|
66
66
|
- !ruby/object:Gem::Version
|
67
|
-
version: 0.
|
67
|
+
version: 0.20.0
|
68
68
|
type: :development
|
69
69
|
prerelease: false
|
70
70
|
version_requirements: !ruby/object:Gem::Requirement
|
71
71
|
requirements:
|
72
72
|
- - "~>"
|
73
73
|
- !ruby/object:Gem::Version
|
74
|
-
version: 0.
|
74
|
+
version: 0.20.0
|
75
75
|
- !ruby/object:Gem::Dependency
|
76
76
|
name: decidim-dev
|
77
77
|
requirement: !ruby/object:Gem::Requirement
|
78
78
|
requirements:
|
79
79
|
- - "~>"
|
80
80
|
- !ruby/object:Gem::Version
|
81
|
-
version: 0.
|
81
|
+
version: 0.20.0
|
82
82
|
type: :development
|
83
83
|
prerelease: false
|
84
84
|
version_requirements: !ruby/object:Gem::Requirement
|
85
85
|
requirements:
|
86
86
|
- - "~>"
|
87
87
|
- !ruby/object:Gem::Version
|
88
|
-
version: 0.
|
88
|
+
version: 0.20.0
|
89
89
|
- !ruby/object:Gem::Dependency
|
90
90
|
name: decidim-participatory_processes
|
91
91
|
requirement: !ruby/object:Gem::Requirement
|
92
92
|
requirements:
|
93
93
|
- - "~>"
|
94
94
|
- !ruby/object:Gem::Version
|
95
|
-
version: 0.
|
95
|
+
version: 0.20.0
|
96
96
|
type: :development
|
97
97
|
prerelease: false
|
98
98
|
version_requirements: !ruby/object:Gem::Requirement
|
99
99
|
requirements:
|
100
100
|
- - "~>"
|
101
101
|
- !ruby/object:Gem::Version
|
102
|
-
version: 0.
|
102
|
+
version: 0.20.0
|
103
103
|
- !ruby/object:Gem::Dependency
|
104
104
|
name: decidim-proposals
|
105
105
|
requirement: !ruby/object:Gem::Requirement
|
106
106
|
requirements:
|
107
107
|
- - "~>"
|
108
108
|
- !ruby/object:Gem::Version
|
109
|
-
version: 0.
|
109
|
+
version: 0.20.0
|
110
110
|
type: :development
|
111
111
|
prerelease: false
|
112
112
|
version_requirements: !ruby/object:Gem::Requirement
|
113
113
|
requirements:
|
114
114
|
- - "~>"
|
115
115
|
- !ruby/object:Gem::Version
|
116
|
-
version: 0.
|
116
|
+
version: 0.20.0
|
117
117
|
description: Adds a UI to customize the terms and limit the customizations to specific
|
118
118
|
places.
|
119
119
|
email:
|
@@ -135,6 +135,7 @@ files:
|
|
135
135
|
- app/commands/decidim/term_customizer/admin/create_translation.rb
|
136
136
|
- app/commands/decidim/term_customizer/admin/create_translation_set.rb
|
137
137
|
- app/commands/decidim/term_customizer/admin/destroy_translations.rb
|
138
|
+
- app/commands/decidim/term_customizer/admin/duplicate_translation_set.rb
|
138
139
|
- app/commands/decidim/term_customizer/admin/import_set_translations.rb
|
139
140
|
- app/commands/decidim/term_customizer/admin/import_translation_keys.rb
|
140
141
|
- app/commands/decidim/term_customizer/admin/update_translation.rb
|
@@ -190,6 +191,10 @@ files:
|
|
190
191
|
- lib/decidim/term_customizer.rb
|
191
192
|
- lib/decidim/term_customizer/admin.rb
|
192
193
|
- lib/decidim/term_customizer/admin_engine.rb
|
194
|
+
- lib/decidim/term_customizer/context.rb
|
195
|
+
- lib/decidim/term_customizer/context/base.rb
|
196
|
+
- lib/decidim/term_customizer/context/controller_context.rb
|
197
|
+
- lib/decidim/term_customizer/context/job_context.rb
|
193
198
|
- lib/decidim/term_customizer/engine.rb
|
194
199
|
- lib/decidim/term_customizer/i18n_backend.rb
|
195
200
|
- lib/decidim/term_customizer/import.rb
|
@@ -202,6 +207,8 @@ files:
|
|
202
207
|
- lib/decidim/term_customizer/import/readers/json.rb
|
203
208
|
- lib/decidim/term_customizer/import/readers/xls.rb
|
204
209
|
- lib/decidim/term_customizer/loader.rb
|
210
|
+
- lib/decidim/term_customizer/plural_forms_form.rb
|
211
|
+
- lib/decidim/term_customizer/plural_forms_manager.rb
|
205
212
|
- lib/decidim/term_customizer/resolver.rb
|
206
213
|
- lib/decidim/term_customizer/test/factories.rb
|
207
214
|
- lib/decidim/term_customizer/translation_directory.rb
|
@@ -229,8 +236,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
229
236
|
- !ruby/object:Gem::Version
|
230
237
|
version: '0'
|
231
238
|
requirements: []
|
232
|
-
|
233
|
-
rubygems_version: 2.7.6
|
239
|
+
rubygems_version: 3.0.3
|
234
240
|
signing_key:
|
235
241
|
specification_version: 4
|
236
242
|
summary: Provides possibility to customize Decidim's localized terms.
|