xlocalize 0.3.2 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 49c020e414aa5935d3d5613c930196af1ccc3b79
4
- data.tar.gz: 43048b71638f80dd8ff958d99800bd59af82cc57
3
+ metadata.gz: 9e6235a370b56da00174d9c280585088401d844a
4
+ data.tar.gz: 53876ca5c6a807f01ebe293369ddfa7c887dff84
5
5
  SHA512:
6
- metadata.gz: 2a48bd0f91385b7e011f6f7fb3b9d5b1ae643d0bc3e4a84cf9be3dc3773b0a7432917efaccc786cc9c951aafd12b3c45acd9d9391764a8f78e38a9d31595a3ef
7
- data.tar.gz: b57cdabfaf66d11ee69a6bd73e06075bf5b135d8e5429ed2793b4ab4bec85160b851f367601a0d94a995c700cb46978cfcbf936788d2e26f43219e8a7df138ee
6
+ metadata.gz: 17522231c3f133253d025bb43b0d2cf6f57d4c66a2aeb09381563f7bff9de7529c7a34cdabbffb495ac6f3c03c4c5bf9e1185aeb4c55e86b4d0b7440e8a94050
7
+ data.tar.gz: 959b99fbd96815f24709be4ac1d394a9030b21ae3c368bada3c163ab6b2f7606da307f0d7ba6b3376c791166da5db4f61052601512331460edec0beee911d8b2
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.3.3
data/.travis.yml CHANGED
@@ -1,6 +1,5 @@
1
1
  language: ruby
2
2
  cache: bundler
3
- rvm: 2.2
4
3
  matrix:
5
4
  include:
6
5
  - {os: osx, osx_image: xcode8.3}
@@ -13,4 +12,4 @@ addons:
13
12
  repo_token: b4206ed2b9443314c998e8909dfa31f0ed476ea5ab460b98e102cd20508ff564
14
13
  after_success:
15
14
  - bundle exec codeclimate-test-reporter
