]> pere.pagekite.me Git - text-free-culture-lessig.git/commitdiff
added script to convert translated —+space with " – "
authorJohannes Larsen <mail@johslarsen.net>
Fri, 4 Sep 2015 19:26:55 +0000 (21:26 +0200)
committerJohannes Larsen <mail@johslarsen.net>
Fri, 4 Sep 2015 20:09:30 +0000 (22:09 +0200)
scripts/translated_emdash_converter.rb [new file with mode: 0755]

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 =~ /^"&mdash;/
+    lines[i-1].sub!(/ *"$/, "\"")
+  end
+  if line =~ /&mdash;"$/
+    lines[i+1].sub!(/^" */, "\"")
+  end
+
+  line.gsub!(/ *&mdash; */, REPLACE_WITH)
+end
+puts lines