blob: 5a655df39cec5f293a5a843358948882e8c1f098 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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
87
88
89
90
91
92
93
94
95
96
97
|
module Twine
module Formatters
class Apple < Abstract
def format_name
'apple'
end
def extension
'.strings'
end
def can_handle_directory?(path)
Dir.entries(path).any? { |item| /^.+\.lproj$/.match(item) }
end
def default_file_name
'Localizable.strings'
end
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
end
def output_path_for_language(lang)
"#{lang}.lproj"
end
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
def format_header(lang)
"/**\n * Apple Strings File\n * Generated by Twine #{Twine::VERSION}\n * Language: #{lang}\n */"
end
def format_section_header(section)
"/********** #{section.name} **********/\n"
end
def key_value_pattern
"\"%{key}\" = \"%{value}\";\n"
end
def format_comment(definition, lang)
"/* #{definition.comment.gsub('*/', '* /')} */\n" if definition.comment
end
def format_key(key)
escape_quotes(key)
end
def format_value(value)
escape_quotes(value)
end
def should_include_definition(definition, lang)
return !definition.is_plural? && super
end
end
end
end
Twine::Formatters.formatters << Twine::Formatters::Apple.new
|