4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
# File 'app/services/lesli_babel/deploy_rails_service.rb', line 4
def build
Lesli::System.engines.each do |engine, engine_info|
engine_id = Module
.where("platform in ('lesli_core', 'lesli_engine')")
.where(:code => engine_info[:code])
.pluck(:id)
engine_id_lesli = Module
.where("platform in ('lesli_core', 'lesli_engine')")
.where(:code => "lesli")
.pluck(:id)
bucket_id_shared = Bucket
.where(:code => "shared")
.where(:module_id => engine_id_lesli)
.pluck(:id)
bucket_id_application = Bucket
.where(:code => "application")
.where(:module_id => engine_id_lesli)
.pluck(:id)
strings = StringService.new(current_user, query).list(engine_id)
strings_shared = StringService.new(current_user, query).list(engine_id_lesli, bucket_id_shared)
strings_application = StringService.new(current_user, query).list(engine_id_lesli, bucket_id_application)
strings = strings.select(
:id,
:label,
:status,
:context,
Lesli.config.locales.keys,
"lesli_babel_modules.id as engine_id",
"lesli_babel_buckets.id as bucket_id",
"lesli_babel_buckets.code as bucket_code",
"lesli_babel_modules.code as engine_code",
"lesli_babel_modules.platform as platform",
"'' as path"
)
translations = {}
available_locales = Lesli.config.locales.keys
available_locales.each do |lang|
translations[lang] = {
:file => "",
:labels => {}
}
end
engine_code = engine_info[:code]
available_locales.each do |lang|
translations[lang][:file] = "#{engine}::Engine".constantize.root.join(
"config", "locales", "translations.#{lang}.yml"
).to_s
strings.each do |string|
bucket_code = string[:bucket_code]
unless translations[lang][:labels].has_key? engine_code
translations[lang][:labels][engine_code] = { }
end
unless translations[lang][:labels][engine_code].has_key? bucket_code
translations[lang][:labels][engine_code][bucket_code] = { }
end
string[lang] = ":" + string.path + ":" if string[lang].blank?
translations[lang][:labels][engine_code][bucket_code][string.label] = string[lang]
end
strings_shared.each do |string|
unless translations[lang][:labels].has_key? "lesli"
translations[lang][:labels]["lesli"] = { }
end
unless translations[lang][:labels]["lesli"].has_key? "shared"
translations[lang][:labels]["lesli"]["shared"] = { }
end
string[lang] = ":" + string.path + ":" if string[lang].blank?
translations[lang][:labels]["lesli"]["shared"][string.label] = string[lang]
end
strings_application.each do |string|
unless translations[lang][:labels].has_key? "lesli"
translations[lang][:labels]["lesli"] = { }
end
unless translations[lang][:labels]["lesli"].has_key? "application"
translations[lang][:labels]["lesli"]["application"] = { }
end
string[lang] = ":" + string.path + ":" if string[lang].blank?
translations[lang][:labels]["lesli"]["application"][string.label] = string[lang]
end
end
translations.each do |lang, translations|
FileUtils.makedirs(File.dirname(translations[:file]))
translation_file = File.new(translations[:file], "w+")
translation_file.write({ "#{lang}": translations[:labels] }.to_yaml)
translation_file.close
end
end
end
|