Class: Babelish::Strings2CSV
- Defined in:
- lib/babelish/strings2csv.rb
Instance Attribute Summary collapse
-
#csv_filename ⇒ Object
default_lang is the the column to refer to if a value is missing actually default_lang = default_filename.
-
#default_lang ⇒ Object
default_lang is the the column to refer to if a value is missing actually default_lang = default_filename.
-
#filenames ⇒ Object
default_lang is the the column to refer to if a value is missing actually default_lang = default_filename.
-
#headers ⇒ Object
default_lang is the the column to refer to if a value is missing actually default_lang = default_filename.
Instance Method Summary collapse
-
#initialize(args = {:filenames => []}) ⇒ Strings2CSV
constructor
A new instance of Strings2CSV.
-
#load_strings(strings_filename) ⇒ Object
Load all strings of a given file.
- #parse_dotstrings_line(line) ⇒ Object
Methods inherited from Base2Csv
Constructor Details
#initialize(args = {:filenames => []}) ⇒ Strings2CSV
Returns a new instance of Strings2CSV.
7 8 9 |
# File 'lib/babelish/strings2csv.rb', line 7 def initialize(args = {:filenames => []}) super(args) end |
Instance Attribute Details
#csv_filename ⇒ Object
default_lang is the the column to refer to if a value is missing actually default_lang = default_filename
5 6 7 |
# File 'lib/babelish/strings2csv.rb', line 5 def csv_filename @csv_filename end |
#default_lang ⇒ Object
default_lang is the the column to refer to if a value is missing actually default_lang = default_filename
5 6 7 |
# File 'lib/babelish/strings2csv.rb', line 5 def default_lang @default_lang end |
#filenames ⇒ Object
default_lang is the the column to refer to if a value is missing actually default_lang = default_filename
5 6 7 |
# File 'lib/babelish/strings2csv.rb', line 5 def filenames @filenames end |
#headers ⇒ Object
default_lang is the the column to refer to if a value is missing actually default_lang = default_filename
5 6 7 |
# File 'lib/babelish/strings2csv.rb', line 5 def headers @headers end |
Instance Method Details
#load_strings(strings_filename) ⇒ Object
Load all strings of a given file
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/babelish/strings2csv.rb', line 20 def load_strings(strings_filename) strings = {} # genstrings uses utf16, so that's what we expect. utf8 should not be impact file = File.open(strings_filename, "r:utf-16:utf-8") begin contents = file.read if RUBY_VERSION == "1.9.2" # fixes conversion, see http://po-ru.com/diary/fixing-invalid-utf-8-in-ruby-revisited/ require 'iconv' ic = Iconv.new('UTF-8//IGNORE', 'UTF-8') contents = ic.iconv(contents + ' ')[0..-2] end rescue Encoding::InvalidByteSequenceError => e # silent error # faults back to utf8 contents = File.open(strings_filename, "r:utf-8") end contents.each_line do |line| hash = self.parse_dotstrings_line(line) strings.merge!(hash) if hash end strings end |
#parse_dotstrings_line(line) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/babelish/strings2csv.rb', line 11 def parse_dotstrings_line(line) line.strip! if line[0] != ?# && line[0] != ?= && line[0] != ?/ m = line.match(/^[^\"]*\"(.+)\"[^=]+=[^\"]*\"(.*)\";/) return {m[1] => m[2]} unless m.nil? end end |