diff --git a/lib/twine/formatters/abstract.rb b/lib/twine/formatters/abstract.rb
index 905b6b7..17a2115 100644
--- a/lib/twine/formatters/abstract.rb
+++ b/lib/twine/formatters/abstract.rb
@@ -115,15 +115,18 @@ module Twine
def format_file(lang, default_lang)
result = format_header(lang) + "\n"
-
- sections = @strings.sections.map { |section| format_section(section, lang, default_lang) }
- result += sections.join("\n")
+ result += format_sections(lang, default_lang)
end
def format_header(lang)
raise NotImplementedError.new("You must implement format_header in your formatter class.")
end
+ def format_sections(lang, default_lang)
+ sections = @strings.sections.map { |section| format_section(section, lang, default_lang) }
+ sections.join("\n")
+ end
+
def format_section_header(section)
end
@@ -134,13 +137,13 @@ module Twine
unless rows.empty?
if section.name && section.name.length > 0
section_header = format_section_header(section)
- result += "\n#{section_header}\n" if section_header
+ result += "\n#{section_header}" if section_header
end
end
rows.map! { |row| format_row(row, lang, default_lang) }
rows.compact! # remove nil entries
- rows.map! { |row| "\n#{row}\n" } # wrap with newlines
+ rows.map! { |row| "\n#{row}" } # prepend newline
result += rows.join
end
diff --git a/lib/twine/formatters/android.rb b/lib/twine/formatters/android.rb
index 92cbcaa..d300a28 100644
--- a/lib/twine/formatters/android.rb
+++ b/lib/twine/formatters/android.rb
@@ -91,65 +91,57 @@ module Twine
end
end
- def write_file(path, lang)
- default_lang = nil
- if DEFAULT_LANG_CODES.has_key?(lang)
- default_lang = DEFAULT_LANG_CODES[lang]
+ def format_header(lang)
+ "\n\n\n"
+ end
+
+ def format_section_header(section)
+ "\t"
+ end
+
+ def format_row(row, lang, default_lang)
+ result = ""
+ key = row.key
+
+ value = row.translated_string_for_lang(lang, default_lang)
+ if !value && @options[:include_untranslated]
+ value = row.translated_string_for_lang(@strings.language_codes[0])
end
- File.open(path, 'w:UTF-8') do |f|
- f.puts "\n\n\n"
- f.write ''
- @strings.sections.each do |section|
- printed_section = false
- section.rows.each do |row|
- if row.matches_tags?(@options[:tags], @options[:untagged])
- if !printed_section
- f.puts ''
- if section.name && section.name.length > 0
- section_name = section.name.gsub('--', '—')
- f.puts "\t"
- end
- printed_section = true
- end
- key = row.key
+ if value # if values is nil, there was no appropriate translation, so let Android handle the defaulting
+ value = String.new(value) # use a copy to prevent modifying the original
- value = row.translated_string_for_lang(lang, default_lang)
- if !value && @options[:include_untranslated]
- value = row.translated_string_for_lang(@strings.language_codes[0])
- end
+ # Android enforces the following rules on the values
+ # 1) apostrophes and quotes must be escaped with a backslash
+ value.gsub!('\'', '\\\\\'')
+ value.gsub!('"', '\\\\"')
+ # 2) HTML escape the string
+ value = CGI.escapeHTML(value)
+ # 3) fix substitutions (e.g. %s/%@)
+ value = androidify_substitutions(value)
+ # 4) replace beginning and end spaces with \0020. Otherwise Android strips them.
+ value.gsub!(/\A *| *\z/) { |spaces| '\u0020' * spaces.length }
- if value # if values is nil, there was no appropriate translation, so let Android handle the defaulting
- value = String.new(value) # use a copy to prevent modifying the original
-
- # Android enforces the following rules on the values
- # 1) apostrophes and quotes must be escaped with a backslash
- value.gsub!('\'', '\\\\\'')
- value.gsub!('"', '\\\\"')
- # 2) HTML escape the string
- value = CGI.escapeHTML(value)
- # 3) fix substitutions (e.g. %s/%@)
- value = androidify_substitutions(value)
- # 4) replace beginning and end spaces with \0020. Otherwise Android strips them.
- value.gsub!(/\A *| *\z/) { |spaces| '\u0020' * spaces.length }
-
- comment = row.comment
- if comment
- comment = comment.gsub('--', '—')
- end
-
- if comment && comment.length > 0
- f.puts "\t\n"
- end
- f.puts "\t#{value}"
- end
- end
- end
+ comment = row.comment
+ if comment
+ comment = comment.gsub('--', '—')
end
- f.puts ''
+ if comment && comment.length > 0
+ result += "\t\n"
+ end
+ result += "\t#{value}"
end
end
+
+ def format_sections(lang, default_lang)
+ result = ''
+
+ result += super(lang, default_lang) + "\n"
+
+ result += ''
+ end
+
end
end
end
diff --git a/lib/twine/formatters/apple.rb b/lib/twine/formatters/apple.rb
index fbb7719..9ff0b86 100644
--- a/lib/twine/formatters/apple.rb
+++ b/lib/twine/formatters/apple.rb
@@ -87,11 +87,11 @@ module Twine
end
def format_section_header(section)
- "/********** #{section.name} **********/" if section.name && section.name.length > 0
+ "/********** #{section.name} **********/\n" if section.name && section.name.length > 0
end
def key_value_pattern
- "\"%{key}\" = \"%{value}\";"
+ "\"%{key}\" = \"%{value}\";\n"
end
def format_comment(comment)