xlocalize 0.4.1 → 0.5.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/lib/xlocalize/executor.rb +19 -22
- data/lib/xlocalize/importer.rb +27 -0
- data/lib/xlocalize/version.rb +1 -1
- data/lib/xlocalize/webtranslateit.rb +7 -7
- data/xlocalize.gemspec +1 -0
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ae37aab6a0d88d19503863c88fba6781572be6e0
|
4
|
+
data.tar.gz: 7bad4314a85fc60fba671d3d112927e1c0903804
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d5697b57687f2229fbcfd7e03c735cd61de0afd61f8d5602e79560a5bad1b6e90564dd8f2123d89ed7e9c4c287fe67206628508593617f08208310802a4b511e
|
7
|
+
data.tar.gz: 70537aa2952e423b8bb8073f422b93a12d4441876bbc84bde3e20e82ca3142738a86cc85da45f9c50475ca85c32ef43ab59d14372740a118bf85061bf7b858c1
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
## [v0.5.0](https://github.com/viktorasl/xlocalize/releases/tag/0.5.0)
|
2
|
+
|
3
|
+
* [cb03ba3](https://github.com/viktorasl/xlocalize/commit/cb03ba3a91c3b4218fd880b50c7b9f2fff113573) Translations import revamp
|
4
|
+
* [bb768a4](https://github.com/viktorasl/xlocalize/commit/bb768a45111519d6797bc38c1a31aed87499d6c9) Not overriding translations on export to WebtranslateIt
|
5
|
+
|
1
6
|
## [v0.4.1](https://github.com/viktorasl/xlocalize/releases/tag/0.4.1)
|
2
7
|
|
3
8
|
* [5be2948](https://github.com/viktorasl/xlocalize/commit/5be2948bbe5a4c1867a9780f122778f2dcd3b1a4) Unescapes xliff files on export
|
data/lib/xlocalize/executor.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
require 'xlocalize/webtranslateit'
|
2
2
|
require 'xlocalize/xliff'
|
3
3
|
require 'xlocalize/helper'
|
4
|
+
require 'xlocalize/importer'
|
4
5
|
require 'colorize'
|
5
6
|
require 'nokogiri'
|
6
7
|
require 'yaml'
|
8
|
+
require 'apfel'
|
7
9
|
|
8
10
|
module Xlocalize
|
9
11
|
class Executor
|
@@ -137,35 +139,30 @@ module Xlocalize
|
|
137
139
|
return name
|
138
140
|
end
|
139
141
|
|
140
|
-
def import_xliff(
|
141
|
-
fname = "#{locale}.xliff"
|
142
|
+
def import_xliff(fname)
|
142
143
|
puts "Importing translations from #{fname}" if $VERBOSE
|
143
144
|
Nokogiri::XML(File.open(fname)).xpath("//xmlns:file").each do |node|
|
144
|
-
tr_fname =
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
file.write "/* #{note} */\n"
|
159
|
-
file.write "\"#{key}\" = #{target.inspect};\n\n"
|
160
|
-
end
|
161
|
-
end
|
145
|
+
tr_fname = node["original"]
|
146
|
+
source_lang = node["source-language"]
|
147
|
+
target_lang = node["target-language"]
|
148
|
+
|
149
|
+
localized_src_fname = localized_filename(tr_fname, source_lang)
|
150
|
+
next if !File.exist?(localized_src_fname)
|
151
|
+
|
152
|
+
translations_hash = Apfel.parse(localized_src_fname).to_hash
|
153
|
+
importer = Importer.new
|
154
|
+
importer.translate_from_node(translations_hash, node)
|
155
|
+
|
156
|
+
f_content = importer.strings_content_from_translations_hash(translations_hash)
|
157
|
+
target_fname = localized_filename(tr_fname, target_lang)
|
158
|
+
File.open(target_fname, 'w') { |f| f.write(f_content) }
|
162
159
|
end
|
163
160
|
end
|
164
161
|
|
165
162
|
def import_plurals_if_needed(locale)
|
166
163
|
plurals_fname = "#{locale}_plurals.yaml"
|
167
164
|
return if !File.exist?(plurals_fname)
|
168
|
-
puts "Importing translations from #{plurals_fname}"
|
165
|
+
puts "Importing translations from #{plurals_fname}" if $VERBOSE
|
169
166
|
plurals_yml = YAML.load_file(plurals_fname)
|
170
167
|
plurals_yml[locale].each do |original_fname, trans_units|
|
171
168
|
content = ''
|
@@ -205,7 +202,7 @@ module Xlocalize
|
|
205
202
|
def import(locales, allows_missing_files=false)
|
206
203
|
puts 'Importing translations' if $VERBOSE
|
207
204
|
locales.each do |locale|
|
208
|
-
import_xliff(locale
|
205
|
+
import_xliff("#{locale}.xliff")
|
209
206
|
import_plurals_if_needed(locale)
|
210
207
|
puts "Done #{locale}".green if $VERBOSE
|
211
208
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
|
2
|
+
module Xlocalize
|
3
|
+
class Importer
|
4
|
+
|
5
|
+
def strings_content_from_translations_hash(translations_hash)
|
6
|
+
result = StringIO.new
|
7
|
+
translations_hash.each do |key, translations|
|
8
|
+
translations.each do |target, note|
|
9
|
+
result << "/* #{note} */\n" if note.length > 0
|
10
|
+
result << "\"#{key}\" = #{target.inspect};\n\n"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
return result.string
|
14
|
+
end
|
15
|
+
|
16
|
+
def translate_from_node(translations, node)
|
17
|
+
(node > "body > trans-unit").each do |trans_unit|
|
18
|
+
key = trans_unit["id"]
|
19
|
+
target = (trans_unit > "target").text
|
20
|
+
note = (trans_unit > "note").text
|
21
|
+
if translations.key?(key)
|
22
|
+
translations[key] = { target => note }
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/xlocalize/version.rb
CHANGED
@@ -40,18 +40,18 @@ module Xlocalize
|
|
40
40
|
return resp
|
41
41
|
end
|
42
42
|
|
43
|
-
def master_file_for_locale_request(file_id, file
|
43
|
+
def master_file_for_locale_request(file_id, file)
|
44
44
|
# /api/projects/:project_token/files/:master_project_file_id/locales/:locale_code [PUT]
|
45
45
|
return Net::HTTP::Put::Multipart.new("/api/projects/#{@key}/files/#{file_id}/locales/#{@source_locale}", {
|
46
46
|
"file" => UploadIO.new(file, "text/plain", file.path),
|
47
|
-
"merge" =>
|
47
|
+
"merge" => true,
|
48
48
|
"ignore_missing" => true,
|
49
49
|
"label" => "",
|
50
50
|
"low_priority" => false
|
51
51
|
})
|
52
52
|
end
|
53
53
|
|
54
|
-
def push_master_plurals(plurals_file
|
54
|
+
def push_master_plurals(plurals_file)
|
55
55
|
if @plurals_file_id.nil?
|
56
56
|
if $VERBOSE
|
57
57
|
$stderr.puts 'Creating plurals file'
|
@@ -66,16 +66,16 @@ module Xlocalize
|
|
66
66
|
if $VERBOSE
|
67
67
|
$stderr.puts 'Updating plurals file'
|
68
68
|
end
|
69
|
-
send_request(master_file_for_locale_request(@plurals_file_id, plurals_file
|
69
|
+
send_request(master_file_for_locale_request(@plurals_file_id, plurals_file))
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
73
|
-
def push_master(file, plurals_file
|
73
|
+
def push_master(file, plurals_file)
|
74
74
|
if $VERBOSE
|
75
75
|
$stderr.puts 'Updating xliff file'
|
76
76
|
end
|
77
|
-
send_request(master_file_for_locale_request(@xliff_file_id, file
|
78
|
-
push_master_plurals(plurals_file
|
77
|
+
send_request(master_file_for_locale_request(@xliff_file_id, file))
|
78
|
+
push_master_plurals(plurals_file) if not plurals_file.nil?
|
79
79
|
end
|
80
80
|
|
81
81
|
def pull(locale)
|
data/xlocalize.gemspec
CHANGED
@@ -24,6 +24,7 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.add_runtime_dependency 'colorize', '~> 0.8'
|
25
25
|
spec.add_runtime_dependency 'multipart-post', '~> 2.0'
|
26
26
|
spec.add_runtime_dependency 'plist', '~> 3.2'
|
27
|
+
spec.add_runtime_dependency 'apfel'
|
27
28
|
|
28
29
|
spec.add_development_dependency 'bundler', '~> 1.10'
|
29
30
|
spec.add_development_dependency 'rspec', '~> 3.5'
|
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.
|
4
|
+
version: 0.5.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-
|
11
|
+
date: 2018-07-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '3.2'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: apfel
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
83
97
|
- !ruby/object:Gem::Dependency
|
84
98
|
name: bundler
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -161,6 +175,7 @@ files:
|
|
161
175
|
- lib/xlocalize.rb
|
162
176
|
- lib/xlocalize/executor.rb
|
163
177
|
- lib/xlocalize/helper.rb
|
178
|
+
- lib/xlocalize/importer.rb
|
164
179
|
- lib/xlocalize/version.rb
|
165
180
|
- lib/xlocalize/webtranslateit.rb
|
166
181
|
- lib/xlocalize/xliff.rb
|