Skip to content

Instantly share code, notes, and snippets.

@spenrose
Created June 1, 2016 15:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spenrose/424caff20b7a2550e144cc15336ccc03 to your computer and use it in GitHub Desktop.
Save spenrose/424caff20b7a2550e144cc15336ccc03 to your computer and use it in GitHub Desktop.
When importing xliff files into Xcode it does not convert new lines to `\n`. This results in broken strings files.
require 'nokogiri'
filename = "filename.xliff"
out_filename = "out_filename.xliff"
doc = File.open(filename) { |f| Nokogiri::XML(f) }
source = doc.css("trans-unit source")
source.each { |s|
s.content = s.content.gsub("\n", "\\n")
}
target = doc.css("trans-unit target")
target.each { |t|
t.content = t.content.gsub("\n", "\\n")
}
File.write(out_filename, doc.to_xml)
@liamnichols
Copy link

I found this while facing a similar issue but FYI it looks like it has been resolved (well at least the behaviour has changed) in Xcode 9.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment