lesli_babel 0.4.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/javascripts/lesli_babel/application.js +1 -3726
- data/app/assets/stylesheets/lesli_babel/application.css +1 -0
- data/app/controllers/lesli_babel/clones_controller.rb +1 -1
- data/app/controllers/lesli_babel/relevants_controller.rb +1 -1
- data/app/models/lesli_babel/clone.rb +1 -1
- data/app/views/lesli_babel/partials/_engine-navigation.html.erb +2 -2
- data/lib/lesli_babel/version.rb +2 -2
- data/{app/assets/stylesheets/lesli_babel → lib/scss}/application.scss +10 -5
- data/{app/assets/stylesheets/lesli_babel → lib/scss}/dashboards.scss +2 -2
- data/{app/assets/stylesheets/lesli_babel → lib/scss}/modules.scss +2 -1
- data/{app/assets/stylesheets/lesli_babel → lib/scss}/translations.scss +2 -1
- data/lib/vue/application.js +7 -7
- data/lib/vue/apps/dashboards/show.vue +10 -12
- data/lib/vue/apps/modules/show.vue +5 -5
- data/lib/vue/apps/relevants/index.vue +2 -2
- data/lib/vue/apps/translations/index.vue +4 -4
- data/lib/vue/components/actions.vue +5 -5
- data/lib/vue/components/form-label-editor.vue +3 -3
- data/lib/vue/components/form-string-new.vue +2 -2
- metadata +7 -18
- data/app/assets/javascripts/lesli_babel/application.js.LICENSE.txt +0 -282
- data/app/models/lesli_babel/string/activity.rb +0 -5
- data/app/models/lesli_babel/string/discussion.rb +0 -68
- data/app/services/lesli_babel/old/translations_android_service.rb +0 -82
- data/app/services/lesli_babel/old/translations_clone_service.rb +0 -161
- data/app/services/lesli_babel/old/translations_flutter_service.rb +0 -102
- data/app/services/lesli_babel/old/translations_ios_service.rb +0 -119
- data/app/services/lesli_babel/old/translations_js_service.rb +0 -114
- data/app/services/lesli_babel/old/translations_middleman_service.rb +0 -77
- data/app/services/lesli_babel/old/translations_rails_service.rb +0 -119
- data/app/services/lesli_babel/old/translations_service.rb +0 -97
- data/app/services/lesli_babel/old/translations_synchronization_service.rb +0 -215
@@ -1,68 +0,0 @@
|
|
1
|
-
module LesliBabel
|
2
|
-
class String::Discussion < CloudObject::Discussion
|
3
|
-
belongs_to :cloud_object, class_name: "String", foreign_key: "cloud_babel_strings_id"
|
4
|
-
belongs_to :parent, class_name: "Discussion", optional: true
|
5
|
-
has_many :children, class_name: "Discussion", foreign_key: "parent_id"
|
6
|
-
|
7
|
-
def self.list(current_user, cloud_id)
|
8
|
-
|
9
|
-
discussions = self.joins(
|
10
|
-
"inner join cloud_babel_strings CO on cloud_babel_string_discussions.cloud_babel_strings_id = CO.id"
|
11
|
-
).joins(
|
12
|
-
"inner join users U on cloud_babel_string_discussions.users_id = U.id"
|
13
|
-
).joins(
|
14
|
-
"inner join user_details UD on UD.users_id = U.id"
|
15
|
-
).select(
|
16
|
-
"cloud_babel_string_discussions.id",
|
17
|
-
"cloud_babel_string_discussions.users_id",
|
18
|
-
"cloud_babel_string_discussions.content",
|
19
|
-
"cloud_babel_string_discussions.created_at",
|
20
|
-
"cloud_babel_string_discussions.cloud_babel_string_discussions_id",
|
21
|
-
"U.email",
|
22
|
-
"CONCAT(UD.first_name, ' ', UD.last_name) as user_name"
|
23
|
-
)
|
24
|
-
.where("CO.id = #{cloud_id}")
|
25
|
-
.where("CO.reference_module_bucket LIKE ?", "#{Rails.configuration.lesli_settings["instance"]}%")
|
26
|
-
.order(id: :asc)
|
27
|
-
.map { |discussion|
|
28
|
-
discussion_attributes = discussion.attributes
|
29
|
-
discussion_attributes["created_at_raw"] = discussion_attributes["created_at"]
|
30
|
-
discussion_attributes["editable"] = discussion.is_editable_by?(current_user)
|
31
|
-
discussion_attributes["created_at"] = LC::Date.to_string_datetime(discussion_attributes["created_at"])
|
32
|
-
discussion_attributes
|
33
|
-
}
|
34
|
-
|
35
|
-
data = {}
|
36
|
-
root_discussions = []
|
37
|
-
|
38
|
-
# Add all responses to that discussion
|
39
|
-
discussions.each do |discussion|
|
40
|
-
discussion_data = {
|
41
|
-
data: discussion,
|
42
|
-
responses: []
|
43
|
-
}
|
44
|
-
data[discussion["id"]] = discussion_data
|
45
|
-
|
46
|
-
if discussion["cloud_babel_string_discussions_id"].present?
|
47
|
-
parent_discussion = data[discussion["cloud_babel_string_discussions_id"]]
|
48
|
-
if parent_discussion[:data]["cloud_babel_string_discussions_id"].present?
|
49
|
-
discussion["response_to"] = parent_discussion[:data]["email"]
|
50
|
-
end
|
51
|
-
parent_discussion[:responses].push(discussion["id"])
|
52
|
-
else
|
53
|
-
root_discussions.push(discussion_data)
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
# Nest the responses to root discussions. A root discussion is any comment that is not a response to another comment
|
58
|
-
root_discussions.each do |discussion|
|
59
|
-
responses = []
|
60
|
-
self.nest_responses(data, discussion, responses)
|
61
|
-
discussion[:responses] = responses
|
62
|
-
end
|
63
|
-
|
64
|
-
# revert the root discussions so the most recent comments appear in the top
|
65
|
-
root_discussions.reverse
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
@@ -1,82 +0,0 @@
|
|
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
|
@@ -1,161 +0,0 @@
|
|
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
|
@@ -1,102 +0,0 @@
|
|
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
|
@@ -1,119 +0,0 @@
|
|
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
|
@@ -1,114 +0,0 @@
|
|
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
|