Class: Twine::Formatters::Apple
Constant Summary
Constants inherited
from Abstract
Twine::Formatters::Abstract::LANGUAGE_CODE_WITH_OPTIONAL_REGION_CODE
Instance Attribute Summary
Attributes inherited from Abstract
#options, #twine_file
Instance Method Summary
collapse
Methods inherited from Abstract
#escape_quotes, #format_definition, #format_file, #format_key_value, #format_section, #format_sections, #initialize, #set_comment_for_key, #set_translation_for_key, #should_include_definition
Instance Method Details
#can_handle_directory?(path) ⇒ Boolean
12
13
14
|
# 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 ⇒ Object
16
17
18
|
# File 'lib/twine/formatters/apple.rb', line 16
def default_file_name
'Localizable.strings'
end
|
#determine_language_given_path(path) ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# 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 ⇒ Object
8
9
10
|
# File 'lib/twine/formatters/apple.rb', line 8
def extension
'.strings'
end
|
78
79
80
|
# File 'lib/twine/formatters/apple.rb', line 78
def (definition, lang)
"/* #{definition..gsub('*/', '* /')} */\n" if definition.
end
|
66
67
68
|
# File 'lib/twine/formatters/apple.rb', line 66
def (lang)
"/**\n * Apple Strings File\n * Generated by Twine #{Twine::VERSION}\n * Language: #{lang}\n */"
end
|
82
83
84
|
# File 'lib/twine/formatters/apple.rb', line 82
def format_key(key)
escape_quotes(key)
end
|
4
5
6
|
# File 'lib/twine/formatters/apple.rb', line 4
def format_name
'apple'
end
|
70
71
72
|
# File 'lib/twine/formatters/apple.rb', line 70
def (section)
"/********** #{section.name} **********/\n"
end
|
86
87
88
|
# File 'lib/twine/formatters/apple.rb', line 86
def format_value(value)
escape_quotes(value)
end
|
#key_value_pattern ⇒ Object
74
75
76
|
# File 'lib/twine/formatters/apple.rb', line 74
def key_value_pattern
"\"%{key}\" = \"%{value}\";\n"
end
|
#output_path_for_language(lang) ⇒ Object
36
37
38
|
# File 'lib/twine/formatters/apple.rb', line 36
def output_path_for_language(lang)
"#{lang}.lproj"
end
|
#read(io, lang) ⇒ Object
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/twine/formatters/apple.rb', line 40
def read(io, lang)
= nil
while line = io.gets
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
(key, )
end
end
match = /\/\* (.*) \*\//.match(line)
if match
= match[1]
else
= nil
end
end
end
|