-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathCollectStrings
executable file
·116 lines (90 loc) · 3.43 KB
/
CollectStrings
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/usr/bin/env ruby
require 'find'
require 'fileutils'
require 'yaml'
require 'osx/cocoa'
SRCROOT = ENV['SRCROOT'] || '.'
ISO_NAMED_DIR = File.join(SRCROOT, 'en.lproj')
NEXT_NAMED_DIR = File.join(SRCROOT, 'English.lproj')
BASE_LOCALE_DIR =
(ENV['BASE_LOCALE_DIR']) ||
(NEXT_NAMED_DIR if File.directory? NEXT_NAMED_DIR) ||
(ISO_NAMED_DIR if File.directory? ISO_NAMED_DIR)
if not BASE_LOCALE_DIR
$stderr.puts "error: No base locale directory found to take original data from. Set one via the BASE_LOCALE_DIR environment variabile or make sure en.lproj or English.lproj exist."
end
TARGET = ENV['TARGET']
if not TARGET
$stderr.puts "error: No target directory found to save the collected strings in. Set one via the TARGET environment variable."
exit 1
end
def run_and_wait(*args)
fork do
exec(*args)
end
Process.wait
end
filesToRunGenstringsOn = []
TARGET_FULL = File.expand_path(TARGET)
# argv = ARGV.empty? ? %w{.} : ARGV
if ENV['ILABS_L0ShowOnRequestLogging'] == 'YES'
$stderr.puts "debug: SRCROOT is #{SRCROOT}"
$stderr.puts "debug: SRCROOT is #{BASE_LOCALE_DIR}"
$stderr.puts "debug: TARGET is #{TARGET}"
end
Find.find(SRCROOT) do |file|
next if File.expand_path(file)[0, TARGET_FULL.length] == TARGET_FULL
fileName = File.basename file
case fileName
when /\.m$/, /\.c$/
filesToRunGenstringsOn << file
when /\.alert$/
# L0Alert files we know the format ourselves :)
alertContents = OSX::NSDictionary.dictionaryWithContentsOfFile(file)
alertStrings = {}
message = alertContents['L0AlertMessage']
alertStrings[message] = message if message
informativeText = alertContents['L0AlertInformativeText']
alertStrings[informativeText] = informativeText if informativeText
if alertContents['L0AlertButtons']
alertContents['L0AlertButtons'].each do |button|
alertStrings[button] = button
end
end
suppressionButtonTitle = alertContents['L0AlertSuppressionButtonTitle']
alertStrings[suppressionButtonTitle] = suppressionButtonTitle if suppressionButtonTitle
alertStringsAsNSDictionary = OSX::NSDictionary.dictionaryWithDictionary(alertStrings)
stringsFileContents = alertStringsAsNSDictionary.descriptionInStringsFileFormat
stringsFile = File.join TARGET, fileName[0, fileName.length - 'alert'.length] + 'strings'
File.open(stringsFile, 'w') do |io|
io << stringsFileContents
end
when /\.loc\.yaml$/
File.open(file) do |file_io|
YAML::each_document(file_io) do |contents|
dict = OSX::NSMutableDictionary.dictionary
contents.each_key do |k|
dict[k] = contents[k]
end
stringsFile = File.join TARGET, fileName[0, fileName.length - 'loc.yaml'.length] + 'strings'
File.open(stringsFile, 'w') do |io|
io << dict.descriptionInStringsFileFormat
end
end
end
when /\.loc\./
target = File.join(TARGET, fileName)
FileUtils.rm target if File.exist? target
FileUtils.cp file, target
end
end
Find.find(BASE_LOCALE_DIR) do |file|
if file =~ /\.nib$/ or file =~ /.xib$/ and not (File.dirname(file) =~ /\.nib$/)
fileName = File.basename(file)
stringFile = File.join TARGET, fileName + '.strings'
run_and_wait '/usr/bin/ibtool', '--generate-strings-file', stringFile, file
end
end
command_line = ['/usr/bin/genstrings', '-o', TARGET]
command_line.push(*filesToRunGenstringsOn)
run_and_wait(*command_line)