decidim-term_customizer 0.17.0 → 0.20.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -2,7 +2,7 @@
|
|
2
2
|
<div class="card-divider">
|
3
3
|
<h2 class="card-title flex--sbc">
|
4
4
|
<div>
|
5
|
-
<%= link_to t("decidim.term_customizer.menu.term_customizer"),
|
5
|
+
<%= link_to t("decidim.term_customizer.menu.term_customizer"), translation_sets_path %>
|
6
6
|
>
|
7
7
|
<%= link_to translated_attribute(set.name), translation_set_translations_path(set) %>
|
8
8
|
>
|
@@ -2,7 +2,7 @@
|
|
2
2
|
<div class="card-divider">
|
3
3
|
<h2 class="card-title flex--sbc">
|
4
4
|
<div>
|
5
|
-
<%= link_to t("decidim.term_customizer.menu.term_customizer"),
|
5
|
+
<%= link_to t("decidim.term_customizer.menu.term_customizer"), translation_sets_path %>
|
6
6
|
>
|
7
7
|
<%= translated_attribute(set.name) %>
|
8
8
|
|
@@ -20,7 +20,7 @@
|
|
20
20
|
<% if allowed_to? :import, :translation_set, translation_set: set %>
|
21
21
|
<%= link_to t("actions.import", scope: "decidim.term_customizer.admin"), import_translation_set_translations_path(set), class: "button tiny button--simple" %>
|
22
22
|
<% end %>
|
23
|
-
<% if allowed_to?
|
23
|
+
<% if set.translations.count > 0 && allowed_to?(:export, :translation_set, translation_set: set) %>
|
24
24
|
<%= render partial: "export_dropdown" %>
|
25
25
|
<% end %>
|
26
26
|
</div>
|
@@ -3,7 +3,7 @@
|
|
3
3
|
<div class="card-divider">
|
4
4
|
<h2 class="card-title flex--sbc">
|
5
5
|
<div>
|
6
|
-
<%= link_to t("decidim.term_customizer.menu.term_customizer"),
|
6
|
+
<%= link_to t("decidim.term_customizer.menu.term_customizer"), translation_sets_path %>
|
7
7
|
>
|
8
8
|
<%= link_to translated_attribute(set.name), translation_set_translations_path(set) %>
|
9
9
|
>
|
@@ -3,7 +3,7 @@
|
|
3
3
|
<div class="card-divider">
|
4
4
|
<h2 class="card-title flex--sbc">
|
5
5
|
<div>
|
6
|
-
<%= link_to t("decidim.term_customizer.menu.term_customizer"),
|
6
|
+
<%= link_to t("decidim.term_customizer.menu.term_customizer"), translation_sets_path %>
|
7
7
|
>
|
8
8
|
<%= link_to translated_attribute(set.name), translation_set_translations_path(set) %>
|
9
9
|
>
|
data/config/locales/ca.yml
CHANGED
@@ -26,10 +26,13 @@ ca:
|
|
26
26
|
back: Enrere
|
27
27
|
cancel: Cancel
|
28
28
|
clear_cache: Clear cache
|
29
|
+
confirm_duplicate: Are you sure you want to duplicate this set?
|
30
|
+
duplicate: Duplicate
|
29
31
|
help: Help
|
30
32
|
import: Import
|
31
33
|
new_translation: Nova traducció
|
32
34
|
new_translation_set: Nou set/joc de traducció
|
35
|
+
view: View
|
33
36
|
add_translations:
|
34
37
|
index:
|
35
38
|
add: Afegir
|
@@ -61,6 +64,10 @@ ca:
|
|
61
64
|
success: Traducció creada amb èxit
|
62
65
|
destroy:
|
63
66
|
success: La traducció ha estat esborrada amb èxit.
|
67
|
+
duplicate:
|
68
|
+
copied_set_name: Copy of %{name}
|
69
|
+
error: Error duplicating translation set.
|
70
|
+
success: Translation set successfully duplicated.
|
64
71
|
edit:
|
65
72
|
save: Guardar
|
66
73
|
title: Set/Joc de traducció
|
@@ -70,7 +77,7 @@ ca:
|
|
70
77
|
constraint_help_title: What are constraints?
|
71
78
|
help_html: <p>A translation set is a "container" that holds the translations for a specific context you want to customize.</p> <p>Translation sets help you to organize your customizations and apply them to different contexts. This allows you to customize the same translation differently in different contexts.</p> <p>For example, if you want to customize a button with the term "Add" differently for different participatory processes, you can create separate translation sets for both processes and apply the set to those processes using the constraints.</p>
|
72
79
|
help_title: What is a translation set?
|
73
|
-
title:
|
80
|
+
title: Set/Joc de traducció
|
74
81
|
index:
|
75
82
|
no_records_html: <p>No translation sets available.</p> <p>Start by adding a translation set from the "<a href="%{new_set_link}">%{button_name}</a>" button.</p>
|
76
83
|
new:
|
data/config/locales/en.yml
CHANGED
@@ -27,10 +27,13 @@ en:
|
|
27
27
|
back: Back
|
28
28
|
cancel: Cancel
|
29
29
|
clear_cache: Clear cache
|
30
|
+
confirm_duplicate: Are you sure you want to duplicate this set?
|
31
|
+
duplicate: Duplicate
|
30
32
|
help: Help
|
31
33
|
import: Import
|
32
34
|
new_translation: New translation
|
33
35
|
new_translation_set: New translation set
|
36
|
+
view: View
|
34
37
|
add_translations:
|
35
38
|
index:
|
36
39
|
add: Add
|
@@ -69,6 +72,10 @@ en:
|
|
69
72
|
success: Translation set successfully created.
|
70
73
|
destroy:
|
71
74
|
success: Translation set successfully deleted.
|
75
|
+
duplicate:
|
76
|
+
copied_set_name: Copy of %{name}
|
77
|
+
error: Error duplicating translation set.
|
78
|
+
success: Translation set successfully duplicated.
|
72
79
|
edit:
|
73
80
|
save: Save
|
74
81
|
title: Translation set
|
@@ -94,7 +101,7 @@ en:
|
|
94
101
|
processes, you can create separate translation sets for both processes
|
95
102
|
and apply the set to those processes using the constraints.</p>
|
96
103
|
help_title: What is a translation set?
|
97
|
-
title: Translation set
|
104
|
+
title: Translation set
|
98
105
|
index:
|
99
106
|
no_records_html: <p>No translation sets available.</p> <p>Start by adding
|
100
107
|
a translation set from the "<a href="%{new_set_link}">%{button_name}</a>"
|
data/config/locales/es.yml
CHANGED
@@ -26,10 +26,13 @@ es:
|
|
26
26
|
back: Volver
|
27
27
|
cancel: Cancel
|
28
28
|
clear_cache: Clear cache
|
29
|
+
confirm_duplicate: Are you sure you want to duplicate this set?
|
30
|
+
duplicate: Duplicate
|
29
31
|
help: Help
|
30
32
|
import: Import
|
31
33
|
new_translation: Nueva traducción
|
32
34
|
new_translation_set: Nuevo grupo de traducciones
|
35
|
+
view: View
|
33
36
|
add_translations:
|
34
37
|
index:
|
35
38
|
add: Añadir
|
@@ -61,6 +64,10 @@ es:
|
|
61
64
|
success: Gurpo de tranducciones creado exitosamente.
|
62
65
|
destroy:
|
63
66
|
success: El grupo de traducciones ha sido creado exitosamente.
|
67
|
+
duplicate:
|
68
|
+
copied_set_name: Copy of %{name}
|
69
|
+
error: Error duplicating translation set.
|
70
|
+
success: Translation set successfully duplicated.
|
64
71
|
edit:
|
65
72
|
save: Guardar
|
66
73
|
title: Grupo de traducciones
|
@@ -70,7 +77,7 @@ es:
|
|
70
77
|
constraint_help_title: What are constraints?
|
71
78
|
help_html: <p>A translation set is a "container" that holds the translations for a specific context you want to customize.</p> <p>Translation sets help you to organize your customizations and apply them to different contexts. This allows you to customize the same translation differently in different contexts.</p> <p>For example, if you want to customize a button with the term "Add" differently for different participatory processes, you can create separate translation sets for both processes and apply the set to those processes using the constraints.</p>
|
72
79
|
help_title: What is a translation set?
|
73
|
-
title:
|
80
|
+
title: Grupo de traducciones
|
74
81
|
index:
|
75
82
|
no_records_html: <p>No translation sets available.</p> <p>Start by adding a translation set from the "<a href="%{new_set_link}">%{button_name}</a>" button.</p>
|
76
83
|
new:
|
data/config/locales/fi.yml
CHANGED
@@ -26,10 +26,13 @@ fi:
|
|
26
26
|
back: Takaisin
|
27
27
|
cancel: Peruuta
|
28
28
|
clear_cache: Tyhjennä välimuisti
|
29
|
+
confirm_duplicate: Haluatko varmasti kopioida tämän paketin?
|
30
|
+
duplicate: Kopioi
|
29
31
|
help: Ohjeet
|
30
32
|
import: Tuo
|
31
33
|
new_translation: Uusi käännös
|
32
34
|
new_translation_set: Uusi käännöspaketti
|
35
|
+
view: Näytä
|
33
36
|
add_translations:
|
34
37
|
index:
|
35
38
|
add: Lisää
|
@@ -61,6 +64,10 @@ fi:
|
|
61
64
|
success: Käännöspaketin luonti onnistui.
|
62
65
|
destroy:
|
63
66
|
success: Käännöspaketin poisto onnistui.
|
67
|
+
duplicate:
|
68
|
+
copied_set_name: 'Kopio: %{name}'
|
69
|
+
error: Käännöspaketin kopiointi epäonnistui.
|
70
|
+
success: Käännöspaketin kopiointi onnistui.
|
64
71
|
edit:
|
65
72
|
save: Tallenna
|
66
73
|
title: Käännöspaketti
|
@@ -70,7 +77,7 @@ fi:
|
|
70
77
|
constraint_help_title: Mitä ovat rajaussäännöt?
|
71
78
|
help_html: <p>Käännöspaketti, on "paketti", joka sisältää käännöksiä tietylle kontekstille, jonka termejä haluat muuttaa.</p><p>Käännöspaketit auttavat sinua pitämään kustomointisi järjestyksessä ja rajaamaan niitä tiettyihin konteksteihin. Tämä mahdollistaa sen, että voit esimerkiksi muuttaa saman termin eri tavalla sivuston eri paikoissa.</p><p>Mikäli haluat esimerkiski muuttaa "Lisää" -napin tekstin erilaiseksi eri prosesseille, voit luoda kaksi erillistä käännöspakettia molempia prosesseja varten. Molemmat paketit rajataan kyseisiin prosesseihin rajaussääntöjen avulla.</p>
|
72
79
|
help_title: Mikä on käännöspaketti?
|
73
|
-
title: Käännöspaketti
|
80
|
+
title: Käännöspaketti
|
74
81
|
index:
|
75
82
|
no_records_html: <p>Ei käännöspaketteja.</p><p>Aloita lisäämällä käännöspaketti "<a href="%{new_set_link}">%{button_name}</a>" -napin avulla.</p>
|
76
83
|
new:
|
data/config/locales/fr.yml
CHANGED
@@ -26,10 +26,13 @@ fr:
|
|
26
26
|
back: Retour
|
27
27
|
cancel: Cancel
|
28
28
|
clear_cache: Purger le cache
|
29
|
+
confirm_duplicate: Are you sure you want to duplicate this set?
|
30
|
+
duplicate: Duplicate
|
29
31
|
help: Help
|
30
32
|
import: Import
|
31
33
|
new_translation: Nouvelle traduction
|
32
34
|
new_translation_set: Nouveau jeu de traduction
|
35
|
+
view: View
|
33
36
|
add_translations:
|
34
37
|
index:
|
35
38
|
add: Ajouter
|
@@ -61,16 +64,20 @@ fr:
|
|
61
64
|
success: Jeu de traduction créé avec succès.
|
62
65
|
destroy:
|
63
66
|
success: Le jeu de traduction a été supprimé.
|
67
|
+
duplicate:
|
68
|
+
copied_set_name: Copy of %{name}
|
69
|
+
error: Error duplicating translation set.
|
70
|
+
success: Translation set successfully duplicated.
|
64
71
|
edit:
|
65
72
|
save: Sauvegarder
|
66
|
-
title: Jeu de
|
73
|
+
title: Jeu de traductions
|
67
74
|
form:
|
68
75
|
add_constraint: Ajouter contrainte
|
69
76
|
constraint_help_html: <p>Constraints are specific rules that allow you to apply the customizations in a set to a specific context.</p> <p>In case you do not define any constraint rules, the customizations in this set will apply to the whole application. On the other hand, if you want the customizations in this set to apply only to a specific process, select "Participatory processes" as the participatory space type and the target process as the participatory space. Furthermore, you can also apply the customizations to a specific component by defining the component for the constraint.</p> <p>If you define multiple constraints, the customizations will apply in all of those.</p>
|
70
77
|
constraint_help_title: What are constraints?
|
71
78
|
help_html: <p>A translation set is a "container" that holds the translations for a specific context you want to customize.</p> <p>Translation sets help you to organize your customizations and apply them to different contexts. This allows you to customize the same translation differently in different contexts.</p> <p>For example, if you want to customize a button with the term "Add" differently for different participatory processes, you can create separate translation sets for both processes and apply the set to those processes using the constraints.</p>
|
72
79
|
help_title: What is a translation set?
|
73
|
-
title:
|
80
|
+
title: Jeu de traductions
|
74
81
|
index:
|
75
82
|
no_records_html: <p>No translation sets available.</p> <p>Start by adding a translation set from the "<a href="%{new_set_link}">%{button_name}</a>" button.</p>
|
76
83
|
new:
|
data/config/locales/sv.yml
CHANGED
@@ -26,10 +26,13 @@ sv:
|
|
26
26
|
back: Back
|
27
27
|
cancel: Cancel
|
28
28
|
clear_cache: Clear cache
|
29
|
+
confirm_duplicate: Are you sure you want to duplicate this set?
|
30
|
+
duplicate: Duplicate
|
29
31
|
help: Help
|
30
32
|
import: Import
|
31
33
|
new_translation: New translation
|
32
34
|
new_translation_set: New translation set
|
35
|
+
view: View
|
33
36
|
add_translations:
|
34
37
|
index:
|
35
38
|
add: Add
|
@@ -61,6 +64,10 @@ sv:
|
|
61
64
|
success: Translation set successfully created.
|
62
65
|
destroy:
|
63
66
|
success: Translation set successfully deleted.
|
67
|
+
duplicate:
|
68
|
+
copied_set_name: Copy of %{name}
|
69
|
+
error: Error duplicating translation set.
|
70
|
+
success: Translation set successfully duplicated.
|
64
71
|
edit:
|
65
72
|
save: Save
|
66
73
|
title: Translation set
|
@@ -70,7 +77,7 @@ sv:
|
|
70
77
|
constraint_help_title: What are constraints?
|
71
78
|
help_html: <p>A translation set is a "container" that holds the translations for a specific context you want to customize.</p> <p>Translation sets help you to organize your customizations and apply them to different contexts. This allows you to customize the same translation differently in different contexts.</p> <p>For example, if you want to customize a button with the term "Add" differently for different participatory processes, you can create separate translation sets for both processes and apply the set to those processes using the constraints.</p>
|
72
79
|
help_title: What is a translation set?
|
73
|
-
title: Translation set
|
80
|
+
title: Translation set
|
74
81
|
index:
|
75
82
|
no_records_html: <p>No translation sets available.</p> <p>Start by adding a translation set from the "<a href="%{new_set_link}">%{button_name}</a>" button.</p>
|
76
83
|
new:
|
@@ -4,12 +4,17 @@ require_relative "term_customizer/version"
|
|
4
4
|
require_relative "term_customizer/engine"
|
5
5
|
require_relative "term_customizer/admin"
|
6
6
|
require_relative "term_customizer/admin_engine"
|
7
|
+
require_relative "term_customizer/context"
|
7
8
|
|
8
9
|
module Decidim
|
9
10
|
module TermCustomizer
|
11
|
+
include ActiveSupport::Configurable
|
12
|
+
|
10
13
|
autoload :I18nBackend, "decidim/term_customizer/i18n_backend"
|
11
14
|
autoload :Import, "decidim/term_customizer/import"
|
12
15
|
autoload :Loader, "decidim/term_customizer/loader"
|
16
|
+
autoload :PluralFormsForm, "decidim/term_customizer/plural_forms_form"
|
17
|
+
autoload :PluralFormsManager, "decidim/term_customizer/plural_forms_manager"
|
13
18
|
autoload :Resolver, "decidim/term_customizer/resolver"
|
14
19
|
autoload :TranslationDirectory, "decidim/term_customizer/translation_directory"
|
15
20
|
autoload :TranslationImportCollection, "decidim/term_customizer/translation_import_collection"
|
@@ -19,6 +24,18 @@ module Decidim
|
|
19
24
|
|
20
25
|
EMPTY_HASH = {}.freeze
|
21
26
|
|
27
|
+
# In case you want to customize the context detection for the controllers
|
28
|
+
# and views, configure your own context resolver.
|
29
|
+
config_accessor :controller_context_class do
|
30
|
+
Decidim::TermCustomizer::Context::ControllerContext
|
31
|
+
end
|
32
|
+
|
33
|
+
# In case you want to customize the context detection for the jobs,
|
34
|
+
# configure your own context resolver.
|
35
|
+
config_accessor :job_context_class do
|
36
|
+
Decidim::TermCustomizer::Context::JobContext
|
37
|
+
end
|
38
|
+
|
22
39
|
class << self
|
23
40
|
attr_accessor :loader
|
24
41
|
end
|
@@ -11,11 +11,12 @@ module Decidim
|
|
11
11
|
routes do
|
12
12
|
resources :translation_sets, path: :sets, except: [:show] do
|
13
13
|
member do
|
14
|
-
post :
|
14
|
+
post :duplicate
|
15
15
|
end
|
16
16
|
|
17
17
|
resources :translations, except: [:show] do
|
18
18
|
collection do
|
19
|
+
post :export
|
19
20
|
get :import, action: :new_import
|
20
21
|
post :import
|
21
22
|
resource :translations_destroy, only: [:new, :destroy]
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module TermCustomizer
|
5
|
+
module Context
|
6
|
+
autoload :Base, "decidim/term_customizer/context/base"
|
7
|
+
autoload :ControllerContext, "decidim/term_customizer/context/controller_context"
|
8
|
+
autoload :JobContext, "decidim/term_customizer/context/job_context"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module TermCustomizer
|
5
|
+
module Context
|
6
|
+
# A context object resolves and stores the translation context for
|
7
|
+
# different application contexts. Contexts can be e.g.
|
8
|
+
# - Controller context, which is used to display translations in
|
9
|
+
# controller messages and the views.
|
10
|
+
# - Job context, which is used to display messages within jobs, mainly
|
11
|
+
# when sending emails.
|
12
|
+
#
|
13
|
+
# The initialization method gets the data for the context which is used
|
14
|
+
# to resolve the translation context objects (organization, participatory
|
15
|
+
# space and component). These are then used to load the correct
|
16
|
+
# translations for each context based on the translation set constraints.
|
17
|
+
class Base
|
18
|
+
attr_reader :organization, :space, :component
|
19
|
+
|
20
|
+
def initialize(data)
|
21
|
+
@data = data
|
22
|
+
|
23
|
+
# Implement the resolve! method in the sub-classes
|
24
|
+
resolve!
|
25
|
+
end
|
26
|
+
|
27
|
+
protected
|
28
|
+
|
29
|
+
attr_reader :data
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module TermCustomizer
|
5
|
+
module Context
|
6
|
+
class ControllerContext < Base
|
7
|
+
def resolve!
|
8
|
+
env = data[:headers].env
|
9
|
+
controller = env["action_controller.instance"]
|
10
|
+
|
11
|
+
@organization = env["decidim.current_organization"]
|
12
|
+
|
13
|
+
# E.g. at the participatory process controller the
|
14
|
+
# `decidim.current_participatory_space` environment variable has not
|
15
|
+
# been set. Therefore, we need to fetch it directly from the
|
16
|
+
# controller using its private method. In some edge cases this may not
|
17
|
+
# be implemented (https://github.com/mainio/decidim-module-term_customizer/issues/28)
|
18
|
+
# in which case we do not have access to the participatory space.
|
19
|
+
if controller.respond_to?(:current_participatory_space, true)
|
20
|
+
@space = controller.send(
|
21
|
+
:current_participatory_space
|
22
|
+
)
|
23
|
+
end
|
24
|
+
@space ||= env["decidim.current_participatory_space"]
|
25
|
+
|
26
|
+
@component = env["decidim.current_component"]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module TermCustomizer
|
5
|
+
module Context
|
6
|
+
class JobContext < Base
|
7
|
+
def resolve!
|
8
|
+
# Figure out the organization and user through the job arguments if
|
9
|
+
# passed for the job.
|
10
|
+
user = nil
|
11
|
+
data[:job].arguments.each do |arg|
|
12
|
+
@organization ||= organization_from_argument(arg)
|
13
|
+
@space ||= space_from_argument(arg)
|
14
|
+
@component ||= component_from_argument(arg)
|
15
|
+
user ||= arg if arg.is_a?(Decidim::User)
|
16
|
+
end
|
17
|
+
|
18
|
+
# In case a component was found, define the space as the component
|
19
|
+
# space to avoid any conflicts.
|
20
|
+
@space = component.participatory_space if component
|
21
|
+
|
22
|
+
# In case a space was found, define the organization as the space
|
23
|
+
# organization to avoid any conflicts.
|
24
|
+
@organization = space.organization if space
|
25
|
+
|
26
|
+
# In case an organization could not be resolved any other way, check
|
27
|
+
# it through the user (if the user was passed).
|
28
|
+
@organization ||= user.organization if user
|
29
|
+
end
|
30
|
+
|
31
|
+
protected
|
32
|
+
|
33
|
+
def organization_from_argument(arg)
|
34
|
+
return arg if arg.is_a?(Decidim::Organization)
|
35
|
+
|
36
|
+
arg.organization if arg.respond_to?(:organization)
|
37
|
+
end
|
38
|
+
|
39
|
+
def space_from_argument(arg)
|
40
|
+
return arg if arg.is_a?(Decidim::Participable)
|
41
|
+
|
42
|
+
arg.participatory_space if arg.respond_to?(:participatory_space)
|
43
|
+
end
|
44
|
+
|
45
|
+
def component_from_argument(arg)
|
46
|
+
return arg if arg.is_a?(Decidim::Component)
|
47
|
+
|
48
|
+
arg.component if arg.respond_to?(:component)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -17,25 +17,13 @@ module Decidim
|
|
17
17
|
# done through a notification to get access to the `current_*`
|
18
18
|
# environment variables within Decidim.
|
19
19
|
ActiveSupport::Notifications.subscribe "start_processing.action_controller" do |_name, _started, _finished, _unique_id, data|
|
20
|
-
|
21
|
-
controller = data[:headers].env["action_controller.instance"]
|
22
|
-
|
23
|
-
# E.g. at the participatory process controller the
|
24
|
-
# `decidim.current_participatory_space` environment variable has not
|
25
|
-
# been set. Therefore, we need to fetch it directly from the
|
26
|
-
# controller using its private method.
|
27
|
-
space =
|
28
|
-
if controller.respond_to?(:current_participatory_space, true)
|
29
|
-
controller.send(:current_participatory_space)
|
30
|
-
else
|
31
|
-
env["decidim.current_participatory_space"]
|
32
|
-
end
|
20
|
+
context = TermCustomizer.controller_context_class.new(data)
|
33
21
|
|
34
22
|
# Create a new resolver instance within the current request scope
|
35
23
|
resolver = Resolver.new(
|
36
|
-
|
37
|
-
space,
|
38
|
-
|
24
|
+
context.organization,
|
25
|
+
context.space,
|
26
|
+
context.component
|
39
27
|
)
|
40
28
|
|
41
29
|
# Create the loader for the backend to fetch the translations from
|
@@ -58,22 +46,15 @@ module Decidim
|
|
58
46
|
# job that may be fired by another job (i.e. the notification job is
|
59
47
|
# always performed last).
|
60
48
|
ActiveSupport::Notifications.subscribe "perform_start.active_job" do |_name, _started, _finished, _unique_id, data|
|
61
|
-
|
62
|
-
# passed for the job.
|
63
|
-
organization = nil
|
64
|
-
user = nil
|
65
|
-
data[:job].arguments.each do |arg|
|
66
|
-
organization = arg if arg.is_a?(Decidim::Organization)
|
67
|
-
user = arg if arg.is_a?(Decidim::User)
|
68
|
-
end
|
69
|
-
|
70
|
-
# In case an organization was not passed for the job, check it through
|
71
|
-
# the user.
|
72
|
-
organization = user.organization if organization.nil? && user
|
49
|
+
context = TermCustomizer.job_context_class.new(data)
|
73
50
|
|
74
51
|
# Create resolver for the target organization or global context in
|
75
52
|
# case organization was not found
|
76
|
-
resolver = Resolver.new(
|
53
|
+
resolver = Resolver.new(
|
54
|
+
context.organization,
|
55
|
+
context.space,
|
56
|
+
context.component
|
57
|
+
)
|
77
58
|
|
78
59
|
# Create the loader for the backend to fetch the translations from
|
79
60
|
TermCustomizer.loader = Loader.new(resolver)
|