]> pere.pagekite.me Git - text-madewithcc.git/commitdiff
Start on script to unfuzzy po files after migration to XML as po4a source.
authorPetter Reinholdtsen <pere@hungry.com>
Fri, 16 Feb 2018 07:06:12 +0000 (07:06 +0000)
committerPetter Reinholdtsen <pere@hungry.com>
Thu, 22 Feb 2018 18:12:09 +0000 (18:12 +0000)
Downloaded from <URL: https://gitlab.com/gunnarwolf/madewithcc-es/issues/3 >

fixup-migrate-gettext.rb [new file with mode: 0644]

diff --git a/fixup-migrate-gettext.rb b/fixup-migrate-gettext.rb
new file mode 100644 (file)
index 0000000..9bb7ec8
--- /dev/null
@@ -0,0 +1,62 @@
+#!/usr/bin/ruby
+class PoStr
+  Sections = %w(Headers Source Translated)
+  attr_accessor :status, :src, :dest, :type, :location
+  def initialize(text)
+    section = 0
+    @status = ''
+    @src = []
+    @dest = []
+
+    text.split(/\n/).each do |lin|
+      # Header
+      if section == 0
+        if lin =~ /^#(.) ([^:]*)(?::(.*))?/
+          type = $1
+          field = $2
+          value = $3
+
+          @status = 'fuzzy' if type == ',' and field == 'fuzzy'
+          @type = value if type == '.' and field == 'type'
+          @location = {:file => field, :line => value} if type == ':'
+        elsif lin =~ /^msgid (".*")/
+          section += 1
+          @src << $1
+        else
+          boom(section, lin, text)
+        end
+
+      # Source text
+      elsif section == 1
+        if lin =~ /^".*"$/
+          @src << lin
+        elsif lin =~ /^msgstr (".*")/
+          section += 1
+          @dest << $1
+        else
+          boom(section, lin, text)
+        end
+
+      # Translated text
+      else
+        if lin =~ /^".*"$/
+          @dest << lin
+        else
+          boom(section, lin, text)
+        end
+      end
+    end
+  end
+
+  def boom(section, line, text)
+    raise RuntimeError, "Unexpected string in %s:\n %s\n\nFull text: %s" %
+                        [Sections[section], line, text]
+  end
+
+  def fuzzy?
+    @status == 'fuzzy'
+  end
+end
+
+file = 'po/es/mwcc.po'
+strings = File.open(file,'r').read.split(/\n\n/)[1..-1].map {|str| PoStr.new(str)}