diff --git a/lib/twine/formatters/flash.rb b/lib/twine/formatters/flash.rb index 7a96506..cb770c0 100644 --- a/lib/twine/formatters/flash.rb +++ b/lib/twine/formatters/flash.rb @@ -70,40 +70,25 @@ module Twine end end - def write_file(path, lang) - default_lang = @strings.language_codes[0] - encoding = @options[:output_encoding] || 'UTF-8' - File.open(path, "w:#{encoding}") do |f| - f.puts "## Flash Strings File\n## Generated by Twine #{Twine::VERSION}\n## Language: #{lang}\n" - @strings.sections.each do |section| - printed_section = false - section.rows.each do |row| - if row.matches_tags?(@options[:tags], @options[:untagged]) - f.puts '' - if !printed_section - if section.name && section.name.length > 0 - f.print "## #{section.name} ##\n\n" - end - printed_section = true - end + def format_header(lang) + "## Flash Strings File\n## Generated by Twine #{Twine::VERSION}\n## Language: #{lang}" + end - key = row.key - value = row.translated_string_for_lang(lang, default_lang) - if value - placeHolderNumber = -1 - value = value.gsub(/%[d@]/) { placeHolderNumber += 1; '{%d}' % placeHolderNumber } - - comment = row.comment - if comment && comment.length > 0 - f.print "# #{comment}\n" - end + def format_section_header(section) + "## #{section.name} ##\n" + end - f.print "#{key}=#{value}" - end - end - end - end - end + def format_comment(comment) + "# #{comment}" + end + + def key_value_pattern + "%{key}=%{value}" + end + + def format_value(value) + placeHolderNumber = -1 + value.gsub(/%[d@]/) { placeHolderNumber += 1; '{%d}' % placeHolderNumber } end end end diff --git a/test/fixtures/formatter_flash.properties b/test/fixtures/formatter_flash.properties index d48ec52..a623196 100644 --- a/test/fixtures/formatter_flash.properties +++ b/test/fixtures/formatter_flash.properties @@ -7,8 +7,9 @@ # comment key1 key1=value1-english key2=value2-english + ## Section 2 ## key3=value3-english # comment key4 -key4=value4-english \ No newline at end of file +key4=value4-english