xliffle 0.3.2 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 936144a3590c2ecc46e063ce185d3babde7ad168d574d9ce4af284a667bd3a97
4
- data.tar.gz: 6df22f4c2c352452a6ddbd43991231c8688e26581bd1979aadb1949bdc6a3ddd
3
+ metadata.gz: 3ce823c44df264f45f986940bf22d4307770211880a494d46014b7eedc71aad3
4
+ data.tar.gz: a73c37e6cec90497c965a1305a4418004b764b8ffa457bc81a68d1f70b2a542d
5
5
  SHA512:
6
- metadata.gz: 8f6fa46615495b718d81ec1f51e237b6e812c9d9140c5161173243e07c4aa3953b1467e9f064a6108a0e783a0affa5ceb9f36717654a9decdbe4ed0b6ffd43dd
7
- data.tar.gz: 6cf80d7260b4befba237a53233e2ba7ff2857760aa88c6659c22c2671999743d591123ca86770726f1c281dba09b15d55b157550163892fb38b611b7edf6097e
6
+ metadata.gz: d5566f6cab939e83083c87410855ea1604269c44d83965cab29dc40dab4dff7e18d0d109d3c50d10a96eebfec0996c2c9548937db9e9a788dae37fff08b805a3
7
+ data.tar.gz: 1452bdaae3b7a3f9af78c84894f1aa5f2e5bdc959c8426c65df67a397ddfc01b031f7364ccdaf32a12a609bb636f190469885ad4c6fdc012570a2b2117cea2a2
data/README.md ADDED
@@ -0,0 +1,150 @@
1
+ # Xliffle
2
+ A Gem to create xliff files from translated strings. Implementing version 1.2 of XLIFF specification: [Xliff-Specification](http://docs.oasis-open.org/xliff/xliff-core/xliff-core.html)
3
+
4
+ ## Warning
5
+ This is still an early implementation.
6
+
7
+ ## Installation
8
+ Add this line to your Gemfile:
9
+
10
+ `gem 'xliffle'`
11
+
12
+
13
+ ## Usage
14
+ ### Create a Xliffle instance
15
+
16
+ #### Example####
17
+
18
+ ```
19
+ xliffle = Xliffle.new
20
+ => #<Xliffle::Creator:0x007fea48d31690 @files=[]>
21
+ ```
22
+
23
+ ### Add a file to Xliffle instance
24
+
25
+ **xliffle.file**(filename, source_locale_code, target_locale_code)
26
+
27
+ #### Example ####
28
+ ```
29
+ file = xliffle.file('de.po', 'de', 'en')
30
+ => #<Xliffle::File...>
31
+ ```
32
+
33
+ ### Add a string to file instance
34
+
35
+ **file.string**(name, source_string, target_string, options={})
36
+
37
+ #### Example ####
38
+
39
+ ```
40
+ string = file.string('admin.foo_bar','Foo', 'Bar')
41
+ # => #<Xliffle::String...>
42
+ ```
43
+
44
+ #### Options
45
+
46
+ The options-hash may take the following optional attributes
47
+
48
+ * `resource_name` — sets the `resname` attribute on the `trans-unit` element, used to identify the resource by name
49
+
50
+ ###### Example with resource_name
51
+
52
+ ```
53
+ second_string = file.string('user.bar_foo','Bar', 'Foo', resource_name: 'foo.bar.header')
54
+ # => #<Xliffle::String...>
55
+ ```
56
+
57
+ * `use_cdata` — wraps the content of source and target tags in a CDATA section
58
+
59
+ ###### Example with use_cdata
60
+
61
+ ```
62
+ second_string = file.string('user.bar_foo','Bar', 'Foo', use_cdata: true)
63
+ # => #<Xliffle::String...>
64
+ ```
65
+
66
+ * `no_escaping` — outputs source and target content as raw XML without escaping, useful when the string already contains inline XML elements (e.g. placeholders)
67
+
68
+ ###### Example with no_escaping
69
+
70
+ ```
71
+ second_string = file.string('user.bar_foo', 'Hello <x id="PH1"/>world', 'Hallo <x id="PH1"/>Welt', no_escaping: true)
72
+ # => #<Xliffle::String...>
73
+ ```
74
+
75
+
76
+ ### Add a note to string instance
77
+ Xliffle supports Xliff localization notes (as structural elements).
78
+
79
+ **string.note**(note, options = {})
80
+
81
+ #### Options ####
82
+
83
+ * *:priority* - Sets the priority of the note (default: 2)
84
+
85
+ #### Example ####
86
+
87
+ ```
88
+ string.note('This is localization comment', priority: 2)
89
+ #=> #<Xliffle::Note...>
90
+ ```
91
+
92
+
93
+ ### Export to file
94
+
95
+ **to_xliff()**
96
+
97
+ Returns xliff-file
98
+
99
+ #### Example ####
100
+ ```
101
+ xliffle.to_file
102
+ # => #<Tempfile...>
103
+ ```
104
+
105
+ ### Export to Xliff string
106
+
107
+ Exports XML-markup to a string
108
+
109
+ **to_xliff()**
110
+ #### Example ####
111
+
112
+ ```
113
+ xliffle.to_xliff
114
+ => "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<xliff version=\"1.2\" xmlns=\"urn:oasis:names:tc:xliff:document:1.2\">\n <file original=\"de.po\" datatype=\"plaintext\" source-language=\"de\" target-language=\"en\">\n <body>\n <trans-unit id=\"admin.foo_bar\">\n <source>Foo</source>\n <target>Bar</target>\n <note priority=\"2\">This is localization comment</note>\n </trans-unit>\n <trans-unit id=\"user.bar_foo\" resname=\"foo.bar.header\">\n <source>Bar</source>\n <target>Foo</target>\n </trans-unit>\n </body>\n </file>\n</xliff>\n"
115
+ ```
116
+
117
+ ##### Rendered Example Output
118
+
119
+ ```
120
+ <?xml version="1.0" encoding="UTF-8"?>
121
+ <xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
122
+ <file original="de.po" datatype="plaintext" source-language="de" target-language="en">
123
+ <body>
124
+ <trans-unit id="admin.foo_bar">
125
+ <source>Foo</source>
126
+ <target>Bar</target>
127
+ <note priority="2">This is localization comment</note>
128
+ </trans-unit>
129
+ <trans-unit id="user.bar_foo" resname="foo.bar.header">
130
+ <source>Bar</source>
131
+ <target>Foo</target>
132
+ </trans-unit>
133
+ </body>
134
+ </file>
135
+ </xliff>
136
+ ```
137
+
138
+
139
+ ## Contributors
140
+
141
+ * Stefan Rohde (@Stefan_Rohde, http://www.rohdenetz.de, info@rohdenetz.de)
142
+
143
+ ## Thanks to
144
+
145
+ * Toptranslation GmbH, Hamburg - my work, my team, my beloved hobby - @toptranslation, https://www.toptranslation.com
146
+
147
+ ## License
148
+
149
+ MIT License. Copyright Stefan Rohde
150
+
@@ -26,7 +26,7 @@ module Xliffle
26
26
  end
27
27
 
28
28
  def to_file
29
- handle = Tempfile.new('foo.xlf')
29
+ handle = Tempfile.new(['xliffle', '.xlf'])
30
30
  handle.write to_xliff
31
31
  handle.close
32
32
  handle
@@ -34,14 +34,10 @@ module Xliffle
34
34
 
35
35
  private
36
36
 
37
- def file_id
38
- @files.length.succ
39
- end
40
-
41
- def xml(&block)
37
+ def xml(&)
42
38
  xml = Builder::XmlMarkup.new(indent: 2)
43
39
  xml.instruct! :xml, encoding: 'UTF-8'
44
- xml.xliff({ version: '1.2', xmlns: 'urn:oasis:names:tc:xliff:document:1.2' }, &block)
40
+ xml.xliff({ version: '1.2', xmlns: 'urn:oasis:names:tc:xliff:document:1.2' }, &)
45
41
  end
46
42
  end
47
43
  end
@@ -13,7 +13,7 @@ module Xliffle
13
13
  end
14
14
 
15
15
  def note(note, priority = 2)
16
- note = Xliffle::Note.new(note, priority: priority)
16
+ note = Xliffle::Note.new(note, priority:)
17
17
  @notes << note
18
18
  note
19
19
  end
@@ -57,6 +57,8 @@ module Xliffle
57
57
  def segment(tag, value)
58
58
  if @options[:use_cdata] && value
59
59
  tag.cdata!(value)
60
+ elsif @options[:no_escaping] && value
61
+ tag << value
60
62
  else
61
63
  tag.text!(value)
62
64
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Xliffle
4
- VERSION = '0.3.2'
4
+ VERSION = '0.5.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xliffle
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefan Rohde
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2021-05-17 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: builder
@@ -24,76 +23,6 @@ dependencies:
24
23
  - - "~>"
25
24
  - !ruby/object:Gem::Version
26
25
  version: '3.2'
27
- - !ruby/object:Gem::Dependency
28
- name: oga
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '3.3'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '3.3'
41
- - !ruby/object:Gem::Dependency
42
- name: pry
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '0.14'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '0.14'
55
- - !ruby/object:Gem::Dependency
56
- name: rspec
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '3.10'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '3.10'
69
- - !ruby/object:Gem::Dependency
70
- name: rubocop
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - "~>"
74
- - !ruby/object:Gem::Version
75
- version: '1.15'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - "~>"
81
- - !ruby/object:Gem::Version
82
- version: '1.15'
83
- - !ruby/object:Gem::Dependency
84
- name: rubocop-rspec
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - "~>"
88
- - !ruby/object:Gem::Version
89
- version: '2.3'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - "~>"
95
- - !ruby/object:Gem::Version
96
- version: '2.3'
97
26
  description: A gem to build XLIFF files from translated strings.
98
27
  email:
99
28
  - info@rohdenetz.de
@@ -102,6 +31,7 @@ extensions: []
102
31
  extra_rdoc_files: []
103
32
  files:
104
33
  - MIT-LICENSE
34
+ - README.md
105
35
  - Rakefile
106
36
  - lib/xliffle.rb
107
37
  - lib/xliffle/creator.rb
@@ -109,13 +39,11 @@ files:
109
39
  - lib/xliffle/note.rb
110
40
  - lib/xliffle/string.rb
111
41
  - lib/xliffle/version.rb
112
- - test/test_helper.rb
113
- - test/xliffle_test.rb
114
42
  homepage: https://github.com/sr189/xliffle
115
43
  licenses:
116
44
  - MIT
117
- metadata: {}
118
- post_install_message:
45
+ metadata:
46
+ rubygems_mfa_required: 'true'
119
47
  rdoc_options: []
120
48
  require_paths:
121
49
  - lib
@@ -123,20 +51,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
123
51
  requirements:
124
52
  - - ">="
125
53
  - !ruby/object:Gem::Version
126
- version: '2.7'
127
- - - "<"
128
- - !ruby/object:Gem::Version
129
- version: '4'
54
+ version: '3.4'
130
55
  required_rubygems_version: !ruby/object:Gem::Requirement
131
56
  requirements:
132
57
  - - ">="
133
58
  - !ruby/object:Gem::Version
134
59
  version: '0'
135
60
  requirements: []
136
- rubygems_version: 3.1.6
137
- signing_key:
61
+ rubygems_version: 3.6.9
138
62
  specification_version: 4
139
63
  summary: Gem to create XLIFF files
140
- test_files:
141
- - test/xliffle_test.rb
142
- - test/test_helper.rb
64
+ test_files: []
data/test/test_helper.rb DELETED
@@ -1,17 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Configure Rails Environment
4
- ENV['RAILS_ENV'] = 'test'
5
-
6
- require File.expand_path('dummy/config/environment.rb', __dir__)
7
- require 'rails/test_help'
8
-
9
- Rails.backtrace_cleaner.remove_silencers!
10
-
11
- # Load support files
12
- Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].sort.each { |f| require f }
13
-
14
- # Load fixtures from the engine
15
- if ActiveSupport::TestCase.method_defined?(:fixture_path=)
16
- ActiveSupport::TestCase.fixture_path = File.expand_path('fixtures', __dir__)
17
- end
data/test/xliffle_test.rb DELETED
@@ -1,9 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- class XliffleTest < ActiveSupport::TestCase
6
- test 'truth' do
7
- assert_kind_of Module, Xliffle
8
- end
9
- end