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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
|
# File 'lib/applocale/Util/config_util.rb', line 75
def load_configfile_to_setting
error_list = Array.new
config_yaml, rubycode = load_configfile
link = config_yaml['link'].to_s.strip
platform = config_yaml['platform'].to_s.strip
xlsxpath = config_yaml['xlsxpath'].to_s.strip
google_credentials_path = config_yaml['google_credentials_path'].to_s.strip
langlist = config_yaml['langlist']
sheetname = config_yaml['sheetname']
export_format = config_yaml['export_format']
export_to = config_yaml['export_to']
setting = Applocale::Config::Setting.new(self.configfile_pathstr)
setting.rubycode = rubycode
unless link.nil? || link.length == 0
if (link =~ /^https/).nil? && (link =~ /^http/).nil?
error = ErrorUtil::ConfigFileInValid.new("Invalid link for [link] : #{link}")
error_list.push(error)
else
setting.link = link
end
end
if platform.nil? || platform.length == 0
error = ErrorUtil::ConfigFileInValid.new('[platform] should not be empty')
error_list.push(error)
else
if Platform.init(platform).nil?
error = ErrorUtil::ConfigFileInValid.new("[platform] can only be 'ios', 'android' or 'json'.")
error_list.push(error)
else
setting.platform = Platform.init(platform)
end
end
case export_format
when 'csv', 'xlsx'
setting.export_format = export_format
else
error = ErrorUtil::ConfigFileInValid.new("[export_format] for item can only be 'csv' or 'xlsx' ")
error_list.push(error)
end
setting.export_to = FilePathUtil.default_export_to
if !(xlsxpath.nil? || xlsxpath.length == 0)
if !(Pathname.new xlsxpath).absolute?
setting.xlsxpath = File.expand_path(xlsxpath, setting.export_to)
else
setting.xlsxpath = xlsxpath
end
else
error = ErrorUtil::ConfigFileInValid.new('[xlsxpath] should not be empty or missing')
error_list.push(error)
end
if !(google_credentials_path.nil? || google_credentials_path.length == 0)
if !(Pathname.new google_credentials_path).absolute?
setting.google_credentials_path = File.expand_path(google_credentials_path, File.dirname(self.configfile_pathstr))
else
setting.google_credentials_path = google_credentials_path
end
end
if langlist.nil?
error = ErrorUtil::ConfigFileInValid.new('[langlist] should not be empty ')
error_list.push(error)
elsif !(langlist.is_a? Hash)
error = ErrorUtil::ConfigFileInValid.new('[langlist] wrong format')
error_list.push(error)
elsif langlist.length <= 0
error = ErrorUtil::ConfigFileInValid.new('[langlist] should not be empty ')
error_list.push(error)
else
langlist.each do |lang, filepath|
path = filepath.strip
if path.length <= 0
error = ErrorUtil::ConfigFileInValid.new("[#{lang}] in [langlist] should not be empty ")
error_list.push(error)
else
if !(Pathname.new path).absolute?
path = File.expand_path(path,File.dirname(self.configfile_pathstr))
end
obj = LangPath.new(lang.to_s, path)
setting.lang_path_list.push(obj)
end
end
end
if sheetname.nil?
error = ErrorUtil::ConfigFileInValid.new('[sheetname] should not be empty ')
error_list.push(error)
elsif !(sheetname.is_a? Hash)
error = ErrorUtil::ConfigFileInValid.new('[sheetname] wrong format, should be dict')
error_list.push(error)
elsif sheetname.length <= 0
error = ErrorUtil::ConfigFileInValid.new('[sheetname] should not be empty ')
error_list.push(error)
else
sheetname.each do |sheetname, infos|
if !(infos.is_a? Hash)
error = ErrorUtil::ConfigFileInValid.new("[sheetname] for item [#{sheetname}] is wrong format ")
error_list.push(error)
else
= {}
langarr = setting.lang_path_list.map { |langpath| langpath.lang }
langarr.each do |lang|
info_lang = infos[lang].to_s.strip
if info_lang.length <= 0
error = ErrorUtil::ConfigFileInValid.new("[sheetname] for item [#{sheetname}]: missing lang [#{lang}] ")
error_list.push(error)
else
[lang] = info_lang
end
end
info_row = infos['row'].to_s.strip
info_key = infos['key'].to_s.strip
info_key_str = infos['key_str'].to_s.strip
if info_row.length > 0 && info_key.length > 0
obj = SheetInfoByRow.new(info_row.to_i, info_key, )
sheet = Sheet.new(sheetname,obj)
setting.sheet_obj_list.push(sheet)
elsif info_key_str.length > 0
obj = SheetInfoByHeader.new(info_key_str, )
sheet = Sheet.new(sheetname,obj)
setting.sheet_obj_list.push(sheet)
else
error = ErrorUtil::ConfigFileInValid.new("[sheetname] for item [#{sheetname}] is wrong format ")
error_list.push(error)
end
end
end
end
setting.printlog
ErrorUtil::ConfigFileInValid.raiseArr(error_list)
return setting
end
|