class Lokale::Importer
Public Instance Methods
file_for_diff(diff, all_lfiles)
click to toggle source
# File lib/lokale/agent.rb, line 398 def file_for_diff(diff, all_lfiles) all_lfiles.select { |lf| lf.full_name == diff.name && lf.lang == diff.lang }.sample end
import_strings(agent, writer)
click to toggle source
# 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/ } # .select { |f| puts "select #{f}, #{f =~ /\.xliff^/}"; f =~ /\.xliff^/ } # .delete_if { |f| puts "delete #{f}, #{f =~ /export/}"; 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