Class: Babelyoda::Strings
Instance Attribute Summary collapse
Attributes inherited from Keyset
#keys, #name
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Keyset
#debug_counts, #drop_empty!, #empty?, #ensure_languages!, keyset_name, #merge!, #merge_key!, parse_xml, #to_s, #to_strings, #to_xml
Constructor Details
#initialize(filename, language) ⇒ Strings
Returns a new instance of Strings.
41
42
43
44
|
# File 'lib/babelyoda/strings.rb', line 41
def initialize(filename, language)
super(Babelyoda::Keyset.keyset_name(filename))
@filename, @language = filename, language
end
|
Instance Attribute Details
#filename ⇒ Object
Returns the value of attribute filename.
38
39
40
|
# File 'lib/babelyoda/strings.rb', line 38
def filename
@filename
end
|
#language ⇒ Object
Returns the value of attribute language.
39
40
41
|
# File 'lib/babelyoda/strings.rb', line 39
def language
@language
end
|
Class Method Details
.save_keyset(keyset, filename, language) ⇒ Object
78
79
80
81
82
|
# File 'lib/babelyoda/strings.rb', line 78
def self.save_keyset(keyset, filename, language)
strings = self.new(filename, language)
strings.merge!(keyset)
strings.save!
end
|
Instance Method Details
#read ⇒ Object
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/babelyoda/strings.rb', line 51
def read
$logger.debug "READING STRINGS FROM: #{@filename} WITH MODE: #{read_mode}"
if File.exist?(@filename)
File.open(@filename, read_mode) do |f|
lexer = StringsLexer.new
parser = StringsParser.new(lexer, @language)
parser.parse(f.read) do |localization_key|
merge_key!(localization_key)
end
end
end
self
end
|
#read! ⇒ Object
46
47
48
49
|
# File 'lib/babelyoda/strings.rb', line 46
def read!
raise ArgumentError.new("File not found: #{filename}") unless File.exist?(@filename)
read
end
|
#save! ⇒ Object
65
66
67
68
69
70
71
72
|
# File 'lib/babelyoda/strings.rb', line 65
def save!
$logger.debug "WRITING STRINGS TO: #{filename} WITH MODE: wb:UTF-8"
FileUtils.mkdir_p(File.dirname(filename))
File.open(filename, "wb:UTF-8") do |f|
write_bom(f)
to_strings(f, language)
end
end
|
#write_bom(f) ⇒ Object
74
75
76
|
# File 'lib/babelyoda/strings.rb', line 74
def write_bom(f)
f.write "\uFEFF" end
|