class Twine::Formatters::Apple
Public Instance Methods
can_handle_directory?(path)
click to toggle source
# File lib/twine/formatters/apple.rb, line 12 def can_handle_directory?(path) Dir.entries(path).any? { |item| /^.+\.lproj$/.match(item) } end
default_file_name()
click to toggle source
# File lib/twine/formatters/apple.rb, line 16 def default_file_name 'Localizable.strings' end
determine_language_given_path(path)
click to toggle source
Calls superclass method
Twine::Formatters::Abstract#determine_language_given_path
# File lib/twine/formatters/apple.rb, line 20 def determine_language_given_path(path) path_arr = path.split(File::SEPARATOR) path_arr.each do |segment| match = /^(.+)\.lproj$/.match(segment) if match if match[1] == "Base" return @options[:developer_language] else return match[1] end end end return super end
extension()
click to toggle source
# File lib/twine/formatters/apple.rb, line 8 def extension '.strings' end
format_comment(definition, lang)
click to toggle source
# File lib/twine/formatters/apple.rb, line 78 def format_comment(definition, lang) "/* #{definition.comment.gsub('*/', '* /')} */\n" if definition.comment end
format_header(lang)
click to toggle source
# File lib/twine/formatters/apple.rb, line 66 def format_header(lang) "/**\n * Apple Strings File\n * Generated by Twine #{Twine::VERSION}\n * Language: #{lang}\n */" end
format_key(key)
click to toggle source
# File lib/twine/formatters/apple.rb, line 82 def format_key(key) escape_quotes(key) end
format_name()
click to toggle source
# File lib/twine/formatters/apple.rb, line 4 def format_name 'apple' end
format_section_header(section)
click to toggle source
# File lib/twine/formatters/apple.rb, line 70 def format_section_header(section) "/********** #{section.name} **********/\n" end
format_value(value)
click to toggle source
# File lib/twine/formatters/apple.rb, line 86 def format_value(value) escape_quotes(value) end
key_value_pattern()
click to toggle source
# File lib/twine/formatters/apple.rb, line 74 def key_value_pattern "\"%{key}\" = \"%{value}\";\n" end
output_path_for_language(lang)
click to toggle source
# File lib/twine/formatters/apple.rb, line 36 def output_path_for_language(lang) "#{lang}.lproj" end
read(io, lang)
click to toggle source
# File lib/twine/formatters/apple.rb, line 40 def read(io, lang) last_comment = nil while line = io.gets # matches a `key = "value"` line, where key may be quoted or unquoted. The former may also contain escaped characters match = /^\s*((?:"(?:[^"\\]|\\.)+")|(?:[^"\s=]+))\s*=\s*"((?:[^"\\]|\\.)*)"/.match(line) if match key = match[1] key = key[1..-2] if key[0] == '"' and key[-1] == '"' key.gsub!('\\"', '"') value = match[2] value.gsub!('\\"', '"') set_translation_for_key(key, lang, value) if last_comment set_comment_for_key(key, last_comment) end end match = /\/\* (.*) \*\//.match(line) if match last_comment = match[1] else last_comment = nil end end end