From: Petter Reinholdtsen Date: Fri, 16 Feb 2018 07:06:12 +0000 (+0000) Subject: Start on script to unfuzzy po files after migration to XML as po4a source. X-Git-Tag: es-printed~494 X-Git-Url: https://pere.pagekite.me/gitweb/text-madewithcc.git/commitdiff_plain/3eef52296ce03452f6ef986169b2591ed5eea6db Start on script to unfuzzy po files after migration to XML as po4a source. Downloaded from --- diff --git a/fixup-migrate-gettext.rb b/fixup-migrate-gettext.rb new file mode 100644 index 0000000..9bb7ec8 --- /dev/null +++ b/fixup-migrate-gettext.rb @@ -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)}