]> pere.pagekite.me Git - text-free-culture-lessig.git/blobdiff - scripts/translated_emdash_converter.rb
added script to convert translated —+space with " – "
[text-free-culture-lessig.git] / scripts / translated_emdash_converter.rb
diff --git a/scripts/translated_emdash_converter.rb b/scripts/translated_emdash_converter.rb
new file mode 100755 (executable)
index 0000000..45edeb0
--- /dev/null
@@ -0,0 +1,27 @@
+#!/usr/bin/env ruby
+
+REPLACE_WITH = " &ndash "
+
+is_translation = false
+
+lines = ARGF.readlines
+lines.each_with_index do |line, i|
+  case line
+  when /^msgid/ then is_translation = false
+  when /^msgstr/ then is_translation = true
+  end
+
+  unless is_translation
+    next
+  end
+
+  if line =~ /^"—/
+    lines[i-1].sub!(/ *"$/, "\"")
+  end
+  if line =~ /—"$/
+    lines[i+1].sub!(/^" */, "\"")
+  end
+
+  line.gsub!(/ *— */, REPLACE_WITH)
+end
+puts lines