Skip to content

Commit a51657a

Browse files
committed
Modify db_fields hash in translation.rb config
This commit modifies how the templates-related tables ('templates', 'phases', 'sections', 'questions', 'annotations', and 'question_options') are queried within our customisation of the translation gem. All of those related tables are removed from config.db_fields. However, the tables (along with their previously specified columns) are now all included in the newly added Template ActiveRecord query (line 24). Rather than returning all of the db entries, this query only returns those that relate to the app's default_org. `'CallableQueries' => [templates_data_for_default_org_proc]` has been added to config.db_fields.`def templates_data_for_default_org_proc` returns a proc. This proc will be called within the translation gem, where it will execute the aforementioned Template ActiveRecord query. Finally, the returned entries will be uploaded to translation.io.
1 parent 965b0a6 commit a51657a

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

config/initializers/translation.rb

+17-7
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,21 @@ def ignore_paths
1717
Dir['**/'] - Dir['app/**/']
1818
end
1919

20+
def templates_data_for_default_org_proc
21+
proc do
22+
# Return all templates data pertaining to default_org
23+
Template.includes(phases: { sections: { questions: %i[annotations question_options] } })
24+
.where(org_id: Rails.application.secrets.default_funder_id)
25+
.pluck(:title, :description,
26+
'phases.title', 'phases.description',
27+
'sections.title', 'sections.description',
28+
'questions.text', 'questions.default_value',
29+
'annotations.text',
30+
'question_options.text')
31+
.flatten.uniq
32+
end
33+
end
34+
2035
TranslationIO.configure do |config|
2136
config.api_key = Rails.application.secrets.translation_io_api_key
2237
config.source_locale = 'en'
@@ -32,13 +47,8 @@ def ignore_paths
3247
config.db_fields = {
3348
'Theme' => %w[title description],
3449
'QuestionFormat' => %w[title description],
35-
'Template' => %w[title description],
36-
'Phase' => %w[title description],
37-
'Section' => %w[title description],
38-
'Question' => %w[text default_value],
39-
'Annotation' => ['text'],
40-
'ResearchDomain' => ['label'],
41-
'QuestionOption' => ['text']
50+
'ResearchDomain' => %w[label],
51+
'CallableQueries' => [templates_data_for_default_org_proc] # array elements are ActiveRecord query procs
4252
}
4353
# Find other useful usage information here:
4454
# https://github.com/translation/rails#readme

0 commit comments

Comments
 (0)