Class: Twine::Formatters::Apple
Constant Summary
collapse
- FORMAT_NAME =
'apple'
- EXTENSION =
'.strings'
- DEFAULT_FILE_NAME =
'Localizable.strings'
Instance Attribute Summary
Attributes inherited from Abstract
#options, #strings
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Abstract
#escape_quotes, #format_file, #format_key_value, #format_row, #format_section, #format_sections, #initialize, #row_pattern, #set_comment_for_key, #set_translation_for_key, #write_all_files, #write_file
Class Method Details
.can_handle_directory?(path) ⇒ Boolean
8
9
10
|
# File 'lib/twine/formatters/apple.rb', line 8
def self.can_handle_directory?(path)
Dir.entries(path).any? { |item| /^.+\.lproj$/.match(item) }
end
|
Instance Method Details
#default_file_name ⇒ Object
12
13
14
|
# File 'lib/twine/formatters/apple.rb', line 12
def default_file_name
return DEFAULT_FILE_NAME
end
|
#determine_language_given_path(path) ⇒ Object
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/twine/formatters/apple.rb', line 16
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 match[1]
end
end
end
return
end
|
100
101
102
|
# File 'lib/twine/formatters/apple.rb', line 100
def (row, lang)
"/* #{row..gsub('*/', '* /')} */\n" if row.
end
|
88
89
90
|
# File 'lib/twine/formatters/apple.rb', line 88
def (lang)
"/**\n * Apple Strings File\n * Generated by Twine #{Twine::VERSION}\n * Language: #{lang}\n */"
end
|
104
105
106
|
# File 'lib/twine/formatters/apple.rb', line 104
def format_key(key)
escape_quotes(key)
end
|
92
93
94
|
# File 'lib/twine/formatters/apple.rb', line 92
def (section)
"/********** #{section.name} **********/\n"
end
|
108
109
110
|
# File 'lib/twine/formatters/apple.rb', line 108
def format_value(value)
escape_quotes(value)
end
|
#key_value_pattern ⇒ Object
96
97
98
|
# File 'lib/twine/formatters/apple.rb', line 96
def key_value_pattern
"\"%{key}\" = \"%{value}\";\n"
end
|
#output_path_for_language(lang) ⇒ Object
30
31
32
|
# File 'lib/twine/formatters/apple.rb', line 30
def output_path_for_language(lang)
"#{lang}.lproj"
end
|
#read_file(path, lang) ⇒ Object
34
35
36
37
38
39
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/twine/formatters/apple.rb', line 34
def read_file(path, lang)
encoding = Twine::Encoding.encoding_for_path(path)
sep = nil
if !encoding.respond_to?(:encode)
if encoding.end_with? 'LE'
sep = "\x0a\x00"
elsif encoding.end_with? 'BE'
sep = "\x00\x0a"
else
sep = "\n"
end
end
if encoding.index('UTF-16')
mode = "rb:#{encoding}"
else
mode = "r:#{encoding}"
end
File.open(path, mode) do |f|
= nil
while line = (sep) ? f.gets(sep) : f.gets
if encoding.index('UTF-16')
if line.respond_to? :encode!
line.encode!('UTF-8')
else
require 'iconv'
line = Iconv.iconv('UTF-8', encoding, line).join
end
end
match = /"((?:[^"\\]|\\.)+)"\s*=\s*"((?:[^"\\]|\\.)*)"/.match(line)
if match
key = match[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
end
|