babelyoda 1.6.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +5 -0
- data/CHANGELOG +1 -0
- data/Gemfile +6 -0
- data/LICENSE +1 -1
- data/README.rdoc +2 -2
- data/Rakefile +1 -0
- data/babelyoda.gemspec +28 -0
- data/lib/babelyoda/file.rb +20 -0
- data/lib/babelyoda/genstrings.rb +27 -0
- data/lib/babelyoda/git.rb +99 -0
- data/lib/babelyoda/git_versions.rb +39 -0
- data/lib/babelyoda/ibtool.rb +51 -0
- data/lib/babelyoda/keyset.rb +58 -0
- data/lib/babelyoda/localization_key.rb +56 -0
- data/lib/babelyoda/localization_value.rb +26 -0
- data/lib/babelyoda/logger.rb +16 -0
- data/lib/babelyoda/rake.rb +10 -0
- data/lib/babelyoda/specification.rb +40 -0
- data/lib/babelyoda/specification_loader.rb +35 -0
- data/lib/babelyoda/strings.rb +64 -8
- data/lib/babelyoda/strings_lexer.rb +12 -0
- data/lib/babelyoda/strings_parser.rb +72 -0
- data/lib/babelyoda/tanker.rb +190 -0
- data/lib/babelyoda/version.rb +3 -0
- data/lib/babelyoda/xib.rb +94 -0
- data/lib/babelyoda.rb +207 -0
- data/templates/Babelfile.erb +15 -0
- metadata +162 -70
- data/VERSION +0 -1
- data/bin/babelyoda +0 -399
- data/data/empty.strings +0 -1
- data/lib/babelyoda/options.rb +0 -42
metadata
CHANGED
@@ -1,93 +1,185 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: babelyoda
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
6
|
-
- 1
|
7
|
-
- 6
|
8
|
-
- 0
|
9
|
-
version: 1.6.0
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.0.0
|
5
|
+
prerelease:
|
10
6
|
platform: ruby
|
11
|
-
authors:
|
7
|
+
authors:
|
12
8
|
- Andrey Subbotin
|
13
9
|
autorequire:
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
12
|
+
date: 2012-01-19 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: &70123403021020 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '2.8'
|
22
|
+
- - ! '>='
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 2.8.0
|
25
|
+
type: :development
|
23
26
|
prerelease: false
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
27
|
+
version_requirements: *70123403021020
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: awesome_print
|
30
|
+
requirement: &70123403019300 !ruby/object:Gem::Requirement
|
31
|
+
none: false
|
32
|
+
requirements:
|
33
|
+
- - ~>
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '1.0'
|
36
|
+
- - ! '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: 1.0.2
|
39
|
+
type: :runtime
|
40
|
+
prerelease: false
|
41
|
+
version_requirements: *70123403019300
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: rake
|
44
|
+
requirement: &70123403017960 !ruby/object:Gem::Requirement
|
45
|
+
none: false
|
46
|
+
requirements:
|
47
|
+
- - ~>
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0.9'
|
50
|
+
- - ! '>='
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: 0.9.2.2
|
53
|
+
type: :runtime
|
54
|
+
prerelease: false
|
55
|
+
version_requirements: *70123403017960
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: active_support
|
58
|
+
requirement: &70123402999880 !ruby/object:Gem::Requirement
|
59
|
+
none: false
|
60
|
+
requirements:
|
61
|
+
- - ~>
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '3.0'
|
64
|
+
- - ! '>='
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: 3.0.0
|
67
|
+
type: :runtime
|
68
|
+
prerelease: false
|
69
|
+
version_requirements: *70123402999880
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: rchardet19
|
72
|
+
requirement: &70123402998780 !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '1.3'
|
78
|
+
- - ! '>='
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: 1.3.5
|
31
81
|
type: :runtime
|
32
|
-
version_requirements: *id001
|
33
|
-
- !ruby/object:Gem::Dependency
|
34
|
-
name: term-ansicolor
|
35
82
|
prerelease: false
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
83
|
+
version_requirements: *70123402998780
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: builder
|
86
|
+
requirement: &70123402997800 !ruby/object:Gem::Requirement
|
87
|
+
none: false
|
88
|
+
requirements:
|
89
|
+
- - ~>
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '3.0'
|
92
|
+
- - ! '>='
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: 3.0.0
|
43
95
|
type: :runtime
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
96
|
+
prerelease: false
|
97
|
+
version_requirements: *70123402997800
|
98
|
+
- !ruby/object:Gem::Dependency
|
99
|
+
name: nokogiri
|
100
|
+
requirement: &70123402996700 !ruby/object:Gem::Requirement
|
101
|
+
none: false
|
102
|
+
requirements:
|
103
|
+
- - ~>
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '1.5'
|
106
|
+
- - ! '>='
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: 1.5.0
|
109
|
+
type: :runtime
|
110
|
+
prerelease: false
|
111
|
+
version_requirements: *70123402996700
|
112
|
+
- !ruby/object:Gem::Dependency
|
113
|
+
name: term-ansicolor
|
114
|
+
requirement: &70123402995660 !ruby/object:Gem::Requirement
|
115
|
+
none: false
|
116
|
+
requirements:
|
117
|
+
- - ~>
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '1.0'
|
120
|
+
- - ! '>='
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: 1.0.7
|
123
|
+
type: :runtime
|
124
|
+
prerelease: false
|
125
|
+
version_requirements: *70123402995660
|
126
|
+
description: A simple utility to push/pull l10n resources of an Xcode project to/from
|
127
|
+
the translators
|
128
|
+
email:
|
129
|
+
- andrey@subbotin.me
|
130
|
+
executables: []
|
49
131
|
extensions: []
|
50
|
-
|
51
|
-
|
52
|
-
-
|
53
|
-
- README.rdoc
|
54
|
-
files:
|
132
|
+
extra_rdoc_files: []
|
133
|
+
files:
|
134
|
+
- .gitignore
|
55
135
|
- CHANGELOG
|
136
|
+
- Gemfile
|
56
137
|
- LICENSE
|
57
138
|
- README.rdoc
|
58
|
-
-
|
59
|
-
-
|
60
|
-
- lib/babelyoda
|
139
|
+
- Rakefile
|
140
|
+
- babelyoda.gemspec
|
141
|
+
- lib/babelyoda.rb
|
142
|
+
- lib/babelyoda/file.rb
|
143
|
+
- lib/babelyoda/genstrings.rb
|
144
|
+
- lib/babelyoda/git.rb
|
145
|
+
- lib/babelyoda/git_versions.rb
|
146
|
+
- lib/babelyoda/ibtool.rb
|
147
|
+
- lib/babelyoda/keyset.rb
|
148
|
+
- lib/babelyoda/localization_key.rb
|
149
|
+
- lib/babelyoda/localization_value.rb
|
150
|
+
- lib/babelyoda/logger.rb
|
151
|
+
- lib/babelyoda/rake.rb
|
152
|
+
- lib/babelyoda/specification.rb
|
153
|
+
- lib/babelyoda/specification_loader.rb
|
61
154
|
- lib/babelyoda/strings.rb
|
62
|
-
|
155
|
+
- lib/babelyoda/strings_lexer.rb
|
156
|
+
- lib/babelyoda/strings_parser.rb
|
157
|
+
- lib/babelyoda/tanker.rb
|
158
|
+
- lib/babelyoda/version.rb
|
159
|
+
- lib/babelyoda/xib.rb
|
160
|
+
- templates/Babelfile.erb
|
63
161
|
homepage: http://github.com/eploko/babelyoda
|
64
162
|
licenses: []
|
65
|
-
|
66
163
|
post_install_message:
|
67
|
-
rdoc_options:
|
68
|
-
|
69
|
-
require_paths:
|
164
|
+
rdoc_options: []
|
165
|
+
require_paths:
|
70
166
|
- lib
|
71
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
requirements:
|
80
|
-
- -
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
|
83
|
-
- 0
|
84
|
-
version: "0"
|
167
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
168
|
+
none: false
|
169
|
+
requirements:
|
170
|
+
- - ! '>='
|
171
|
+
- !ruby/object:Gem::Version
|
172
|
+
version: '0'
|
173
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
174
|
+
none: false
|
175
|
+
requirements:
|
176
|
+
- - ! '>='
|
177
|
+
- !ruby/object:Gem::Version
|
178
|
+
version: '0'
|
85
179
|
requirements: []
|
86
|
-
|
87
|
-
|
88
|
-
rubygems_version: 1.3.6
|
180
|
+
rubyforge_project: babelyoda
|
181
|
+
rubygems_version: 1.8.10
|
89
182
|
signing_key:
|
90
183
|
specification_version: 3
|
91
|
-
summary:
|
184
|
+
summary: Xcode project localization made easy
|
92
185
|
test_files: []
|
93
|
-
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
1.6.0
|
data/bin/babelyoda
DELETED
@@ -1,399 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'rubygems'
|
4
|
-
require 'fileutils'
|
5
|
-
require 'term/ansicolor'
|
6
|
-
require 'tmpdir'
|
7
|
-
require 'yaml'
|
8
|
-
|
9
|
-
include Term::ANSIColor
|
10
|
-
|
11
|
-
require 'babelyoda/options'
|
12
|
-
require 'babelyoda/strings'
|
13
|
-
|
14
|
-
# Main block
|
15
|
-
|
16
|
-
def main
|
17
|
-
$config = BabelYoda::Options.parse
|
18
|
-
setup
|
19
|
-
print_config
|
20
|
-
prepare_folders
|
21
|
-
init_lproj_dirs
|
22
|
-
apply_incremental_translations
|
23
|
-
gen_src_code_strings
|
24
|
-
extract_untranslated_src_code_strings
|
25
|
-
gen_src_xib_strings
|
26
|
-
extract_untranslated_src_xib_strings
|
27
|
-
localize_xibs_incrementally
|
28
|
-
pack_tmp_lproj
|
29
|
-
push_tmp_lproj
|
30
|
-
FileUtils.rm_rf $config['tmp_dir'], :verbose => true
|
31
|
-
success "All done!"
|
32
|
-
end
|
33
|
-
|
34
|
-
# Aux methods
|
35
|
-
|
36
|
-
def setup
|
37
|
-
global_config_filename = File.expand_path('~/.babelyoda')
|
38
|
-
$config.merge!(YAML.load_file(global_config_filename)) if File.exist?(global_config_filename)
|
39
|
-
config = YAML.load_file($config['rules'])
|
40
|
-
config['tmp_dir'] = File.join Dir.tmpdir, "epl.babelyoda.#{$$}"
|
41
|
-
config['src_dir'] = File.join config['tmp_dir'], 'src'
|
42
|
-
config['startwd'] = Dir.getwd
|
43
|
-
config['src_lang_lproj'] = config['src_lang'] + '.lproj'
|
44
|
-
config['src_lang_lproj_dir'] = File.join(config['strings_folder'], config['src_lang_lproj'])
|
45
|
-
config['src_lang_code_strings_file'] = File.join(config['src_lang_lproj_dir'], 'Localizable.strings')
|
46
|
-
config['initial_strings_file'] = File.join(config['strings_folder'], 'Localizable.strings')
|
47
|
-
$config.merge!(config)
|
48
|
-
$config['products_folder'] = File.expand_path($config['products_folder'])
|
49
|
-
$config['time_badge'] = Time.now.utc.strftime('%Y%m%d_%H%M')
|
50
|
-
end
|
51
|
-
|
52
|
-
def print_config ; status "CONFIG" ; y $config ; end
|
53
|
-
def exe(cmd) ; putcmd cmd ; system cmd ; end
|
54
|
-
def putcmd(cmd) ; print magenta, "CMD: #{cmd}", reset, "\n" ; end
|
55
|
-
def status(msg) ; print blue, "--- #{msg} ---", reset, "\n" ; end
|
56
|
-
def success(msg) ; print green, bold, 'SUCCESS: ', msg, reset, "\n" ; end
|
57
|
-
def error(msg) ; print red, bold, 'ERROR: ', msg, reset, "\n" ; exit 1 ; end
|
58
|
-
def escape_cmd_args(args) ; args.collect{ |arg| "'#{arg}'"}.join(' ') ; end
|
59
|
-
|
60
|
-
# Globbers
|
61
|
-
|
62
|
-
def all_languages
|
63
|
-
result = Array.new
|
64
|
-
result << $config['languages']
|
65
|
-
result << $config['src_lang']
|
66
|
-
result.flatten!.sort!
|
67
|
-
end
|
68
|
-
|
69
|
-
def all_lproj_dirs
|
70
|
-
result = Array.new
|
71
|
-
result << dst_lproj_dirs
|
72
|
-
result << src_lproj_dir
|
73
|
-
result.flatten!.sort!
|
74
|
-
end
|
75
|
-
|
76
|
-
def src_lproj_dir
|
77
|
-
$config['src_lang_lproj_dir']
|
78
|
-
end
|
79
|
-
|
80
|
-
def dst_lproj_dirs
|
81
|
-
$config['languages'].collect{ |l|
|
82
|
-
lproj_dir_for_lang(l)
|
83
|
-
}.sort!
|
84
|
-
end
|
85
|
-
|
86
|
-
def lproj_dir_for_lang(lang)
|
87
|
-
File.join($config['strings_folder'], "#{lang}.lproj")
|
88
|
-
end
|
89
|
-
|
90
|
-
def tmp_lproj_dir_for_lang(lang)
|
91
|
-
File.join($config['tmp_dir'], "#{lang}.lproj")
|
92
|
-
end
|
93
|
-
|
94
|
-
def src_code_files
|
95
|
-
$config['folders'].collect{ |dir|
|
96
|
-
Dir.glob(File.join(dir, '**', '*.{c,h,m,hh,mm}'))
|
97
|
-
}.flatten!.sort!
|
98
|
-
end
|
99
|
-
|
100
|
-
def dst_code_strings_files
|
101
|
-
$config['languages'].collect{ |l|
|
102
|
-
File.join(lproj_dir_for_lang(l), 'Localizable.strings')
|
103
|
-
}.sort!
|
104
|
-
end
|
105
|
-
|
106
|
-
def all_code_strings_files
|
107
|
-
result = Array.new
|
108
|
-
result << dst_code_strings_files
|
109
|
-
result << $config['src_lang_code_strings_file']
|
110
|
-
result.flatten!.sort!
|
111
|
-
end
|
112
|
-
|
113
|
-
def xib_files_for_lang(lang)
|
114
|
-
$config['folders'].collect{ |dir|
|
115
|
-
Dir.glob(File.join(dir, '**', lang + '.lproj', '*.xib'))
|
116
|
-
}.flatten!.sort!
|
117
|
-
end
|
118
|
-
|
119
|
-
def dst_xib_files
|
120
|
-
$config['languages'].collect{ |lang|
|
121
|
-
xib_files_for_lang(lang)
|
122
|
-
}.flatten!.sort!
|
123
|
-
end
|
124
|
-
|
125
|
-
def src_xib_files
|
126
|
-
xib_files_for_lang($config['src_lang'])
|
127
|
-
end
|
128
|
-
|
129
|
-
def strings_files_for_lang(lang)
|
130
|
-
$config['folders'].collect{ |dir|
|
131
|
-
Dir.glob(File.join(dir, '**', lang + '.lproj', '*.strings'))
|
132
|
-
}.flatten!.sort!
|
133
|
-
end
|
134
|
-
|
135
|
-
def all_strings_files
|
136
|
-
all_languages.collect{ |lang| strings_files_for_lang(lang) }.flatten!.sort!
|
137
|
-
end
|
138
|
-
|
139
|
-
def strings_file_for_xib_lang(xib, lang)
|
140
|
-
parts = File.split(xib)
|
141
|
-
lang_split = File.split(parts[-2])
|
142
|
-
lang_split[-1] = lang + '.lproj'
|
143
|
-
parts[-2] = File.join(lang_split)
|
144
|
-
parts[-1] = parts[-1].slice(0, parts[-1].length - 4) + '.strings'
|
145
|
-
result = File.join(parts)
|
146
|
-
result
|
147
|
-
end
|
148
|
-
|
149
|
-
def xib_file_for_xib_lang(xib, lang)
|
150
|
-
xib_filename = File.split(xib).last
|
151
|
-
parts = File.split(xib)
|
152
|
-
lang_split = File.split(parts[-2])
|
153
|
-
lang_split[-1] = lang + '.lproj'
|
154
|
-
parts[-2] = File.join(lang_split)
|
155
|
-
File.join(parts)
|
156
|
-
end
|
157
|
-
|
158
|
-
def strings_files_for_xib(xib)
|
159
|
-
all_languages.each.collect { |lang| strings_file_for_xib_lang(xib, lang) }
|
160
|
-
end
|
161
|
-
|
162
|
-
# Globs all incremental translations for the given .strings file and language.
|
163
|
-
def incremental_translations(file, lang)
|
164
|
-
filename = File.split(file).last
|
165
|
-
mask = "#{$config['prefix']}_*_*_#{lang}_#{filename}"
|
166
|
-
Dir.glob(File.join($config['incremental_translations_folder'], mask)).sort!
|
167
|
-
end
|
168
|
-
|
169
|
-
# Processing
|
170
|
-
|
171
|
-
def prepare_folders
|
172
|
-
status "PREPARING FOLDERS"
|
173
|
-
FileUtils.mkdir_p $config['incremental_translations_folder'], :verbose => true
|
174
|
-
FileUtils.mkdir_p $config['old_xibs_folder'], :verbose => true
|
175
|
-
FileUtils.mkdir_p File.join($config['tmp_dir'], 'zips'), :verbose => true
|
176
|
-
make_tmp_lproj_dirs
|
177
|
-
end
|
178
|
-
|
179
|
-
def make_tmp_lproj_dirs
|
180
|
-
FileUtils.mkdir_p tmp_lproj_dir_for_lang($config['src_lang']), :verbose => true
|
181
|
-
FileUtils.mkdir_p $config['languages'].sort.collect{ |lang| tmp_lproj_dir_for_lang(lang) }, :verbose => true
|
182
|
-
end
|
183
|
-
|
184
|
-
def init_lproj_dirs
|
185
|
-
status "PREPARING LPROJ FOLDERS"
|
186
|
-
if File.exists?($config['initial_strings_file']) && File.exists?($config['src_lang_code_strings_file'])
|
187
|
-
error "Both '#{$config['initial_strings_file']}' and '#{$config['src_lang_code_strings_file']}' exist!"
|
188
|
-
end
|
189
|
-
FileUtils.mkdir_p all_lproj_dirs, :verbose => true
|
190
|
-
end
|
191
|
-
|
192
|
-
# Iterate over all the .strings files and apply
|
193
|
-
# all the translations found for each in the
|
194
|
-
# incremental translations folder.
|
195
|
-
def apply_incremental_translations
|
196
|
-
all_languages.each do |lang|
|
197
|
-
strings_files_for_lang(lang).each do |strings_file|
|
198
|
-
status "APPLYING INCREMENTAL TRANSLATIONS FOR '#{strings_file}'"
|
199
|
-
incremental_translations(strings_file, lang).each do |translation|
|
200
|
-
combine_strings(translation, strings_file)
|
201
|
-
end
|
202
|
-
end
|
203
|
-
end
|
204
|
-
end
|
205
|
-
|
206
|
-
# Generate .strings file into the temporary directory,
|
207
|
-
# touch the target file so it's created if it didn't exist,
|
208
|
-
# and then merge it with the new file, preserving any translations made.
|
209
|
-
def gen_src_code_strings
|
210
|
-
status "GENERATING STRINGS FILE FOR THE SOURCE LANGUAGE"
|
211
|
-
genstrings src_code_files, $config['tmp_dir']
|
212
|
-
tmp_strings_file = File.join($config['tmp_dir'], 'Localizable.strings')
|
213
|
-
merge_strings tmp_strings_file, all_code_strings_files
|
214
|
-
end
|
215
|
-
|
216
|
-
def genstrings(files, output_path)
|
217
|
-
files_safe = escape_cmd_args(files)
|
218
|
-
rc = exe "genstrings -o '#{output_path}' #{files_safe}"
|
219
|
-
error "Failed to generate strings" unless rc
|
220
|
-
strings_file = File.join(output_path, 'Localizable.strings')
|
221
|
-
BabelYoda::StringsHelper.safe_init_strings_file strings_file
|
222
|
-
end
|
223
|
-
|
224
|
-
def gen_src_xib_strings
|
225
|
-
status "GENERATING STRINGS FILES FOR THE SOURCE LANGUAGE XIBS"
|
226
|
-
src_xib_files.each do |xib|
|
227
|
-
tmp_strings_file = gen_xib_strings xib
|
228
|
-
merge_strings tmp_strings_file, strings_files_for_xib(xib)
|
229
|
-
end
|
230
|
-
end
|
231
|
-
|
232
|
-
def tmp_filename_for_xib_strings(xib)
|
233
|
-
xib_filename = File.split(xib).last
|
234
|
-
strings_filename = xib_filename.slice(0, xib.length - 4) + '.strings'
|
235
|
-
File.join($config['tmp_dir'], strings_filename)
|
236
|
-
end
|
237
|
-
|
238
|
-
def gen_xib_strings(xib)
|
239
|
-
strings = tmp_filename_for_xib_strings(xib)
|
240
|
-
rc = exe "ibtool --generate-strings-file '#{strings}' '#{xib}'"
|
241
|
-
error "Failed to generate strings for file '#{xib}'" unless rc
|
242
|
-
BabelYoda::StringsHelper.safe_init_strings_file strings
|
243
|
-
strings
|
244
|
-
end
|
245
|
-
|
246
|
-
def merge_strings(src_strings, dst_strings)
|
247
|
-
targets = dst_strings.is_a?(String) ? [dst_strings] : dst_strings
|
248
|
-
puts "DST_STRINGS: #{dst_strings}"
|
249
|
-
targets.each do |target|
|
250
|
-
status "MERGING STRINGS AT '#{src_strings}' INTO '#{target}'"
|
251
|
-
FileUtils.mkdir_p File.split(target)[0], :verbose => true
|
252
|
-
if File.exists? target
|
253
|
-
rc = exe "wincent-strings-util --base '#{src_strings}' --merge '#{target}' --output '#{target}'"
|
254
|
-
error "Failed to merge '#{src_strings}' into '#{target}'" unless rc
|
255
|
-
else
|
256
|
-
FileUtils.cp src_strings, target, :verbose => true
|
257
|
-
end
|
258
|
-
end
|
259
|
-
end
|
260
|
-
|
261
|
-
def extract_untranslated_src_code_strings
|
262
|
-
tmp_strings_file = File.join($config['tmp_dir'], 'Localizable.strings')
|
263
|
-
$config['languages'].sort.each do |lang|
|
264
|
-
src_file = File.join(lproj_dir_for_lang(lang), 'Localizable.strings')
|
265
|
-
dst_file = File.join(tmp_lproj_dir_for_lang(lang), mangled_name('Localizable.strings', lang))
|
266
|
-
status "EXTRACTING UNTRANSLATED STRINGS FROM '#{src_file}' TO '#{dst_file}'"
|
267
|
-
rc = exe "wincent-strings-util --base '#{tmp_strings_file}' --extract '#{src_file}' --output '#{dst_file}'"
|
268
|
-
error "Failed to extract untranslated string from '#{src_file}' into '#{dst_file}' based on '#{tmp_strings_file}'" unless rc
|
269
|
-
end
|
270
|
-
end
|
271
|
-
|
272
|
-
def extract_untranslated_src_xib_strings
|
273
|
-
src_xib_files.each do |xib|
|
274
|
-
tmp_strings_file = tmp_filename_for_xib_strings(xib)
|
275
|
-
$config['languages'].sort.each do |lang|
|
276
|
-
src_file = strings_file_for_xib_lang(xib, lang)
|
277
|
-
src_filename = File.split(src_file).last
|
278
|
-
dst_file = File.join(tmp_lproj_dir_for_lang(lang), mangled_name(src_filename, lang))
|
279
|
-
|
280
|
-
status "EXTRACTING UNTRANSLATED STRINGS FROM '#{src_file}' TO '#{dst_file}'"
|
281
|
-
rc = exe "wincent-strings-util --base '#{tmp_strings_file}' --extract '#{src_file}' --output '#{dst_file}'"
|
282
|
-
error "Failed to extract untranslated string from '#{src_file}' into '#{dst_file}' based on '#{tmp_strings_file}'" unless rc
|
283
|
-
end
|
284
|
-
end
|
285
|
-
end
|
286
|
-
|
287
|
-
def combine_strings(incremental_strings, old_strings)
|
288
|
-
status "COMBINING STRINGS FROM '#{incremental_strings}' INTO '#{old_strings}'"
|
289
|
-
FileUtils.touch old_strings
|
290
|
-
rc = exe "wincent-strings-util --base '#{old_strings}' --combine '#{incremental_strings}' --output '#{old_strings}'"
|
291
|
-
error "Failed to combine '#{incremental_strings}' into '#{old_strings}'" unless rc
|
292
|
-
end
|
293
|
-
|
294
|
-
def pack_tmp_lproj
|
295
|
-
# Copy the source language Localizable.strings into the temporary lproj folder.
|
296
|
-
status "COPYING STRINGS FILE FOR '#{$config['src_lang']}'"
|
297
|
-
FileUtils.cp $config['src_lang_code_strings_file'],
|
298
|
-
File.join(tmp_lproj_dir_for_lang($config['src_lang']), mangled_name('Localizable.strings', $config['src_lang'])),
|
299
|
-
:verbose => true
|
300
|
-
|
301
|
-
src_xib_files.each do |xib|
|
302
|
-
strings = strings_file_for_xib_lang(xib, $config['src_lang'])
|
303
|
-
strings_filename = File.split(strings).last
|
304
|
-
FileUtils.cp strings,
|
305
|
-
File.join(tmp_lproj_dir_for_lang($config['src_lang']), mangled_name(strings_filename, $config['src_lang'])),
|
306
|
-
:verbose => true
|
307
|
-
end
|
308
|
-
|
309
|
-
# Pack all the temporary lproj folders.
|
310
|
-
all_languages.sort.each do |lang|
|
311
|
-
status "PACKING RESOURCES FOR '#{lang}'"
|
312
|
-
FileUtils.cd(tmp_lproj_dir_for_lang(lang), :verbose => true) do |dir|
|
313
|
-
|
314
|
-
# Get rid of empty files
|
315
|
-
Dir.glob(File.join(dir, '**', '*.strings')).flatten.sort.each do |tmp_strings_file|
|
316
|
-
FileUtils.rm_rf(tmp_strings_file, :verbose => true) unless File.size?(tmp_strings_file) > 2
|
317
|
-
end
|
318
|
-
|
319
|
-
rc = exe "zip -r -9 -y '../zips/#{zipname_for_lang(lang)}' *"
|
320
|
-
error "Failed to pack resources for '#{lang}'" unless rc
|
321
|
-
end
|
322
|
-
end
|
323
|
-
end
|
324
|
-
|
325
|
-
def push_tmp_lproj
|
326
|
-
# Move all zips from the temporary lproj folder into the products folder (e.g. ~/Desktop).
|
327
|
-
FileUtils.mv Dir.glob(File.join($config['tmp_dir'], 'zips', '*.zip')), $config['products_folder'], :verbose => true
|
328
|
-
end
|
329
|
-
|
330
|
-
# Generates a mangled filename for the given file and language.
|
331
|
-
def mangled_name(file, lang)
|
332
|
-
"#{$config['prefix']}_#{$config['time_badge']}_#{lang}_#{file}"
|
333
|
-
end
|
334
|
-
|
335
|
-
# Genarates ZIP file name for the given language
|
336
|
-
def zipname_for_lang(lang)
|
337
|
-
"#{$config['prefix']}_#{$config['time_badge']}_#{lang}_Localization.zip"
|
338
|
-
end
|
339
|
-
|
340
|
-
def localize_xibs_incrementally
|
341
|
-
# ibtool
|
342
|
-
# --previous-file path_to_project/English.lproj/MainWindow.old.xib # old_dst_xib
|
343
|
-
# --incremental-file path_to_project/fr.lproj/MainWindow.old.xib # old_src_xib
|
344
|
-
# --strings-file path_to_strings/fr/MainWindow.strings # dst_strings
|
345
|
-
# --localize-incremental
|
346
|
-
# --write path_to_project/fr.lproj/MainWindow.xib # dst_xib
|
347
|
-
# path_to_project/English.lproj/MainWindow.new.xib # src_xib
|
348
|
-
|
349
|
-
$config['languages'].sort.each do |lang|
|
350
|
-
puts "XIB-LANG: #{lang}"
|
351
|
-
xib_files_for_lang(lang).each do |dst_xib|
|
352
|
-
puts "XIB-DST: #{dst_xib}"
|
353
|
-
dst_strings = dst_xib.slice(0, dst_xib.length - 4) + '.strings'
|
354
|
-
src_xib = xib_file_for_xib_lang(dst_xib, $config['src_lang'])
|
355
|
-
old_src_xib = old_xib_for_xib_lang(src_xib, $config['src_lang'])
|
356
|
-
FileUtils.cp src_xib, old_src_xib, :preserve => true, :verbose => true
|
357
|
-
FileUtils.cp src_xib, dst_xib, :preserve => true, :verbose => true
|
358
|
-
old_dst_xib = old_xib_for_xib_lang(dst_xib, lang)
|
359
|
-
FileUtils.cp dst_xib, old_dst_xib, :preserve => true, :verbose => true
|
360
|
-
|
361
|
-
BabelYoda::StringsHelper.safe_init_strings_file dst_strings
|
362
|
-
|
363
|
-
ncmd = ['ibtool', '--previous-file', "'#{old_dst_xib}'",
|
364
|
-
'--incremental-file', "'#{old_src_xib}'",
|
365
|
-
'--strings-file', "'#{dst_strings}'",
|
366
|
-
'--localize-incremental',
|
367
|
-
'--write', "#{dst_xib}",
|
368
|
-
"#{src_xib}"].join(' ')
|
369
|
-
rc = exe ncmd
|
370
|
-
error "Failed to localize a XIB incrementally" unless rc
|
371
|
-
end
|
372
|
-
end
|
373
|
-
end
|
374
|
-
|
375
|
-
def xib_file_for_xib_lang(xib, lang)
|
376
|
-
xib_filename = File.split(xib).last
|
377
|
-
parts = File.split(xib)
|
378
|
-
lang_split = File.split(parts[-2])
|
379
|
-
lang_split[-1] = lang + '.lproj'
|
380
|
-
parts[-2] = File.join(lang_split)
|
381
|
-
result = File.join(parts)
|
382
|
-
unless lang == $config['src_lang']
|
383
|
-
FileUtils.cp xib_file_for_xib_lang(xib, $config['src_lang']),
|
384
|
-
result, :preserve => true, :verbose => true
|
385
|
-
end
|
386
|
-
result
|
387
|
-
end
|
388
|
-
|
389
|
-
def mangled_old_xib_name(xib, lang)
|
390
|
-
file = File.split(xib).last
|
391
|
-
File.join($config['old_xibs_folder'], "#{$config['prefix']}_OLD_#{lang}_#{file}")
|
392
|
-
end
|
393
|
-
|
394
|
-
def old_xib_for_xib_lang(xib, lang)
|
395
|
-
mangled_old_xib_filename = mangled_old_xib_name(xib, lang)
|
396
|
-
end
|
397
|
-
|
398
|
-
main
|
399
|
-
exit 0
|
data/data/empty.strings
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
��
|