class Terrestrial::Cli::DotStringsFormatter
Public Class Methods
new(entries)
click to toggle source
# File lib/terrestrial/cli/dot_strings_formatter.rb, line 5 def initialize(entries) @entries = entries end
Public Instance Methods
format()
click to toggle source
# File lib/terrestrial/cli/dot_strings_formatter.rb, line 29 def format result = [] entries.each do |entry| result.concat(file_comments(entry)) result.concat(id_and_string(entry)) result.concat(spacing) end result.join("\n") end
format_foreign_translation()
click to toggle source
# File lib/terrestrial/cli/dot_strings_formatter.rb, line 9 def format_foreign_translation result = [] entries.reject(&:placeholder?).each do |entry| # just id and string needed for translation # files. extra metadata is found in base.lproj. result << id_and_string(entry) result << "" end result.concat(placeholder_disclaimer) entries.select(&:placeholder?).each do |entry| # just id and string needed for translation # files. extra metadata is found in base.lproj. result << id_and_string(entry) result << "" end result.join("\n") end
Private Instance Methods
entries()
click to toggle source
# File lib/terrestrial/cli/dot_strings_formatter.rb, line 73 def entries @entries end
escape_string(string)
click to toggle source
# File lib/terrestrial/cli/dot_strings_formatter.rb, line 65 def escape_string(string) string.gsub("\"", "\\\"") end
file_comments(entry)
click to toggle source
# File lib/terrestrial/cli/dot_strings_formatter.rb, line 49 def file_comments(entry) ["// Files:"] + entry .occurences .uniq {|occ| occ.file } .map {|occ| "// - #{occ.file}" } end
id_and_string(entry)
click to toggle source
# File lib/terrestrial/cli/dot_strings_formatter.rb, line 57 def id_and_string(entry) if entry.respond_to? :formatted_string ["\"#{entry.identifier}\"=\"#{escape_string(entry.formatted_string)}\";"] else ["\"#{entry.identifier}\"=\"#{escape_string(entry.string)}\";"] end end
placeholder_disclaimer()
click to toggle source
# File lib/terrestrial/cli/dot_strings_formatter.rb, line 41 def placeholder_disclaimer [ "// The following translations have been copied from the project base language because no translation was provided for them.", "// iOS requires each Localizable.strings file to contain all keys used in the project. In order to provide proper fallbacks, Terrestrial includes missing translations in each translation resource file.", "" ] end
spacing()
click to toggle source
# File lib/terrestrial/cli/dot_strings_formatter.rb, line 69 def spacing [""] # No need to put new line because of join above end