Top Level Namespace
Defined Under Namespace
Modules: LocalizeStringFilter
Instance Method Summary
collapse
Instance Method Details
#collect_keys(strings_path) ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/localize_string_filter.rb', line 19
def collect_keys(strings_path)
strings_keys = Array.new
File.open(strings_path, "r") do |file|
file.each_line do |line|
if line.start_with? "\""
temp_array = line.split('=')
quotation_indexes = Array.new
temp_array[0].split("").each_with_index do |character, index|
if character == '"'
quotation_indexes << index
end
end
str = temp_array[0][quotation_indexes[0], quotation_indexes[1] + 1]
strings_keys << str
end
end
end
return strings_keys
end
|
#collect_missing_keys(localized_keys, swift_files) ⇒ Object
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
|
# File 'lib/localize_string_filter.rb', line 39
def collect_missing_keys(localized_keys, swift_files)
missing_keys = Array.new
percentCount = 0
localized_keys.each do |key|
the_key_is_valid = false
percentCount = percentCount + 1
precent = ((percentCount.to_f / localized_keys.count.to_f) * 10000).round / 10000.0
str = (precent * 100).to_s
puts "#{str[0,4]}% || searching key: #{key}"
swift_files.each do |swift_file|
if File.readlines(swift_file).any?{ |l| l[key] }
the_key_is_valid = true
break
end
end
if !the_key_is_valid
missing_keys << key
end
end
return missing_keys
end
|
#delete_missing_keys(missing_keys, strings_path) ⇒ Object
77
78
79
80
81
82
83
84
85
86
87
88
|
# File 'lib/localize_string_filter.rb', line 77
def delete_missing_keys(missing_keys, strings_path)
missing_keys.each do |key|
open(strings_path, 'r') do |f|
open(strings_path + '.tmp', 'w') do |f2|
f.each_line do |line|
f2.write(line) unless line.start_with? key
end
end
end
FileUtils.mv strings_path + '.tmp', strings_path
end
end
|
#output_missing_keys(missing_keys, project_path) ⇒ Object
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/localize_string_filter.rb', line 66
def output_missing_keys(missing_keys, project_path)
missing_keys_output_path = project_path + "/missing_keys.txt"
File.open(missing_keys_output_path, "w+") do |f|
missing_keys.each {
|element| f.puts(element)
}
end
puts "\n missing_keys: #{missing_keys}"
puts "check the file: #{missing_keys_output_path}"
end
|
#traverse_swift_files(file_path, swift_files) ⇒ Object
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
# File 'lib/localize_string_filter.rb', line 4
def traverse_swift_files(file_path, swift_files)
if File.directory? file_path
Dir.foreach(file_path) do |file|
if file !="." and file !=".."
traverse_swift_files(file_path+"/"+file, swift_files)
end
end
else
if (file_path.end_with? ".storyboard") || (file_path.end_with? ".swift") || (file_path.end_with? ".m") || (file_path.end_with? ".h") || (file_path.end_with? ".xib")
swift_files << file_path
end
end
end
|