-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathMergeLocalizations
executable file
·43 lines (31 loc) · 1.14 KB
/
MergeLocalizations
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
#!/usr/bin/env ruby
require 'fileutils'
require 'osx/cocoa'
require 'yaml'
SRCROOT = ENV['SRCROOT'] || '.'
LOCALES_DIR = ENV['LOCALES_DIR'] || File.join(SRCROOT, 'Locales')
Dir.open(LOCALES_DIR) do |d|
# non-hidden (non-.) directories, and dirs not starting with '_' are locales
LOCALES = d.entries.select do |x|
x.match(/^[^\._]/) and File.directory?(File.join(LOCALES_DIR, x))
end
end
LOCALES.each do |l|
next if ARGV.length > 0 and not ARGV.include? l
locale_dir = File.join(LOCALES_DIR, l)
locale_yaml_file = File.join(LOCALES_DIR, l + ".yaml")
committed_localizations = YAML::load_file(locale_yaml_file)
Dir.open(locale_dir).each do |file|
next unless file =~ /\.strings$/
its_strings = committed_localizations[file]
strings_file = File.join(locale_dir, file)
d = OSX::NSDictionary.dictionaryWithContentsOfFile strings_file
d.each do |k, v|
its_strings[k.to_s] = v.to_s unless its_strings[k.to_s]
end
newD = OSX::NSDictionary.dictionaryWithDictionary its_strings
File.open(strings_file, 'w') do |io|
io << newD.descriptionInStringsFileFormat.to_s
end
end
end