xlocalize 0.2.4 → 0.2.5

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1e769ae9ea466eac3b9a343ce2e7583e3c8e0d8c
4
- data.tar.gz: a7ac50fb19af682e46347139fc466aaaacee47ed
3
+ metadata.gz: 934cb7077c838252617fce8f0583847eff82aedd
4
+ data.tar.gz: 85ef3055860a34de3e9ccb33634b9110c2af1762
5
5
  SHA512:
6
- metadata.gz: bf16efc0ad633adb1bd34c0364d724c905fe59a30ad1d5d39ca406e647b9b407095ea6bfa980c5e827fa096a121aff77902c6148e4f5544dbf016cb1849aa065
7
- data.tar.gz: f0f9d990697113327a4ec9a410dad15ee84688e9f07a69c082e8221d03e64b8273200cb14efb158ff092aaf69130bd21275cbce4c6c11717f5ece233b4bba7f4
6
+ metadata.gz: 5d21bc3c534b8523c1188af30ea7323c5f2936271ad5351e0fc2f2fc46b3db868ee8acc1f6461fbced3ea891e308973035a28daae473b2d41219c0cc1d98ffed
7
+ data.tar.gz: 86723f67f6ef7062d159cfe6b368a52348aa174925ccf525e4cbdf484f3ec4001d7ba751045073f4af50b2434eefcaa7ea6ce548c435bbb759ffc3ddce569958
@@ -2,7 +2,6 @@ require 'xlocalize/webtranslateit'
2
2
  require 'xlocalize/xliff'
3
3
  require 'colorize'
4
4
  require 'nokogiri'
5
- require 'plist'
6
5
  require 'yaml'
7
6
 
8
7
  module Xlocalize
@@ -91,7 +90,6 @@ module Xlocalize
91
90
  def download(wti, locales)
92
91
  begin
93
92
  locales.each do |locale|
94
- puts "Downloading translations for #{locale}"
95
93
  translations = wti.pull(locale)
96
94
 
97
95
  out_list_of_translations_of_locale(wti, locale, translations).each do |out|
@@ -106,7 +104,7 @@ module Xlocalize
106
104
  end
107
105
  end
108
106
 
109
- def filename_from_xliff_provided_filename(file_name, locale)
107
+ def localized_filename(file_name, locale)
110
108
  parts = file_name.split('/')
111
109
  name = ""
112
110
  parts.each_with_index do |part, idx|
@@ -114,8 +112,9 @@ module Xlocalize
114
112
  if part.end_with?(".lproj")
115
113
  name += "#{locale}.lproj"
116
114
  elsif idx+1 == parts.count
115
+ extension = (part.split('.')[1] == 'stringsdict') ? 'stringsdict' : 'strings'
117
116
  # TODO: join all parts till the last '.'
118
- name += "#{part.split('.')[0]}.strings"
117
+ name += "#{part.split('.')[0]}.#{extension}"
119
118
  else
120
119
  name += part
121
120
  end
@@ -124,8 +123,10 @@ module Xlocalize
124
123
  end
125
124
 
126
125
  def import_xliff(locale)
127
- Nokogiri::XML(open("#{locale}.xliff")).xpath("//xmlns:file").each do |node|
128
- File.open(filename_from_xliff_provided_filename(node["original"], locale), "w") do |file|
126
+ fname = "#{locale}.xliff"
127
+ puts "Importing translations from #{fname}"
128
+ Nokogiri::XML(open(fname)).xpath("//xmlns:file").each do |node|
129
+ File.open(localized_filename(node["original"], locale), "w") do |file|
129
130
  (node > "body > trans-unit").each do |trans_unit|
130
131
  key = trans_unit["id"]
131
132
  target = (trans_unit > "target").text
@@ -142,19 +143,40 @@ module Xlocalize
142
143
  def import_plurals_if_needed(locale)
143
144
  plurals_fname = "#{locale}_plurals.yaml"
144
145
  return if !File.exist?(plurals_fname)
146
+ puts "Importing translations from #{plurals_fname}"
145
147
  plurals_yml = YAML.load_file(plurals_fname)
146
- plurals_yml[locale].each do |fname, trans_units|
147
- content = {}
148
- trans_units.each do |key, vals|
149
- content[key] = {
150
- "NSStringLocalizedFormatKey" => "%\#@value@",
151
- "value" => vals.merge({
152
- "NSStringFormatSpecTypeKey" => "NSStringPluralRuleType",
153
- "NSStringFormatValueTypeKey" => "d"
154
- })
155
- }
148
+ plurals_yml[locale].each do |original_fname, trans_units|
149
+ content = ''
150
+ content << '<?xml version="1.0" encoding="UTF-8"?>' + "\n"
151
+ content << '<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">' + "\n"
152
+ content << '<plist version="1.0">' + "\n"
153
+
154
+ fname = localized_filename(original_fname, locale)
155
+ content << "<dict>\n"
156
+ trans_units.each do |key, element|
157
+ content << "\t<key>#{key}</key>\n"
158
+ content << "\t<dict>\n"
159
+
160
+ content << "\t\t<key>NSStringLocalizedFormatKey</key>\n"
161
+ content << "\t\t<string>%\#@value@</string>\n"
162
+ content << "\t\t<key>value</key>\n"
163
+ content << "\t\t<dict>\n"
164
+ element.each do |k, v|
165
+ content << "\t\t\t<key>#{k}</key>\n"
166
+ content << "\t\t\t<string>#{v}</string>\n"
167
+ end
168
+ content << "\t\t\t<key>NSStringFormatSpecTypeKey</key>\n"
169
+ content << "\t\t\t<string>NSStringPluralRuleType</string>\n"
170
+ content << "\t\t\t<key>NSStringFormatValueTypeKey</key>\n"
171
+ content << "\t\t\t<string>d</string>\n"
172
+ content << "\t\t</dict>\n"
173
+
174
+ content << "\t</dict>\n"
156
175
  end
157
- File.open(fname, 'w') { |f| f.write content.to_plist }
176
+ content << "</dict>\n"
177
+ content << "</plist>\n"
178
+
179
+ File.open(fname, 'w') { |f| f.write content }
158
180
  end
159
181
  end
160
182
 
@@ -1,4 +1,4 @@
1
1
  module Xlocalize
2
- VERSION = "0.2.4"
2
+ VERSION = "0.2.5"
3
3
  DESCRIPTION = "Xcode localizations import/export helper tool"
4
4
  end
data/xlocalize.gemspec CHANGED
@@ -22,7 +22,6 @@ Gem::Specification.new do |spec|
22
22
  spec.add_runtime_dependency 'nokogiri', '= 1.6'
23
23
  spec.add_runtime_dependency 'commander', '~> 4.4'
24
24
  spec.add_runtime_dependency 'colorize', '~> 0.8'
25
- spec.add_runtime_dependency 'plist', '~> 3.2'
26
25
  spec.add_runtime_dependency 'multipart-post', '~> 2.0'
27
26
 
28
27
  spec.add_development_dependency 'bundler', '~> 1.10'
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.2.4
4
+ version: 0.2.5
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: 2017-03-03 00:00:00.000000000 Z
11
+ date: 2017-03-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -52,20 +52,6 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0.8'
55
- - !ruby/object:Gem::Dependency
56
- name: plist
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '3.2'
62
- type: :runtime
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '3.2'
69
55
  - !ruby/object:Gem::Dependency
70
56
  name: multipart-post
71
57
  requirement: !ruby/object:Gem::Requirement