Created
June 1, 2016 15:54
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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