lesli_babel 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. checksums.yaml +7 -0
  2. data/Rakefile +5 -0
  3. data/app/assets/config/lesli_babel_manifest.js +7 -0
  4. data/app/assets/images/lesli_babel/babel-logo.svg +157 -0
  5. data/app/assets/javascripts/lesli_babel/application.js +3288 -0
  6. data/app/assets/stylesheets/lesli_babel/application.scss +41 -0
  7. data/app/assets/stylesheets/lesli_babel/dashboards.scss +55 -0
  8. data/app/assets/stylesheets/lesli_babel/modules.scss +33 -0
  9. data/app/assets/stylesheets/lesli_babel/translations.scss +58 -0
  10. data/app/controllers/lesli_babel/application_controller.rb +37 -0
  11. data/app/controllers/lesli_babel/buckets_controller.rb +79 -0
  12. data/app/controllers/lesli_babel/clones_controller.rb +80 -0
  13. data/app/controllers/lesli_babel/dashboards_controller.rb +38 -0
  14. data/app/controllers/lesli_babel/modules_controller.rb +91 -0
  15. data/app/controllers/lesli_babel/relevants_controller.rb +38 -0
  16. data/app/controllers/lesli_babel/strings_controller.rb +142 -0
  17. data/app/controllers/lesli_babel/translations_controller.rb +134 -0
  18. data/app/jobs/lesli_babel/application_job.rb +7 -0
  19. data/app/mailers/lesli_babel/application_mailer.rb +6 -0
  20. data/app/models/lesli_babel/application_record.rb +36 -0
  21. data/app/models/lesli_babel/bucket.rb +6 -0
  22. data/app/models/lesli_babel/clone.rb +24 -0
  23. data/app/models/lesli_babel/dashboard.rb +35 -0
  24. data/app/models/lesli_babel/module.rb +35 -0
  25. data/app/models/lesli_babel/relevant.rb +21 -0
  26. data/app/models/lesli_babel/string/activity.rb +5 -0
  27. data/app/models/lesli_babel/string/discussion.rb +68 -0
  28. data/app/models/lesli_babel/string.rb +225 -0
  29. data/app/models/lesli_babel/translation.rb +5 -0
  30. data/app/services/lesli_babel/module_service.rb +18 -0
  31. data/app/services/lesli_babel/old/translations_android_service.rb +82 -0
  32. data/app/services/lesli_babel/old/translations_clone_service.rb +161 -0
  33. data/app/services/lesli_babel/old/translations_flutter_service.rb +102 -0
  34. data/app/services/lesli_babel/old/translations_ios_service.rb +119 -0
  35. data/app/services/lesli_babel/old/translations_js_service.rb +114 -0
  36. data/app/services/lesli_babel/old/translations_middleman_service.rb +77 -0
  37. data/app/services/lesli_babel/old/translations_rails_service.rb +119 -0
  38. data/app/services/lesli_babel/old/translations_service.rb +97 -0
  39. data/app/services/lesli_babel/old/translations_synchronization_service.rb +215 -0
  40. data/app/services/lesli_babel/string_service.rb +80 -0
  41. data/app/views/lesli_babel/buckets/_form.html.erb +17 -0
  42. data/app/views/lesli_babel/buckets/edit.html.erb +6 -0
  43. data/app/views/lesli_babel/buckets/index.html.erb +25 -0
  44. data/app/views/lesli_babel/buckets/new.html.erb +5 -0
  45. data/app/views/lesli_babel/buckets/show.html.erb +4 -0
  46. data/app/views/lesli_babel/clones/_form.html.erb +19 -0
  47. data/app/views/lesli_babel/clones/edit.html.erb +20 -0
  48. data/app/views/lesli_babel/clones/index.html.erb +20 -0
  49. data/app/views/lesli_babel/clones/new.html.erb +20 -0
  50. data/app/views/lesli_babel/clones/show.html.erb +20 -0
  51. data/app/views/lesli_babel/dashboards/show.html.erb +1 -0
  52. data/app/views/lesli_babel/dashboards/stats..html.erb +1 -0
  53. data/app/views/lesli_babel/modules/_form.html.erb +17 -0
  54. data/app/views/lesli_babel/modules/edit.html.erb +1 -0
  55. data/app/views/lesli_babel/modules/index.html.erb +1 -0
  56. data/app/views/lesli_babel/modules/new.html.erb +1 -0
  57. data/app/views/lesli_babel/modules/show.html.erb +1 -0
  58. data/app/views/lesli_babel/partials/_engine-navigation.html.erb +37 -0
  59. data/app/views/lesli_babel/partials/_engine-sidebar.html.erb +45 -0
  60. data/app/views/lesli_babel/relevants/edit.html.erb +20 -0
  61. data/app/views/lesli_babel/relevants/index.html.erb +21 -0
  62. data/app/views/lesli_babel/relevants/new.html.erb +20 -0
  63. data/app/views/lesli_babel/relevants/show.html.erb +20 -0
  64. data/app/views/lesli_babel/string/activities/_form.html.erb +17 -0
  65. data/app/views/lesli_babel/string/activities/edit.html.erb +6 -0
  66. data/app/views/lesli_babel/string/activities/index.html.erb +25 -0
  67. data/app/views/lesli_babel/string/activities/new.html.erb +5 -0
  68. data/app/views/lesli_babel/string/activities/show.html.erb +4 -0
  69. data/app/views/lesli_babel/string/discussions/_form.html.erb +17 -0
  70. data/app/views/lesli_babel/string/discussions/edit.html.erb +6 -0
  71. data/app/views/lesli_babel/string/discussions/index.html.erb +25 -0
  72. data/app/views/lesli_babel/string/discussions/new.html.erb +5 -0
  73. data/app/views/lesli_babel/string/discussions/show.html.erb +4 -0
  74. data/app/views/lesli_babel/strings/_form.html.erb +17 -0
  75. data/app/views/lesli_babel/strings/edit.html.erb +6 -0
  76. data/app/views/lesli_babel/strings/index.html.erb +25 -0
  77. data/app/views/lesli_babel/strings/new.html.erb +5 -0
  78. data/app/views/lesli_babel/strings/show.html.erb +4 -0
  79. data/app/views/lesli_babel/translations/_form.html.erb +17 -0
  80. data/app/views/lesli_babel/translations/edit.html.erb +6 -0
  81. data/app/views/lesli_babel/translations/index.html.erb +1 -0
  82. data/app/views/lesli_babel/translations/new.html.erb +5 -0
  83. data/app/views/lesli_babel/translations/show.html.erb +1 -0
  84. data/config/routes.rb +63 -0
  85. data/db/migrate/v1.0/0901100110_create_lesli_babel_modules.rb +42 -0
  86. data/db/migrate/v1.0/0901110110_create_lesli_babel_buckets.rb +43 -0
  87. data/db/migrate/v1.0/0901120110_create_lesli_babel_strings.rb +80 -0
  88. data/lib/lesli_babel/engine.rb +54 -0
  89. data/lib/lesli_babel/version.rb +3 -0
  90. data/lib/lesli_babel.rb +6 -0
  91. data/lib/tasks/lesli_babel_tasks.rake +121 -0
  92. data/lib/vue/application.js +46 -0
  93. data/lib/vue/apps/dashboards/show.vue +85 -0
  94. data/lib/vue/apps/modules/show.vue +97 -0
  95. data/lib/vue/apps/relevants/index.vue +47 -0
  96. data/lib/vue/apps/translations/index.vue +64 -0
  97. data/lib/vue/components/actions.vue +29 -0
  98. data/lib/vue/components/form-label-editor.vue +439 -0
  99. data/lib/vue/components/form-string-new.vue +171 -0
  100. data/lib/vue/stores/module.js +49 -0
  101. data/lib/vue/stores/statistics.js +42 -0
  102. data/lib/vue/stores/strings.js +141 -0
  103. data/lib/vue/stores/translations.js +73 -0
  104. data/license +674 -0
  105. data/readme.md +19 -0
  106. metadata +149 -0
