Adapted Flash formatter to the modular style.
This commit is contained in:
parent
84cf07d353
commit
a35107ea99
2 changed files with 19 additions and 33 deletions
|
@ -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
|
||||
|
|
3
test/fixtures/formatter_flash.properties
vendored
3
test/fixtures/formatter_flash.properties
vendored
|
@ -7,8 +7,9 @@
|
|||
# comment key1
|
||||
key1=value1-english
|
||||
key2=value2-english
|
||||
|
||||
## Section 2 ##
|
||||
|
||||
key3=value3-english
|
||||
# comment key4
|
||||
key4=value4-english
|
||||
key4=value4-english
|
||||
|
|
Reference in a new issue