decidim-voca 0.0.6 → 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 +4 -4
- data/LICENSE.md +161 -161
- data/README.md +42 -133
- data/Rakefile +46 -39
- data/app/cells/decidim/footer_topics/show_overrides.erb +8 -0
- data/app/cells/decidim/meetings/dates_and_map/show_overrides.erb +23 -0
- data/app/commands/decidim/voca/admin/code_census/save_code_list.rb +34 -0
- data/app/commands/decidim/voca/code_census/confirm_code_authorization.rb +16 -0
- data/app/commands/decidim/voca/create_editor_file.rb +36 -0
- data/app/commands/decidim/voca/rack_attack_configurator.rb +244 -0
- data/app/commands/decidim/voca/sync_redis_routing.rb +120 -0
- data/app/commands/decidim/voca/user_fields_configurator.rb +40 -0
- data/app/controllers/decidim/voca/admin/application_controller.rb +4 -6
- data/app/controllers/decidim/voca/admin/code_census/code_lists_controller.rb +40 -0
- data/app/controllers/decidim/voca/application_controller.rb +4 -6
- data/app/controllers/decidim/voca/code_census/authorizations_controller.rb +53 -0
- data/app/controllers/decidim/voca/editor_files_controller.rb +47 -0
- data/app/controllers/decidim/voca/geolocation_controller.rb +32 -0
- data/app/forms/decidim/voca/admin/code_census/code_list_form.rb +21 -0
- data/app/forms/decidim/voca/admin/organization_config_form.rb +24 -0
- data/app/forms/decidim/voca/code_census/code_form.rb +41 -0
- data/app/forms/decidim/voca/editor_file_form.rb +18 -0
- data/app/jobs/decidim/voca/machine_translate_awesome_menu_label_job.rb +63 -0
- data/app/jobs/decidim/voca/machine_translate_component_setting_job.rb +58 -0
- data/app/jobs/decidim/voca/machine_translate_content_block_setting_job.rb +85 -0
- data/app/models/decidim/voca/conversation_uuid.rb +18 -0
- data/app/models/decidim/voca/editor_file.rb +18 -0
- data/app/models/decidim/voca/validation_code.rb +13 -0
- data/app/overrides/admin_add_machine_translation_flag.rb +36 -0
- data/app/overrides/insert_assets.rb +26 -0
- data/app/overrides/insert_weglot_scripts.rb +36 -0
- data/app/overrides/proposal_camera.rb +18 -0
- data/app/overrides/show_votes.rb +27 -0
- data/app/overrides/voca_footer.rb +52 -0
- data/app/packs/entrypoints/admin-decidim-voca.js +2 -0
- data/app/packs/entrypoints/admin-decidim-voca.scss +1 -0
- data/app/packs/entrypoints/decidim-voca-fixes.scss +1 -0
- data/app/packs/entrypoints/decidim-voca.js +1 -0
- data/app/packs/entrypoints/decidim-voca.scss +1 -0
- data/app/packs/images/voca-logo-primary-x3.png +0 -0
- data/app/packs/src/decidim/direct_uploads/upload_field.js +150 -0
- data/app/packs/src/decidim/voca/admin/voca.js +16 -0
- data/app/packs/src/decidim/voca/proposal_better_ux/use_camera_button.js +39 -0
- data/app/packs/src/decidim/voca/proposal_better_ux/utils/get_current_position.js +21 -0
- data/app/packs/src/decidim/voca/proposal_better_ux/utils/get_proposal_form.js +13 -0
- data/app/packs/src/decidim/voca/proposal_better_ux/utils/loading.js +23 -0
- data/app/packs/src/decidim/voca/proposal_better_ux/utils/locate_coordinates.js +23 -0
- data/app/packs/src/decidim/voca/proposal_custom_fields/custom_field_renderer_override.js +152 -0
- data/app/packs/src/decidim/voca/proposal_custom_fields/editor_budget_field.js +329 -0
- data/app/packs/src/decidim/voca/proposal_custom_fields/editor_upload_field.js +85 -0
- data/app/packs/src/decidim/voca/proposal_custom_fields/proposal_custom_fields.js +96 -0
- data/app/packs/src/decidim/voca/proposal_custom_fields/render_budget_field.js +76 -0
- data/app/packs/src/decidim/voca/proposal_fields/render_budget_field.js +76 -0
- data/app/packs/src/decidim/voca/questionnaire/scroll_questionnaire_steps_to_top.js +18 -0
- data/app/packs/src/decidim/voca/voca.js +4 -0
- data/app/packs/src/decidim/voca/weglot/index.js +13 -0
- data/app/packs/src/decidim/voca/weglot/start_weglot.js +112 -0
- data/app/packs/src/decidim/voca/weglot/switcher.js +92 -0
- data/app/packs/src/decidim/voca/weglot/wait_for_weglot.js +10 -0
- data/app/packs/stylesheets/decidim/voca/_custom_proposal_fields.scss +111 -0
- data/app/packs/stylesheets/decidim/voca/_decidim_voca.scss +5 -0
- data/app/packs/stylesheets/decidim/voca/_decidim_voca_fixes.scss +25 -0
- data/app/packs/stylesheets/decidim/voca/_primary_footer.scss +77 -0
- data/app/packs/stylesheets/decidim/voca/_proposal_camera.scss +14 -0
- data/app/packs/stylesheets/decidim/voca/_weglot.scss +61 -0
- data/app/packs/stylesheets/decidim/voca/admin/_decidim_voca.scss +5 -0
- data/app/packs/stylesheets/decidim/voca/admin/_full_machine_translation.scss +34 -0
- data/app/permissions/decidim/voca/admin/permissions.rb +31 -0
- data/app/permissions/decidim/voca/permissions.rb +17 -0
- data/app/views/decidim/voca/admin/code_census/authorizations/new.html.erb +33 -0
- data/app/views/decidim/voca/admin/code_census/code_lists/edit.html.erb +27 -0
- data/app/views/decidim/voca/code_census/authorizations/new.html.erb +24 -0
- data/app/views/decidim/voca/deepl/overrides/_admin_machine_translation_alert.html.erb +14 -0
- data/app/views/decidim/voca/rack_attack/_blocked.html.erb +151 -0
- data/app/views/decidim/voca/weglot/_js_configuration.html.erb +14 -0
- data/app/views/decidim/voca/weglot/_locale_switcher.html.erb +14 -0
- data/app/views/decidim/voca/weglot/_locale_switcher_mobile.erb +14 -0
- data/app/views/decidim/voca/weglot/_topbar_locale_switcher.html.erb +14 -0
- data/config/assets.rb +12 -0
- data/config/i18n-tasks.yml +14 -5
- data/config/locales/cs.yml +94 -0
- data/config/locales/custom_fields.cs.yml +30 -0
- data/config/locales/custom_fields.en.yml +41 -0
- data/config/locales/custom_fields.fr.yml +30 -0
- data/config/locales/custom_fields.it.yml +30 -0
- data/config/locales/en.yml +97 -4
- data/config/locales/fr.yml +102 -0
- data/config/locales/it.yml +94 -0
- data/lib/decidim/voca/awesome_menu_label_machine_translation.rb +73 -0
- data/lib/decidim/voca/awesome_menu_labels.rb +28 -0
- data/lib/decidim/voca/cache_namespace.rb +21 -0
- data/lib/decidim/voca/code_census/admin_engine.rb +22 -0
- data/lib/decidim/voca/code_census/engine.rb +29 -0
- data/lib/decidim/voca/code_census/workflow.rb +7 -0
- data/lib/decidim/voca/code_census.rb +4 -0
- data/lib/decidim/voca/component_setting_manifest.rb +27 -0
- data/lib/decidim/voca/component_setting_pending_locales.rb +33 -0
- data/lib/decidim/voca/component_translated_settings_machine_translation.rb +86 -0
- data/lib/decidim/voca/configuration.rb +23 -0
- data/lib/decidim/voca/content_block_setting_manifest.rb +67 -0
- data/lib/decidim/voca/content_block_translated_settings_machine_translation.rb +100 -0
- data/lib/decidim/voca/deepl/deepl_active_job_context.rb +27 -0
- data/lib/decidim/voca/deepl/deepl_context.rb +78 -0
- data/lib/decidim/voca/deepl/deepl_form_builder_overrides.rb +82 -0
- data/lib/decidim/voca/deepl/deepl_machine_translator.rb +61 -0
- data/lib/decidim/voca/deepl/deepl_middleware.rb +83 -0
- data/lib/decidim/voca/deepl/engine_config.rb +179 -0
- data/lib/decidim/voca/deepl/translation_bar_overrides.rb +20 -0
- data/lib/decidim/voca/deepl.rb +9 -0
- data/lib/decidim/voca/engine.rb +318 -11
- data/lib/decidim/voca/export/comment_serializer_localized_csv.rb +34 -0
- data/lib/decidim/voca/export/csv_with_locale_transformer.rb +53 -0
- data/lib/decidim/voca/export/proposal_serializer_localized_csv.rb +45 -0
- data/lib/decidim/voca/export/user_answers_serializer_localized_csv.rb +54 -0
- data/lib/decidim/voca/good_job_settings.rb +74 -0
- data/lib/decidim/voca/installation.rb +33 -0
- data/lib/decidim/voca/machine_translation/translate_string.rb +121 -0
- data/lib/decidim/voca/machine_translation_human_source.rb +29 -0
- data/lib/decidim/voca/machine_translation_resource_job_voca.rb +65 -0
- data/lib/decidim/voca/organization_voca_extensions.rb +31 -0
- data/lib/decidim/voca/overrides/csv_export_serializers.rb +51 -0
- data/lib/decidim/voca/overrides/meetings/dates_and_map_cell_overrides.rb +20 -0
- data/lib/decidim/voca/overrides/menu_breadcrumb_last_activity_cache.rb +31 -0
- data/lib/decidim/voca/overrides/mod_secure/conversation_controller_overrides.rb +19 -0
- data/lib/decidim/voca/overrides/mod_secure/conversation_sanitize.rb +29 -0
- data/lib/decidim/voca/overrides/mod_secure/conversation_uuid.rb +34 -0
- data/lib/decidim/voca/overrides/mod_secure/user_conversations_redirect_overrides.rb +53 -0
- data/lib/decidim/voca/overrides/mod_secure/user_profile_verification_override.rb +31 -0
- data/lib/decidim/voca/overrides/newsletter_helper_overrides.rb +30 -0
- data/lib/decidim/voca/overrides/resource_presenter_overrides.rb +30 -0
- data/lib/decidim/voca/overrides/sanitize_helper_overrides.rb +39 -0
- data/lib/decidim/voca/sync_locales/README.md +13 -0
- data/lib/decidim/voca/sync_locales/awesome_menu_label_sync.rb +89 -0
- data/lib/decidim/voca/sync_locales/command.rb +54 -0
- data/lib/decidim/voca/sync_locales/component_setting_sync.rb +72 -0
- data/lib/decidim/voca/sync_locales/content_block_setting_sync.rb +86 -0
- data/lib/decidim/voca/sync_locales/field_hash_normalizer.rb +98 -0
- data/lib/decidim/voca/sync_locales/locale_context.rb +589 -0
- data/lib/decidim/voca/sync_locales/machine_translation_enqueuer.rb +60 -0
- data/lib/decidim/voca/sync_locales/relation_lint_runner.rb +55 -0
- data/lib/decidim/voca/sync_locales/runner.rb +352 -0
- data/lib/decidim/voca/sync_locales.rb +11 -0
- data/lib/decidim/voca/update_column_without_callbacks.rb +21 -0
- data/lib/decidim/voca/version.rb +13 -3
- data/lib/decidim/voca.rb +42 -13
- data/lib/decidim-voca.rb +5 -0
- data/lib/tasks/decidim/voca/voca_anonymize.rake +41 -0
- data/lib/tasks/decidim/voca/voca_clean_machine_translations.rake +22 -0
- data/lib/tasks/decidim/voca/voca_enhanced_invalid_record.rake +141 -0
- data/lib/tasks/decidim/voca/voca_install_migration.rake +45 -0
- data/lib/tasks/decidim/voca/voca_relation_lint.rake +12 -0
- data/lib/tasks/decidim/voca/voca_sync_locales.rake +10 -0
- data/lib/tasks/decidim/voca/voca_upgrade.rake +13 -0
- data/lib/tasks/decidim/voca/voca_webpacker.rake +58 -0
- metadata +248 -55
- data/app/assets/config/voca_manifest.js +0 -0
- data/app/assets/images/decidim/voca/icon.svg +0 -1
- data/app/commands/decidim/voca/organization/command.rb +0 -16
- data/app/commands/decidim/voca/organization/organization_command.rb +0 -17
- data/app/commands/decidim/voca/organization/update_color_command.rb +0 -35
- data/app/commands/decidim/voca/organization/update_environment_command.rb +0 -23
- data/app/commands/decidim/voca/organization/update_feature_command.rb +0 -32
- data/app/commands/decidim/voca/organization/update_file_upload_command.rb +0 -45
- data/app/commands/decidim/voca/organization/update_locale_command.rb +0 -53
- data/app/commands/decidim/voca/organization/update_naming_command.rb +0 -30
- data/app/commands/decidim/voca/organization/update_permission_command.rb +0 -31
- data/app/commands/decidim/voca/organization/update_smtp_command.rb +0 -51
- data/app/jobs/decidim/voca/command_job.rb +0 -36
- data/app/jobs/decidim/voca/webhook_notifier_job.rb +0 -57
- data/app/rpc/decidim/voca/decidim_service_controller.rb +0 -68
- data/app/rpc/decidim/voca/rpc/enum_casting.rb +0 -58
- data/app/rpc/decidim/voca/rpc/get_settings.rb +0 -144
- data/app/rpc/decidim/voca/rpc/health.rb +0 -18
- data/app/rpc/decidim/voca/rpc/seed_admin.rb +0 -75
- data/app/rpc/decidim/voca/rpc/set_settings.rb +0 -56
- data/app/rpc/decidim/voca/rpc/setup_db.rb +0 -38
- data/config/environments/development.rb +0 -6
- data/config/spring.rb +0 -2
- data/lib/decidim/voca/admin.rb +0 -10
- data/lib/decidim/voca/admin_engine.rb +0 -27
- data/lib/decidim/voca/backup/app_backup.rb +0 -169
- data/lib/decidim/voca/backup/app_decrypt_backup_file.rb +0 -50
- data/lib/decidim/voca/backup/app_encrypt_backup_file.rb +0 -49
- data/lib/decidim/voca/backup/app_upload_to_s3.rb +0 -49
- data/lib/decidim/voca/middleware/dynamic_config_middleware.rb +0 -42
- data/lib/decidim/voca/rpc/decidim_pb.rb +0 -134
- data/lib/decidim/voca/rpc/decidim_services_pb.rb +0 -30
- data/lib/decidim/voca/test/factories.rb +0 -9
- data/lib/decidim/voca/updater.rb +0 -50
- data/lib/tasks/voca.rake +0 -88
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "nokogiri"
|
|
4
|
+
|
|
5
|
+
module Decidim
|
|
6
|
+
module Voca
|
|
7
|
+
module MachineTranslation
|
|
8
|
+
# Shared string translation for MT paths that cannot use +MachineTranslationSaveJob+ (no DB column).
|
|
9
|
+
module TranslateString
|
|
10
|
+
class << self
|
|
11
|
+
def call(text:, source_locale:, target_locale:, html: false, context: nil)
|
|
12
|
+
klass = Decidim.machine_translation_service_klass
|
|
13
|
+
return nil if klass.blank?
|
|
14
|
+
return "" if text.blank?
|
|
15
|
+
|
|
16
|
+
work = text.dup
|
|
17
|
+
work.gsub!(Regexp.new(%q(<img\s+src="data:image/png;base64,[^"]*"\s*/?>), Regexp::IGNORECASE), "")
|
|
18
|
+
|
|
19
|
+
return dummy_dev_translation(work, target_locale) if klass.to_s == "Decidim::Dev::DummyTranslator"
|
|
20
|
+
|
|
21
|
+
return dummy_deepl_style_translation(work, target_locale, html) if dummy_translate?
|
|
22
|
+
|
|
23
|
+
return nil unless translatable?(work)
|
|
24
|
+
return nil unless deepl_service?(klass)
|
|
25
|
+
|
|
26
|
+
segmented_translate(work, source_locale.to_s, target_locale.to_s, html:, context:)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def dummy_translate?
|
|
30
|
+
%w(1 true enabled).include?(ENV.fetch("VOCA_DUMMY_TRANSLATE", "false"))
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def deepl_service?(klass)
|
|
34
|
+
klass.to_s == "Decidim::Voca::DeepL::MachineTranslator"
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def translatable?(text)
|
|
38
|
+
text.present? && text.bytesize < 131_000
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def mutex
|
|
42
|
+
@mutex ||= Mutex.new
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def dummy_dev_translation(work, target_locale)
|
|
46
|
+
"#{target_locale} - #{work}"
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def dummy_deepl_style_translation(work, _target_locale, html)
|
|
50
|
+
ctx = deepl_context_base
|
|
51
|
+
str = "DUMMY TRANSLATION [date=#{Time.current.strftime("%d/%m/%Y %H:%M:%S")},mode=#{html ? "html" : "text"},text_to_translate=\"#{work}\",context=\"#{ctx}\"]"
|
|
52
|
+
str = "<p><strong>#{str}</strong></p>" if html
|
|
53
|
+
str.html_safe
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def segmented_translate(text, source_locale, target_locale, html:, context:)
|
|
57
|
+
return deepl_translate_segment(text, source_locale, target_locale, html: false, context:) unless html
|
|
58
|
+
|
|
59
|
+
fragment = Nokogiri::HTML.fragment(text)
|
|
60
|
+
fragment.children.each do |node|
|
|
61
|
+
if node.inner_html.present?
|
|
62
|
+
node.inner_html = deepl_translate_segment(node.inner_html, source_locale, target_locale, html: true, context:)
|
|
63
|
+
else
|
|
64
|
+
node.content = deepl_translate_segment(node.content, source_locale, target_locale, html: false, context:)
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
fragment.to_s
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def deepl_translate_segment(text, source_locale, target_locale, html:, context:)
|
|
71
|
+
return text unless translatable?(text)
|
|
72
|
+
return dummy_deepl_style_translation(text, target_locale, html) if dummy_translate?
|
|
73
|
+
|
|
74
|
+
return text unless defined?(::DeepL)
|
|
75
|
+
|
|
76
|
+
mutex.synchronize do
|
|
77
|
+
result = ::DeepL.translate(
|
|
78
|
+
text,
|
|
79
|
+
source_locale,
|
|
80
|
+
target_locale,
|
|
81
|
+
context: full_context(context),
|
|
82
|
+
**deepl_kwargs(target_locale, html:)
|
|
83
|
+
)
|
|
84
|
+
result.text
|
|
85
|
+
rescue StandardError => e
|
|
86
|
+
Rails.logger.error("Voca TranslateString: #{e.message}")
|
|
87
|
+
raise e
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def full_context(context)
|
|
92
|
+
base = deepl_context_base
|
|
93
|
+
[context, base].compact.join(" ")
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def deepl_context_base
|
|
97
|
+
return "" unless Decidim::Voca.const_defined?(:DeepL)
|
|
98
|
+
|
|
99
|
+
Decidim::Voca::DeepL::Context.deepl_context
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def deepl_kwargs(target_locale, html:)
|
|
103
|
+
kwargs = {}
|
|
104
|
+
kwargs[:formality] = "prefer_more" if supports_formality?(target_locale)
|
|
105
|
+
kwargs[:tag_handling] = "html" if html
|
|
106
|
+
kwargs
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def supports_formality?(target_locale)
|
|
110
|
+
return false unless defined?(::DeepL)
|
|
111
|
+
|
|
112
|
+
lang = ::DeepL.languages.find { |locale| locale.code == target_locale.to_s.upcase }
|
|
113
|
+
lang&.supports_formality?
|
|
114
|
+
rescue ::DeepL::Exceptions::NotSupported, NameError
|
|
115
|
+
false
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module Voca
|
|
5
|
+
# Resolves which locale key holds human text for +MachineTranslationResourceJobVoca+ when
|
|
6
|
+
# minimalistic mode treats the default locale as authoritative but that slot is empty
|
|
7
|
+
# (e.g. participant wrote only in +I18n.locale+).
|
|
8
|
+
module MachineTranslationHumanSource
|
|
9
|
+
module_function
|
|
10
|
+
|
|
11
|
+
# @param organization [Decidim::Organization]
|
|
12
|
+
# @param field_hash [Hash] new value for a translatable JSONB field
|
|
13
|
+
# @param job_source_locale [String] +I18n.locale+ passed into the resource job
|
|
14
|
+
# @return [String, nil] locale string to read source text from, or nil if none
|
|
15
|
+
def authoring_locale(organization, field_hash, job_source_locale)
|
|
16
|
+
return nil unless organization && field_hash.is_a?(Hash)
|
|
17
|
+
|
|
18
|
+
h = field_hash.stringify_keys
|
|
19
|
+
dl = organization.default_locale.to_s
|
|
20
|
+
return dl if h[dl].presence
|
|
21
|
+
|
|
22
|
+
job_loc = job_source_locale.to_s
|
|
23
|
+
return job_loc if job_loc.present? && h[job_loc].presence
|
|
24
|
+
|
|
25
|
+
organization.available_locales.map(&:to_s).find { |loc| h[loc].presence }
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "machine_translation_human_source"
|
|
4
|
+
|
|
5
|
+
module Decidim
|
|
6
|
+
module Voca
|
|
7
|
+
# Under minimalistic Deepl, core Decidim treats any present locale as "already translated",
|
|
8
|
+
# which skips MT. This prepended module narrows +translated_locales_list+ so only the
|
|
9
|
+
# organization default blocks +pending_locales+ when the default slot has human text.
|
|
10
|
+
#
|
|
11
|
+
# When the default slot is empty but another locale has content (typical participant UI in
|
|
12
|
+
# a non-default language), we delegate +translated_locales_list+ to core and resolve
|
|
13
|
+
# +resource_field_value+ from the job's +source_locale+ (+I18n.locale+) or the first filled
|
|
14
|
+
# locale in +organization.available_locales+ order — see +MachineTranslationHumanSource+.
|
|
15
|
+
module MachineTranslationResourceJobVoca
|
|
16
|
+
def resource_field_value(previous_changes, field, source_locale)
|
|
17
|
+
if voca_minimalistic_pending_locales_mode?
|
|
18
|
+
values = previous_changes[field]
|
|
19
|
+
new_value = values&.last
|
|
20
|
+
if new_value.is_a?(Hash) && @resource.respond_to?(:organization) && @resource.organization
|
|
21
|
+
org = @resource.organization
|
|
22
|
+
dl = default_locale(@resource)
|
|
23
|
+
if new_value.stringify_keys[dl].presence
|
|
24
|
+
source_locale = dl
|
|
25
|
+
else
|
|
26
|
+
resolved = MachineTranslationHumanSource.authoring_locale(org, new_value, source_locale)
|
|
27
|
+
source_locale = resolved if resolved.present?
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
super
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def translated_locales_list(field)
|
|
35
|
+
if voca_minimalistic_pending_locales_mode?
|
|
36
|
+
dl = default_locale(@resource)
|
|
37
|
+
hash = @resource[field]
|
|
38
|
+
return super unless hash.is_a?(Hash)
|
|
39
|
+
|
|
40
|
+
value = hash[dl].presence || hash[dl.to_sym].presence
|
|
41
|
+
return super if value.blank?
|
|
42
|
+
|
|
43
|
+
[dl]
|
|
44
|
+
else
|
|
45
|
+
super
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
private
|
|
50
|
+
|
|
51
|
+
def voca_minimalistic_pending_locales_mode?
|
|
52
|
+
return false unless org
|
|
53
|
+
return false unless org.minimalistic_deepl?
|
|
54
|
+
|
|
55
|
+
org.enable_machine_translations?
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def org
|
|
59
|
+
return false unless @resource.respond_to?(:organization)
|
|
60
|
+
|
|
61
|
+
@org ||= @resource.organization
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module Voca
|
|
5
|
+
module OrganizationVocaExtensions
|
|
6
|
+
extend ActiveSupport::Concern
|
|
7
|
+
|
|
8
|
+
included do
|
|
9
|
+
def voca_features_toggle
|
|
10
|
+
@voca_features_toggle ||= Decidim::Toggle.config_for(self, Decidim::Voca::MODULE_NAME)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def deepl_enabled?
|
|
14
|
+
voca_features_toggle["deepl_enabled"]
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def minimalistic_deepl?
|
|
18
|
+
voca_features_toggle["minimalistic_deepl_enabled"]
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def weglot?
|
|
22
|
+
voca_features_toggle["weglot_enabled"]
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def weglot_cache?
|
|
26
|
+
voca_features_toggle["weglot_cache"]
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module Voca
|
|
5
|
+
module Overrides
|
|
6
|
+
# Prepends voca multi-locale CSV export behaviour on Decidim serializers.
|
|
7
|
+
module ProposalSerializerCsvExport
|
|
8
|
+
module_function
|
|
9
|
+
|
|
10
|
+
def apply
|
|
11
|
+
mod = Decidim::Voca::Export::ProposalSerializerLocalizedCsv
|
|
12
|
+
return if Decidim::Proposals::ProposalSerializer.ancestors.include?(mod)
|
|
13
|
+
|
|
14
|
+
Decidim::Proposals::ProposalSerializer.prepend(mod)
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
module CommentSerializerOverride
|
|
19
|
+
module_function
|
|
20
|
+
|
|
21
|
+
def apply
|
|
22
|
+
mod = Decidim::Voca::Export::CommentSerializerLocalizedCsv
|
|
23
|
+
return if Decidim::Comments::CommentSerializer.ancestors.include?(mod)
|
|
24
|
+
|
|
25
|
+
Decidim::Comments::CommentSerializer.prepend(mod)
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
module UserAnswersSerializerOverride
|
|
30
|
+
module_function
|
|
31
|
+
|
|
32
|
+
def apply
|
|
33
|
+
mod = Decidim::Voca::Export::UserAnswersSerializerLocalizedCsv
|
|
34
|
+
return if Decidim::Forms::UserResponsesSerializer.ancestors.include?(mod)
|
|
35
|
+
|
|
36
|
+
Decidim::Forms::UserResponsesSerializer.prepend(mod)
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
module CsvExportSerializers
|
|
41
|
+
module_function
|
|
42
|
+
|
|
43
|
+
def apply
|
|
44
|
+
ProposalSerializerCsvExport.apply
|
|
45
|
+
CommentSerializerOverride.apply
|
|
46
|
+
UserAnswersSerializerOverride.apply
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module Voca
|
|
5
|
+
module Overrides
|
|
6
|
+
module Meetings
|
|
7
|
+
module DatesAndMapCellOverrides
|
|
8
|
+
extend ActiveSupport::Concern
|
|
9
|
+
|
|
10
|
+
included do
|
|
11
|
+
alias_method :voca_show_original, :show
|
|
12
|
+
def show
|
|
13
|
+
render :show_overrides
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module Voca
|
|
5
|
+
module Overrides
|
|
6
|
+
# Time-bucketed fragment key so ActionLog is not queried before the cache read.
|
|
7
|
+
module MenuBreadcrumbLastActivityCache
|
|
8
|
+
private
|
|
9
|
+
|
|
10
|
+
def cache_hash
|
|
11
|
+
[
|
|
12
|
+
"decidim/content_blocks/menu_breadcrumb_last_activity",
|
|
13
|
+
id_prefix,
|
|
14
|
+
model.cache_key_with_version,
|
|
15
|
+
I18n.locale.to_s,
|
|
16
|
+
minute_bucket,
|
|
17
|
+
visitor_cache_key
|
|
18
|
+
].join(Decidim.cache_key_separator)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def minute_bucket
|
|
22
|
+
(Time.current.to_i / 60).to_s
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def visitor_cache_key
|
|
26
|
+
current_user&.cache_key_with_version || "anonymous"
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module Voca
|
|
5
|
+
module Overrides
|
|
6
|
+
module ConversationControllerOverrides
|
|
7
|
+
extend ActiveSupport::Concern
|
|
8
|
+
|
|
9
|
+
included do
|
|
10
|
+
def conversation
|
|
11
|
+
@conversation ||= Decidim::Messaging::Conversation.find_by(
|
|
12
|
+
decidim_voca_conversation_uuids: { uuid: params[:id] }
|
|
13
|
+
)
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module Voca
|
|
5
|
+
module Overrides
|
|
6
|
+
module ConversationSanitize
|
|
7
|
+
extend ActiveSupport::Concern
|
|
8
|
+
|
|
9
|
+
included do |_base|
|
|
10
|
+
include ::Decidim::SanitizeHelper
|
|
11
|
+
|
|
12
|
+
if respond_to?(:before_validation)
|
|
13
|
+
# When included in a ActiveRecord
|
|
14
|
+
before_validation :voca_sanitize_body
|
|
15
|
+
elsif respond_to?(:validate)
|
|
16
|
+
# When included in ActiveModel
|
|
17
|
+
validate :voca_sanitize_body
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
private
|
|
21
|
+
|
|
22
|
+
def voca_sanitize_body
|
|
23
|
+
self.body = decidim_sanitize(body, strip_tags: true) unless body.empty?
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module Voca
|
|
5
|
+
module Overrides
|
|
6
|
+
# Injected into Decidim::Messaging::Conversation model to generate a UUID for the conversation
|
|
7
|
+
module ConversationUuid
|
|
8
|
+
extend ActiveSupport::Concern
|
|
9
|
+
|
|
10
|
+
included do
|
|
11
|
+
has_one :conversation_uuid,
|
|
12
|
+
class_name: "Decidim::Voca::ConversationUuid",
|
|
13
|
+
foreign_key: :decidim_conversation_id,
|
|
14
|
+
autosave: true,
|
|
15
|
+
inverse_of: :conversation
|
|
16
|
+
default_scope { joins(:conversation_uuid).order(updated_at: :desc) }
|
|
17
|
+
|
|
18
|
+
after_create :generate_uuid
|
|
19
|
+
delegate :uuid, to: :conversation_uuid, allow_nil: true
|
|
20
|
+
|
|
21
|
+
def to_param
|
|
22
|
+
uuid
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
private
|
|
26
|
+
|
|
27
|
+
def generate_uuid
|
|
28
|
+
self.conversation_uuid = Decidim::Voca::ConversationUuid.create(conversation: self)
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module Voca
|
|
5
|
+
module Overrides
|
|
6
|
+
# Decidim core redirects with +id: @conversation.id+; profile routes are constrained to UUIDs
|
|
7
|
+
# (+constraints(id: UUID_REGEXP)+ in {Decidim::Voca::Engine}). Use the public UUID segment so
|
|
8
|
+
# Location matches {ConversationControllerOverrides} (+params[:id]+ is the UUID).
|
|
9
|
+
module UserConversationsRedirectOverrides
|
|
10
|
+
extend ActiveSupport::Concern
|
|
11
|
+
|
|
12
|
+
prepended do
|
|
13
|
+
def new
|
|
14
|
+
@form = form(Messaging::ConversationForm).from_params(params, sender: user)
|
|
15
|
+
|
|
16
|
+
return redirect_back_or_to(profile_path(user.nickname)) if @form.recipient.empty?
|
|
17
|
+
|
|
18
|
+
@conversation = new_conversation(@form.recipient)
|
|
19
|
+
|
|
20
|
+
return redirect_to profile_conversation_path(nickname: user.nickname, id: @conversation.uuid) if @conversation.id
|
|
21
|
+
|
|
22
|
+
enforce_permission_to :create, :conversation, interlocutor: user, conversation: @conversation
|
|
23
|
+
|
|
24
|
+
render :show
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def create
|
|
28
|
+
@form = form(Messaging::ConversationForm).from_params(params, sender: user)
|
|
29
|
+
@conversation = new_conversation(@form.recipient)
|
|
30
|
+
|
|
31
|
+
enforce_permission_to :create, :conversation, interlocutor: user, conversation: @conversation
|
|
32
|
+
|
|
33
|
+
if @conversation.id
|
|
34
|
+
flash[:alert] = I18n.t("user_conversations.create.existing_error", scope: "decidim")
|
|
35
|
+
return redirect_to profile_conversation_path(nickname: user.nickname, id: @conversation.uuid)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
Messaging::StartConversation.call(@form) do
|
|
39
|
+
on(:ok) do |_conversation|
|
|
40
|
+
flash[:notice] = I18n.t("user_conversations.create.success", scope: "decidim")
|
|
41
|
+
return redirect_to profile_conversations_path(nickname: user.nickname)
|
|
42
|
+
end
|
|
43
|
+
on(:invalid) do
|
|
44
|
+
flash[:alert] = I18n.t("user_conversations.create.error", scope: "decidim")
|
|
45
|
+
render action: :show
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module Voca
|
|
5
|
+
module Overrides
|
|
6
|
+
module UserProfileVerificationOverride
|
|
7
|
+
extend ActiveSupport::Concern
|
|
8
|
+
|
|
9
|
+
included do
|
|
10
|
+
before_validation :voca_sanitize_name
|
|
11
|
+
before_validation :voca_sanitize_nickname
|
|
12
|
+
|
|
13
|
+
private
|
|
14
|
+
|
|
15
|
+
def voca_sanitize_string(string)
|
|
16
|
+
strip_regex = /[<>?%&\^*#@()\[\]=+:;"{}\\|\n\r]/m
|
|
17
|
+
ActionController::Base.helpers.strip_tags(string).gsub(strip_regex, "")
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def voca_sanitize_name
|
|
21
|
+
self.name = voca_sanitize_string(name) unless name.empty?
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def voca_sanitize_nickname
|
|
25
|
+
self.nickname = voca_sanitize_string(nickname).downcase unless nickname.empty?
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module Voca
|
|
5
|
+
module Overrides
|
|
6
|
+
module NewsletterHelperOverrides
|
|
7
|
+
extend ActiveSupport::Concern
|
|
8
|
+
|
|
9
|
+
included do
|
|
10
|
+
alias_method :original_transform_image_urls, :transform_image_urls
|
|
11
|
+
|
|
12
|
+
def transform_image_urls(content, host)
|
|
13
|
+
return content if host.blank?
|
|
14
|
+
|
|
15
|
+
content.scan(/src\s*=\s*"([^"]*)"/).each do |src|
|
|
16
|
+
url = src.first
|
|
17
|
+
|
|
18
|
+
next if url.start_with?("http://", "https://", "//")
|
|
19
|
+
|
|
20
|
+
root_url = decidim.root_url(host:)[0..-2]
|
|
21
|
+
src_replaced = "#{root_url}#{src.first}"
|
|
22
|
+
content = content.gsub(/src\s*=\s*"([^"]*#{src.first})"/, %(src="#{src_replaced}"))
|
|
23
|
+
end
|
|
24
|
+
content
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module Voca
|
|
5
|
+
module Overrides
|
|
6
|
+
module ResourcePresenterOverrides
|
|
7
|
+
extend ActiveSupport::Concern
|
|
8
|
+
|
|
9
|
+
included do
|
|
10
|
+
# Alias the original mail method
|
|
11
|
+
alias_method :original_editor_locales, :editor_locales
|
|
12
|
+
|
|
13
|
+
private
|
|
14
|
+
|
|
15
|
+
# Prepares the HTML content for the editors with the correct tags included
|
|
16
|
+
# to identify the hashtags and mentions.
|
|
17
|
+
# Overrides it to include Decidim::ContentRenderers::BlobRenderer in the
|
|
18
|
+
# renderer array to properly render files and images in the Meetings editor.
|
|
19
|
+
def editor_locales(data, all_locales)
|
|
20
|
+
data = original_editor_locales(data, all_locales)
|
|
21
|
+
handle_locales(data, all_locales) do |content|
|
|
22
|
+
renderer = Decidim::ContentRenderers::BlobRenderer.new(content)
|
|
23
|
+
renderer.render(links: false, editor: true).html_safe
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "decidim/meetings"
|
|
4
|
+
|
|
5
|
+
module Decidim
|
|
6
|
+
module Voca
|
|
7
|
+
module Overrides
|
|
8
|
+
module SanitizeHelperOverrides
|
|
9
|
+
extend ActiveSupport::Concern
|
|
10
|
+
|
|
11
|
+
included do
|
|
12
|
+
# Alias the original mail method
|
|
13
|
+
alias_method :original_content_handle_locale, :content_handle_locale
|
|
14
|
+
alias_method :original_render_sanitized_content, :render_sanitized_content
|
|
15
|
+
|
|
16
|
+
private
|
|
17
|
+
|
|
18
|
+
# Overrides it to include Decidim::ContentRenderers::BlobRenderer in the
|
|
19
|
+
# renderer to properly render files and images in the Meetings show view.
|
|
20
|
+
def content_handle_locale(body, all_locales, links, strip_tags)
|
|
21
|
+
body = original_content_handle_locale(body, all_locales, links, strip_tags)
|
|
22
|
+
handle_locales(body, all_locales) do |content|
|
|
23
|
+
Decidim::ContentRenderers::BlobRenderer.new(content).render.html_safe
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# Overrides it to render safe content in the the Meetings show view.
|
|
28
|
+
def render_sanitized_content(resource, method, presenter_class: nil)
|
|
29
|
+
content = present(resource, presenter_class:).send(method, links: true, strip_tags: !try(:safe_content?))
|
|
30
|
+
|
|
31
|
+
return decidim_sanitize_editor_admin(content, {}) if try(:safe_content_admin?)
|
|
32
|
+
|
|
33
|
+
try(:safe_content?) ? content : decidim_sanitize(content, {})
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Sync Command
|
|
2
|
+
This folder includes the script for the rake task `decidim:voca:sync_locales`.
|
|
3
|
+
|
|
4
|
+
```
|
|
5
|
+
.
|
|
6
|
+
├── command.rb # Execute the runner, wrapping rebuild search before and after execution
|
|
7
|
+
└── runner.rb # Identifies all models that can be translated and run a normalization on translatable fields, and a new machine translation job if needed.
|
|
8
|
+
├── field_hash_normalizer.rb # normalize the hash to be sure "root" key is only default locale, and all the rest is machine-translated. Clean locales that are not available anymore.
|
|
9
|
+
├── machine_translation_enqueuer.rb # Enqueue a machine translation job for all the missing locales.
|
|
10
|
+
├── component_setting_sync.rb # For Decidim::Component only: normalize translated *global* settings JSON and enqueue Decidim::Voca::MachineTranslateComponentSettingJob (nested JSONB, not a DB column).
|
|
11
|
+
├── locale_context.rb # Find the organization linked to a resource
|
|
12
|
+
```
|
|
13
|
+
|