@@ -0,0 +1,82 @@
1
+ module LesliBabel
2
+ class TranslationsAndroidService
3
+
4
+ def self.build(engine_id = nil)
5
+
6
+ translation_folder_path = Rails.root.join("public", "tmp", "locales")
7
+
8
+ # get all rails engines
9
+ engines = Module.where(:id => engine_id).map do |engine|
10
+ engine[:id]
11
+ end
12
+
13
+ # get strings filtered by module (only rails translations)
14
+ strings = TranslationsService.strings_for_apps(engines)
15
+
16
+ translations = {}
17
+
18
+ available_locales = Rails.application.config.lesli_settings["configuration"]["locales"]
19
+
20
+ strings.each do |string|
21
+
22
+ module_name = string[:engine_name].downcase.sub("cloud", "")
23
+ engine_name = string[:engine_name]
24
+ bucket_name = string[:bucket_name]
25
+ module_type = string[:platform]
26
+
27
+ available_locales.each do |lang|
28
+
29
+ file_path = translation_folder_path.join(
30
+ engine_name, "values-#{lang}", "#{ bucket_name.gsub("/","_") }.xml"
31
+ )
32
+
33
+ file_id = file_path.to_s
34
+
35
+ unless translations.has_key? file_id
36
+ translations[file_id] = []
37
+ end
38
+
39
+ # send debug message for missing translations
40
+ string[lang] = ":" + string.path + ":" if string[lang].blank?
41
+
42
+ translations[file_id].push({
43
+ label: string.label,
44
+ translation: string[lang]
45
+ })
46
+
47
+ end
48
+
49
+ end
50
+
51
+ translation_files = []
52
+
53
+ translations.each do |translation|
54
+
55
+ file_path = translation[0]
56
+ strings = translation[1]
57
+
58
+ translation_files.push(file_path)
59
+
60
+ # creates folder and subfolders
61
+ FileUtils.makedirs(File.dirname(file_path))
62
+
63
+ # creates translation file for every available language
64
+ translation_file = File.new(file_path, "w+")
65
+
66
+ translation_file.write("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n")
67
+ translation_file.write("<resources>\n")
68
+ strings.each do |string|
69
+ translation_file.write("<string name=\"#{string[:label]}\">#{string[:translation]}</string>\n")
70
+ end
71
+ translation_file.write("</resources>")
72
+
73
+ translation_file.close
74
+
75
+ end
76
+
77
+ LC::Response.service true, translation_files
78
+
79
+ end
80
+
81
+ end
82
+ end
@@ -0,0 +1,161 @@
1
+ =begin
2
+
3
+ Copyright (c) 2020, all rights reserved.
4
+
5
+ All the information provided by this platform is protected by international laws related to
6
+ industrial property, intellectual property, copyright and relative international laws.
7
+ All intellectual or industrial property rights of the code, texts, trade mark, design,
8
+ pictures and any other information belongs to the owner of this platform.
9
+
10
+ Without the written permission of the owner, any replication, modification,
11
+ transmission, publication is strictly forbidden.
12
+
13
+ For more information read the license file including with this software.
14
+
15
+ // · ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~
16
+ // ·
17
+
18
+ =end
19
+
20
+ module LesliBabel
21
+ class TranslationsCloneService
22
+
23
+
24
+ # IMPORTANT: This is a modified copy of the SynchronizationService
25
+ # please be careful modifying this file
26
+ def self.remote_clone instance_code=nil
27
+
28
+ instance_name = instance_code.camelize
29
+ instance_code = instance_code.gsub("_","-")
30
+
31
+
32
+ # synchronization server url
33
+ host = "http://localhost:8080"
34
+ host = "https://server.raven.dev.gt"
35
+
36
+
37
+ return LC::Response.service(false, "no valid instance code provided") if instance_code.blank?
38
+
39
+
40
+ api_endpoint = "#{host}/api/bucket/babel-#{instance_code}/documents"
41
+
42
+
43
+ # get last sync data
44
+ response = Faraday.get(api_endpoint+"?last=1")
45
+ response = FastJsonparser.parse(response.body)
46
+ response = response[:data][:documents][0]
47
+
48
+
49
+ # if first time sync
50
+ return LC::Response.service(false, "no strings found") if response.blank?
51
+
52
+
53
+ # add new modules
54
+ response[:modules].each do |babel_module|
55
+ next if babel_module[:name].blank?
56
+
57
+ # we do not want to clone strings from builder engines
58
+ next if babel_module[:name] == instance_name
59
+
60
+ platform = babel_module[:platform]
61
+ platform = "rails_engine" if babel_module[:name].start_with?("Cloud")
62
+ platform = "rails_core" if babel_module[:name] == "Core"
63
+
64
+ local_module = CloudBabel::Module
65
+ .create_with({
66
+ created_at: babel_module[:created_at],
67
+ platform: babel_module[:platform]
68
+ }).find_or_create_by({ name: babel_module[:name] })
69
+
70
+ local_module.platform = platform
71
+ local_module.updated_at = DateTime.now
72
+ local_module.save
73
+
74
+ end
75
+
76
+ # working with buckets
77
+ babel_reference_modules = {}
78
+
79
+ response[:buckets].each do |babel_bucket|
80
+
81
+ next if babel_bucket[:name].blank?
82
+
83
+ # we do not want to clone strings from builder engines
84
+ next if babel_bucket[:reference_module] == instance_name
85
+
86
+ # reference to modules that buckets belongs to
87
+ # this reference as string is necessary because the id of the module can change
88
+ # between synchronizations, thats why we search for the id of the module every time
89
+ if babel_reference_modules[babel_bucket[:reference_module]].blank?
90
+ babel_reference_modules[babel_bucket[:reference_module]] =
91
+ CloudBabel::Module.find_by(name: babel_bucket[:reference_module])
92
+ end
93
+
94
+ # add new bucket
95
+ CloudBabel::Bucket
96
+ .create_with({
97
+ created_at: babel_bucket[:created_at],
98
+ module: babel_reference_modules[babel_bucket[:reference_module]]
99
+ }).find_or_create_by({
100
+ name: babel_bucket[:name],
101
+ reference_module: babel_bucket[:reference_module]
102
+ })
103
+
104
+ end
105
+
106
+ # · working with strings
107
+ babel_reference_buckets = {}
108
+
109
+ response[:strings].each do |remote_string|
110
+ # reference to modules that buckets belongs to
111
+ # this reference as string is necessary because the id of the module or bucket can change
112
+ # between synchronizations, thats why we search for the id of the module every time
113
+ if babel_reference_buckets[remote_string[:reference_bucket]].blank?
114
+ remote_string[:reference_bucket] ||= remote_string[:reference_module_bucket]
115
+ babel_reference_buckets[remote_string[:reference_bucket]] =
116
+ CloudBabel::Bucket.find_by(
117
+ name: remote_string[:reference_bucket].split("-")[1],
118
+ reference_module: remote_string[:reference_bucket].split("-")[0]
119
+ )
120
+ end
121
+
122
+ # Do not sync labes that do not have a valid module and bucket reference
123
+ next if babel_reference_buckets[remote_string[:reference_bucket]].blank?
124
+
125
+ # we do not want to clone strings from builder engines
126
+ next if babel_reference_buckets[remote_string[:reference_bucket]].reference_module == instance_name
127
+
128
+ remote_string_reference = "#{babel_reference_buckets[remote_string[:reference_bucket]].reference_module}-#{babel_reference_buckets[remote_string[:reference_bucket]].name}"
129
+
130
+ # add new string if it does not exist
131
+ local_string = CloudBabel::String.with_deleted.create_with({
132
+ context: remote_string[:context],
133
+ es: remote_string[:es],
134
+ en: remote_string[:en],
135
+ de: remote_string[:de],
136
+ status: remote_string[:status],
137
+ need_help: remote_string[:need_help],
138
+ need_translation: remote_string[:need_translation],
139
+ last_update_context: remote_string[:last_update_context],
140
+ last_update_es: remote_string[:last_update_es],
141
+ last_update_en: remote_string[:last_update_en],
142
+ last_update_de: remote_string[:last_update_de],
143
+ last_update_fr: remote_string[:last_update_fr],
144
+ last_update_status: remote_string[:last_update_status],
145
+ created_at: remote_string[:created_at],
146
+ updated_at: remote_string[:updated_at],
147
+ deleted_at: remote_string[:deleted_at],
148
+ bucket: babel_reference_buckets[remote_string[:reference_bucket]]
149
+ }).find_or_create_by({
150
+ label: remote_string[:label],
151
+ reference_module_bucket: remote_string_reference
152
+ })
153
+
154
+ end
155
+
156
+ LC::Response.service true
157
+
158
+ end
159
+
160
+ end
161
+ end
@@ -0,0 +1,102 @@
1
+ module LesliBabel
2
+ class TranslationsFlutterService
3
+
4
+ def self.build(engine_id = nil)
5
+
6
+ # get all rails engines
7
+ engines = Module.where(:id => engine_id).map do |engine|
8
+ engine[:id]
9
+ end
10
+
11
+ # get strings filtered by module (only rails translations)
12
+ strings = TranslationsService.strings_for_apps(engines)
13
+
14
+ indexes = {}
15
+ translations = {}
16
+ available_locales = Rails.application.config.lesli_settings["configuration"]["locales"]
17
+
18
+ strings.each do |string|
19
+
20
+ module_name = string[:engine_name].downcase.sub("cloud", "")
21
+ engine_name = string[:engine_name]
22
+ bucket_name = string[:bucket_name]
23
+ module_type = string[:platform]
24
+
25
+ bucket_name_clean = bucket_name.gsub("/","_")
26
+
27
+ available_locales.each do |lang|
28
+
29
+ file_path = Rails.root.join(
30
+ "public", "tmp", "babel", "flutter","l10n", "app_#{lang}.arb"
31
+ )
32
+
33
+ file_id = file_path.to_s
34
+
35
+ unless translations.has_key? file_id
36
+ translations[file_id] = []
37
+ end
38
+
39
+ # send debug message for missing translations
40
+ string[lang] = ":" + string.path + ":" if string[lang].blank?
41
+
42
+ translations[file_id].push({
43
+ label: "#{bucket_name_clean}_#{string.label}".camelize(:lower),
44
+ translation: string[lang]
45
+ })
46
+
47
+ end
48
+
49
+ # Index keys
50
+ if not indexes.has_key? bucket_name_clean
51
+ indexes[bucket_name_clean] = []
52
+ end
53
+
54
+ indexes[bucket_name_clean].push({
55
+ k: string.label.camelize(:lower),
56
+ v: "#{bucket_name_clean}_#{string.label}".upcase
57
+ })
58
+
59
+ end
60
+
61
+ translation_files = []
62
+
63
+ # Create translations files for every available language
64
+ translations.each do |translation|
65
+
66
+ file_path = translation[0]
67
+ strings = translation[1]
68
+
69
+ translation_files.push(file_path)
70
+
71
+ # creates folder and subfolders
72
+ FileUtils.makedirs(File.dirname(file_path))
73
+
74
+ # creates translation file for every available language
75
+ translation_file = File.new(file_path, "w+")
76
+
77
+ # start the file with curlybraces as flutter requires
78
+ translation_file.write("{\n")
79
+
80
+ strings.each_with_index do |string,index|
81
+
82
+ # writes the key value translations
83
+ translation_file.write("\"#{string[:label]}\": \"#{string[:translation]}\"")
84
+
85
+ # add comma and new line if not last string
86
+ translation_file.write(",\n") if index != strings.size - 1
87
+
88
+ end
89
+
90
+ # ends the file with curlybraces
91
+ translation_file.write("}\n")
92
+
93
+ translation_file.close
94
+
95
+ end
96
+
97
+ LC::Response.service true, translation_files
98
+
99
+ end
100
+
101
+ end
102
+ end
@@ -0,0 +1,119 @@
1
+ module LesliBabel
2
+ class TranslationsIosService
3
+
4
+ def self.build(engine_id = nil)
5
+
6
+ # get all rails engines
7
+ engines = Module.where(:id => engine_id).map do |engine|
8
+ engine[:id]
9
+ end
10
+
11
+ # get strings filtered by module (only rails translations)
12
+ strings = TranslationsService.strings_for_apps(engines)
13
+
14
+ indexes = {}
15
+ translations = {}
16
+
17
+ available_locales = Rails.application.config.lesli_settings["configuration"]["locales"]
18
+
19
+ strings.each do |string|
20
+
21
+ module_name = string[:engine_name].downcase.sub("cloud", "")
22
+ engine_name = string[:engine_name]
23
+ bucket_name = string[:bucket_name]
24
+ module_type = string[:platform]
25
+ bucket_name_clean = bucket_name.gsub("/","_")
26
+
27
+ available_locales.each do |lang|
28
+
29
+ file_path = Rails.root.join(
30
+ "public", "tmp", "locales", engine_name, "Resources",
31
+ "#{lang}.lproj", "Localizable.strings"
32
+ )
33
+
34
+ file_id = file_path.to_s
35
+
36
+ unless translations.has_key? file_id
37
+ translations[file_id] = []
38
+ end
39
+
40
+ # send debug message for missing translations
41
+ string[lang] = ":" + string.path + ":" if string[lang].blank?
42
+
43
+ translations[file_id].push({
44
+ label: "#{bucket_name_clean}_#{string.label}".upcase,
45
+ translation: string[lang]
46
+ })
47
+
48
+ end
49
+
50
+ # Index keys
51
+ if not indexes.has_key? bucket_name_clean
52
+ indexes[bucket_name_clean] = []
53
+ end
54
+
55
+ indexes[bucket_name_clean].push({
56
+ k: string.label.camelize(:lower),
57
+ v: "#{bucket_name_clean}_#{string.label}".upcase
58
+ })
59
+
60
+ end
61
+
62
+ translation_files = []
63
+
64
+ # Create translations files for every available language
65
+ translations.each do |translation|
66
+
67
+ file_path = translation[0]
68
+ strings = translation[1]
69
+
70
+ translation_files.push(file_path)
71
+
72
+ # creates folder and subfolders
73
+ FileUtils.makedirs(File.dirname(file_path))
74
+
75
+ # creates translation file for every available language
76
+ translation_file = File.new(file_path, "w+")
77
+
78
+ strings.each do |string|
79
+ translation_file.write("\"#{string[:label]}\" = \"#{string[:translation]}\";\n")
80
+ end
81
+
82
+ translation_file.close
83
+
84
+ end
85
+
86
+ # Create global label index file
87
+ index_file_path = Rails.root.join("public", "tmp", "locales", "Translations.swift")
88
+
89
+ FileUtils.makedirs(File.dirname(index_file_path))
90
+
91
+ index_file = File.new(index_file_path, "w+")
92
+
93
+ index_file.write("\ enum Translations { \n")
94
+
95
+ indexes.each do |index_bucket|
96
+
97
+ index_file.write("\ enum #{index_bucket[0]} { \n")
98
+
99
+ index_bucket[1].each do |index_label|
100
+ index_file.write("static let #{index_label[:k]} = \"#{index_label[:v]}\"\n")
101
+ end
102
+
103
+ index_file.write("\ } \n")
104
+
105
+ end
106
+
107
+ index_file.write("\ } \n")
108
+
109
+ index_file.close
110
+
111
+ # include index into translation files zip
112
+ translation_files.push(index_file_path)
113
+
114
+ LC::Response.service true, translation_files
115
+
116
+ end
117
+
118
+ end
119
+ end
@@ -0,0 +1,114 @@
1
+ module LesliBabel
2
+ class TranslationsJsService
3
+
4
+ def self.build
5
+
6
+ # usually we download translations to use with other platforms like, flutter, reactnative, electron etc.
7
+ # so for these cases we need to include all the translations
8
+ engines = Module.all.map do |engine|
9
+ engine[:id]
10
+ end
11
+
12
+ # get strings filtered by module (only rails translations)
13
+ strings = TranslationsService.strings(engines)
14
+
15
+ strings = strings.select(
16
+ :id,
17
+ :label,
18
+ :status,
19
+ :context,
20
+ :priority,
21
+ :need_help,
22
+ :need_translation,
23
+ Rails.application.config.lesli_settings["configuration"]["locales"],
24
+ "cloud_babel_modules.id as engine_id",
25
+ "cloud_babel_buckets.id as bucket_id",
26
+ "cloud_babel_buckets.name as bucket_name",
27
+ "cloud_babel_modules.name as engine_name",
28
+ "cloud_babel_modules.platform as platform",
29
+ "'' as path"
30
+ )
31
+
32
+ translations = {}
33
+
34
+ available_locales = Rails.application.config.lesli_settings["configuration"]["locales"]
35
+
36
+ # add key for every available language (required by i18n Rails gem)
37
+ available_locales.each do |lang|
38
+ translations[lang] = { }
39
+ end
40
+
41
+ strings.each do |string|
42
+ module_name = string[:engine_name].downcase.sub("cloud", "")
43
+ engine_code = string[:engine_name].underscore
44
+ engine_name = string[:engine_name]
45
+ bucket_name = string[:bucket_name]
46
+ platform = string[:platform]
47
+
48
+ available_locales.each do |lang|
49
+
50
+ # translations path for lesli core
51
+ file_path = Rails.root.join("config", "locales", bucket_name, "#{ bucket_name.gsub("/","_") }.#{ lang }.js")
52
+
53
+ # translations path for translations for engines
54
+ file_path = Rails.root.join("public", "tmp", "locales", "#{lang}.json")
55
+
56
+ file_id = file_path.to_s.to_sym
57
+
58
+ unless translations[lang].has_key? file_id
59
+ translations[lang][file_id] = { }
60
+ end
61
+
62
+ unless translations[lang][file_id].has_key? module_name
63
+ translations[lang][file_id][module_name] = { }
64
+ end
65
+
66
+ unless translations[lang][file_id][module_name].has_key? bucket_name
67
+ translations[lang][file_id][module_name][bucket_name] = { }
68
+ end
69
+
70
+ # send debug message for missing translations
71
+ #string[lang] = ":" + string.path + ":" if string[lang].blank?
72
+
73
+ translations[lang][file_id][module_name][bucket_name][string.label] = string[lang]
74
+
75
+ end
76
+
77
+ end
78
+
79
+ translation_files = []
80
+
81
+ translations.each do |file_by_language|
82
+
83
+ lang = file_by_language[0]
84
+ file_by_controller = file_by_language[1]
85
+
86
+ file_by_controller.each do |file|
87
+
88
+ file_path = file[0].to_s
89
+ translations = file[1]
90
+
91
+ translation_files.push(file_path)
92
+
93
+ # creates folder and subfolders
94
+ FileUtils.makedirs(File.dirname(file_path))
95
+
96
+ # creates translation file for every available language
97
+ translation_file = File.new(file_path, "w+")
98
+
99
+ translation_file.write({ "#{lang}": translations}.to_json)
100
+
101
+ translation_file.close
102
+
103
+ p "file added: #{ file_path }"
104
+
105
+ end
106
+
107
+ end
108
+
109
+ LC::Response.service true, translation_files
110
+
111
+ end
112
+
113
+ end
114
+ end
@@ -0,0 +1,77 @@
1
+ module LesliBabel
2
+ class TranslationsMiddlemanService
3
+
4
+ def self.build(engine_id)
5
+
6
+ # get all rails engines
7
+ engines = Module.where(:id => engine_id).map(&:id)
8
+
9
+ # get strings filtered by module (only rails translations)
10
+ strings = TranslationsService.strings_for_apps(engines)
11
+
12
+ indexes = {}
13
+ translations = {}
14
+ available_locales = Rails.application.config.lesli_settings["configuration"]["locales"]
15
+
16
+ # add key for every available language (required by i18n Rails gem)
17
+ available_locales.each do |lang|
18
+ translations[lang] = { :path => '', :labels => {} }
19
+ end
20
+
21
+ strings.each do |string|
22
+
23
+ module_name = string[:engine_name].downcase.sub("cloud", "")
24
+ engine_name = string[:engine_name]
25
+ bucket_name = string[:bucket_name]
26
+ module_type = string[:platform]
27
+
28
+ bucket_name_clean = bucket_name.gsub("/","_")
29
+
30
+ available_locales.each do |lang|
31
+
32
+ file_path = Rails.root.join(
33
+ "public", "tmp", "babel", "middleman","locales", "#{lang}.yml"
34
+ )
35
+
36
+ translations[lang][:file] = file_path.to_s
37
+
38
+ unless translations[lang][:labels].has_key? bucket_name
39
+ translations[lang][:labels][bucket_name] = { }
40
+ end
41
+
42
+ # send debug message for missing translations
43
+ string[lang] = ":" + string.path + ":" if string[lang].blank?
44
+
45
+ translations[lang][:labels][bucket_name][string.label] = string[lang]
46
+
47
+ end
48
+
49
+ end
50
+
51
+ translation_files = []
52
+
53
+ # Create translations files for every available language
54
+ translations.each do |translation|
55
+
56
+ lang = translation[0]
57
+ file = translation[1][:file]
58
+ labels = translation[1][:labels]
59
+
60
+ translation_files.push(file)
61
+
62
+ # creates folder and subfolders
63
+ FileUtils.makedirs(File.dirname(file))
64
+
65
+ # creates translation file for every available language
66
+ translation_file = File.new(file, "w+")
67
+ translation_file.write({ "#{lang.to_s}": labels}.to_yaml)
68
+ translation_file.close
69
+
70
+ end
71
+
72
+ LC::Response.service true, translation_files
73
+
74
+ end
75
+
76
+ end
77
+ end