365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
|
# File 'lib/lokale/agent.rb', line 365
def import_strings(agent, writer)
xliff_paths = agent.proj_files
.select { |f| f =~ /\.xliff$/ }
.delete_if { |f| f =~ /export/ }
return if xliff_paths.empty?
diffs = xliff_paths.flat_map { |p| Diff.from_file(p) }
diffs.each do |d|
lf = file_for_diff(d, agent.lfiles)
next if lf.nil?
content = lf.content
strings_to_append = []
d.lstrings.each do |ls|
string_regexp = /^\s*?"#{ls.key}"\s*?=\s*?"(.*?)";/
if content =~ string_regexp
if $1 != ls.str
puts "#{lf.lang}/#{lf.full_name} update \"#{ls.key.blue}\": \"#{$1}\" -> \"#{ls.str.blue}\""
content.sub! string_regexp, "\"#{ls.key}\" = \"#{ls.str}\";"
end
else
strings_to_append << ls
end
end
lf.write content
writer.append_new_strings(strings_to_append, lf) unless strings_to_append.empty?
end
end
|