16
-
15
+
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## [v0.4.0](https://github.com/viktorasl/xlocalize/releases/tag/0.4.0)
2
+
3
+ * [8e2ded3](https://github.com/viktorasl/xlocalize/commit/8e2ded3e9448edca3ed18d88be4c2c0a37122891) Removes redundant files
4
+ * [89afd2c](https://github.com/viktorasl/xlocalize/commit/89afd2c90903b78103199f9702ace16427889572) Option to exclude translation units
5
+ * [529f461](https://github.com/viktorasl/xlocalize/commit/529f4616b542cd29daa6374d74730a878789329d) Unescaping translation units if needed
6
+ * [a24dd76](https://github.com/viktorasl/xlocalize/commit/a24dd768a734a604ebc2125753453cb99d2e06b7) CLI global verbose option
7
+ * [67ae28c](https://github.com/viktorasl/xlocalize/commit/67ae28c320679391d044eb14e8df9ab7c7527ad8) CLI option to skip missing import files
8
+ * [c615725](https://github.com/viktorasl/xlocalize/commit/c615725d7b2c16e0c38df86408224fd7ddc9ee4d) Flag to allow missing files when importing
9
+
1
10
  ## [v0.3.2](https://github.com/viktorasl/xlocalize/releases/tag/0.3.2)
2
11
 
3
12
  * [d081ce2](https://github.com/viktorasl/xlocalize/commit/d081ce2640d7e8997d6d98a7659f31d571103f36) Bumps nokogiri version
@@ -16,25 +16,25 @@ module Xlocalize
16
16
  return "#{locale}.xliff"
17
17
  end
18
18
 
19
- def export_master(wti, project, targets, excl_prefix, master_lang)
19
+ def export_master(wti, project, targets, excl_prefix, master_lang, exclude_units=[])
20
20
  master_file_name = locale_file_name(master_lang)
21
21
 
22
22
  File.delete(master_file_name) if File.exist?(master_file_name)
23
23
 
24
24
  if Helper.xcode_at_least?(9)
25
- system "xcodebuild -exportLocalizations -localizationPath ./ -project #{project}"
25
+ Kernel.system "xcodebuild -exportLocalizations -localizationPath ./ -project #{project}"
26
26
  else
27
27
  # hacky way to finish xcodebuild -exportLocalizations script, because
28
28
  # since Xcode7.3 & OS X Sierra script hangs even though it produces
29
29
  # xliff output
30
30
  # http://www.openradar.me/25857436
31
- system "xcodebuild -exportLocalizations -localizationPath ./ -project #{project} & sleep 0"
31
+ Kernel.system "xcodebuild -exportLocalizations -localizationPath ./ -project #{project} & sleep 0"
32
32
  while !File.exist?(master_file_name) do
33
33
  sleep(1)
34
34
  end
35
35
  end
36
36
 
37
- purelyze(master_lang, targets, excl_prefix, project, filer_ui_duplicates=Helper.xcode_at_least?(9.3))
37
+ purelyze(master_lang, targets, excl_prefix, project, filer_ui_duplicates=Helper.xcode_at_least?(9.3), exclude_units)
38
38
  push_master_file(wti, master_lang, master_file_name) if !wti.nil?
39
39
  end
40
40
 
@@ -55,9 +55,9 @@ module Xlocalize
55
55
  end if !wti.nil?
56
56
  end
57
57
 
58
- def purelyze(locale, targets, excl_prefix, project, filer_ui_duplicates=false)
58
+ def purelyze(locale, targets, excl_prefix, project, filer_ui_duplicates=false, exclude_units)
59
59
  locale_file_name = locale_file_name(locale)
60
- doc = Nokogiri::XML(open(locale_file_name))
60
+ doc = Nokogiri::XML(File.open(locale_file_name))
61
61
 
62
62
  puts "Removing all files not matching required targets" if $VERBOSE
63
63
  doc.filter_not_target_files(targets)
@@ -65,8 +65,13 @@ module Xlocalize
65
65
  doc.filter_trans_units(excl_prefix)
66
66
  puts "Filtering plurals" if $VERBOSE
67
67
  plurals = doc.filter_plurals(project)
68
+ puts "Removing excluded translation units" if $VERBOSE
69
+ doc.xpath("//xmlns:trans-unit").each { |unit| unit.remove if exclude_units.include?(unit['id']) }
68
70
  puts "Removing all files having no trans-unit elements after removal" if $VERBOSE
69
71
  doc.filter_empty_files
72
+ puts "Unescaping translation units" if $VERBOSE
73
+ doc.unescape
74
+
70
75
  if filer_ui_duplicates
71
76
  puts "Filtering duplicate xib & storyboard translation files" if $VERBOSE
72
77
  doc.filter_duplicate_storyboard_xib_files
@@ -132,11 +137,18 @@ module Xlocalize
132
137
  return name
133
138
  end
134
139
 
135
- def import_xliff(locale)
140
+ def import_xliff(locale, allows_missing_files)
136
141
  fname = "#{locale}.xliff"
137
- puts "Importing translations from #{fname}"
138
- Nokogiri::XML(open(fname)).xpath("//xmlns:file").each do |node|
139
- File.open(localized_filename(node["original"], locale), "w") do |file|
142
+ puts "Importing translations from #{fname}" if $VERBOSE
143
+ Nokogiri::XML(File.open(fname)).xpath("//xmlns:file").each do |node|
144
+ tr_fname = localized_filename(node["original"], locale)
145
+ if !File.exist?(tr_fname)
146
+ err = "Missing #{tr_fname} file"
147
+ raise err if !allows_missing_files
148
+ puts err.yellow if $VERBOSE
149
+ next
150
+ end
151
+ File.open(tr_fname, "w") do |file|
140
152
  (node > "body > trans-unit").each do |trans_unit|
141
153
  key = trans_unit["id"]
142
154
  target = (trans_unit > "target").text
@@ -190,10 +202,10 @@ module Xlocalize
190
202
  end
191
203
  end
192
204
 
193
- def import(locales)
205
+ def import(locales, allows_missing_files=false)
194
206
  puts 'Importing translations' if $VERBOSE
195
207
  locales.each do |locale|
196
- import_xliff(locale)
208
+ import_xliff(locale, allows_missing_files)
197
209
  import_plurals_if_needed(locale)
198
210
  puts "Done #{locale}".green if $VERBOSE
199
211
  end
@@ -1,4 +1,4 @@
1
1
  module Xlocalize
2
- VERSION = "0.3.2"
2
+ VERSION = "0.4.0"
3
3
  DESCRIPTION = "Xcode localizations import/export helper tool"
4
4
  end
@@ -69,5 +69,11 @@ module Xlocalize
69
69
  end
70
70
  end
71
71
  end
72
+
73
+ def unescape
74
+ self.xpath("//xmlns:source").each do |src|
75
+ src.content = CGI.unescapeHTML(src.content)
76
+ end
77
+ end
72
78
  end
73
79
  end
data/lib/xlocalize.rb CHANGED
@@ -16,7 +16,10 @@ module Xlocalize
16
16
  c.option '--targets ARRAY', Array, 'Target in the project'
17
17
  c.option '--excl_prefix STRING', String, 'Exclude strings having specified prefix'
18
18
  c.option '--master_lang STRING', String, 'Master language of the project'
19
+ c.option '--exclude_units ARRAY', Array, 'Translation unit IDs to exclude'
19
20
  c.action do |_, options|
21
+ options.default :exclude_units => []
22
+
20
23
  if options.project.nil? or
21
24
  options.targets.nil? or
22
25
  options.excl_prefix.nil? or
@@ -25,7 +28,7 @@ module Xlocalize
25
28
  end
26
29
 
27
30
  wti = WebtranslateIt.new(options.wti_key) if !options.wti_key.nil?
28
- Executor.new.export_master(wti, options.project, options.targets, options.excl_prefix, options.master_lang)
31
+ Executor.new.export_master(wti, options.project, options.targets, options.excl_prefix, options.master_lang, options.exclude_units)
29
32
  end
30
33
  end
31
34
  end
@@ -52,12 +55,13 @@ module Xlocalize
52
55
  c.syntax = 'xlocalize import [options]'
53
56
  c.description = 'Import localized strings to Xcode project'
54
57
  c.option '--locales ARRAY', Array, 'Locales to import'
58
+ c.option '--allow-missing-files', 'Allow missing files read from xliff'
55
59
  c.action do |_, options|
56
60
  if options.locales.nil?
57
61
  raise 'Missing parameter'
58
62
  end
59
-
60
- Executor.new.import(options.locales)
63
+ allow_missing_files = options.allow_missing_files ||= false
64
+ Executor.new.import(options.locales, allow_missing_files=allow_missing_files)
61
65
  end
62
66
  end
63
67
  end
@@ -67,6 +71,8 @@ module Xlocalize
67
71
  program :version, Xlocalize::VERSION
68
72
  program :description, Xlocalize::DESCRIPTION
69
73
 
74
+ global_option('--verbose') { $VERBOSE = true }
75
+
70
76
  define_export_cmd
71
77
  define_download_cmd
72
78
  define_import_cmd
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xlocalize
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Viktoras Laukevičius
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-25 00:00:00.000000000 Z
11
+ date: 2018-06-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -147,6 +147,7 @@ extensions: []
147
147
  extra_rdoc_files: []
148
148
  files:
149
149
  - ".gitignore"
150
+ - ".ruby-version"
150
151
  - ".travis.yml"
151
152
  - CHANGELOG.md
152
153
  - CODE_OF_CONDUCT.md
@@ -184,7 +185,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
184
185
  version: '0'
185
186
  requirements: []
186
187
  rubyforge_project:
187
- rubygems_version: 2.6.8
188
+ rubygems_version: 2.5.2
188
189
  signing_key:
189
190
  specification_version: 4
190
191
  summary: Xcode localizations import/export helper tool