Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 117 lines (90 sloc) 3.43 KB
#!/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)