tolq-parsers-xliff 0.1.4 → 0.1.5

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: 207acef5698ce9b31f042cca0006c6eb637dd23c
4
- data.tar.gz: 4379620a6c9567e3361db956afe096c65c79a6fe
3
+ metadata.gz: 54e8257412582072e447ab41106b4354254a25a8
4
+ data.tar.gz: 0a17033cc0e99e8b53a0fae54681c7e1992f4c86
5
5
  SHA512:
6
- metadata.gz: 31dd134dcd2c29a6fb75e241f7ec1062662ec3e32c42fa206a0f2931f9ecfd01e48b9d20bc93964405ec234a0cd8b589deb65a122dea92c26057d9cf6bfa4675
7
- data.tar.gz: 7d30383026764381af1587fb0ccc4ca1f8d00b2fe529745382900a586027719e51c3c7dce5f6495d4de823aa1a5957c914238758be1889ccb0943ce500355145
6
+ metadata.gz: 823ef5c99d158ab0a2cf3e62360e06298c1e5d61369955cdf9f15205f25b247c00970e265f02237702022db41c9873301678b08c2e5de1c927a5ec1a8806b7fe
7
+ data.tar.gz: 22df13c0a2a35bbca71e69ec5a359d5527b0ab03ced6cbeccbea35975b832c83a9530e26f54f534cf366ce25c44faa125f05bd1ce75f8b51fff5053e9e3b191b
@@ -0,0 +1,37 @@
1
+ module Tolq::Parsers::Xliff
2
+ # Unparses a tolq response to xliff suitable
3
+ # As opposed to other unparsers, requires the original,
4
+ # AND the target language code
5
+ # Assumes single file per xliff
6
+ class Unparser
7
+ # Unparses the tolq response
8
+ #
9
+ # @param tolq_response [Hash] A parsed response from our api
10
+ # @return [String] A xliff formatted string
11
+ def from_tolq_response(tolq_response, original:, target_language_code:)
12
+ translations = tolq_response['translations'].values.first
13
+ translate_xliff(translations, original, target_language_code).to_s
14
+ end
15
+
16
+ # Unparses a translations hash of key => translation
17
+ #
18
+ # @param translations [Hash] A hash of translations with key => translation
19
+ # @return [String] A xliff formatted string
20
+ def from_hash(translations, original:, target_language_code:)
21
+ translate_xliff(translations, original, target_language_code).to_s
22
+ end
23
+
24
+ private
25
+
26
+ def translate_xliff(translations, xliff_text, target_language_code)
27
+ xliff = XLIFFer::XLIFF.new(xliff_text)
28
+ xliff.files.first.target_language = target_language_code
29
+ xliff.files.first.strings.each do |string|
30
+ if translation = translations[string.id]
31
+ string.target = translation
32
+ end
33
+ end
34
+ xliff
35
+ end
36
+ end
37
+ end
data/lib/xliff/version.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  module Tolq
2
2
  module Parsers
3
3
  module Xliff
4
- VERSION = "0.1.4"
4
+ VERSION = "0.1.5"
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tolq-parsers-xliff
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Timon Vonk
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-14 00:00:00.000000000 Z
11
+ date: 2017-02-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: xliffer
@@ -98,6 +98,7 @@ files:
98
98
  - bin/tolq_xliff
99
99
  - lib/tolq-parsers-xliff.rb
100
100
  - lib/xliff/parser.rb
101
+ - lib/xliff/unparser.rb
101
102
  - lib/xliff/version.rb
102
103
  - tolq-parsers-xliff.gemspec
103
104
  homepage: https://github.com/tolq/parsers/xliff