tmx_importer 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +0 -1
- data/README.md +3 -3
- data/lib/tmx_importer/version.rb +1 -1
- data/lib/tmx_importer.rb +4 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2d9609a8256bf614eed18bcd0482e7cc72e75f68
|
4
|
+
data.tar.gz: ed72d1341c9daf13a7bba504457b25be16d2a93a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 59eb55bd99594f64f64b4ab9beb1e3990a85082cb5c0d7123ee6168013b5b1a73313eb5c95e222df7cb50f01b5df2111266e825ea99e94a71b14a4e87b31be56
|
7
|
+
data.tar.gz: d4a284564130928be00a06597c523033fd10f7069c9235072aeacad409fd720f2f38ee9d49fedcff408598b520efbfe0793311c6a1fbf8c21b9137c77a0c5427
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/tmx_importer.svg)](https://badge.fury.io/rb/tmx_importer) [![Build Status](https://travis-ci.org/diasks2/tmx_importer.png)](https://travis-ci.org/diasks2/tmx_importer) [![License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat)](https://github.com/diasks2/tmx_importer/blob/master/LICENSE.txt)
|
4
4
|
|
5
|
-
This gem handles the importing and parsing of [.tmx translation memory files](http://www.ttt.org/oscarstandards/tmx/tmx14-20020710.htm). TMX files are xml files.
|
5
|
+
This gem handles the importing and parsing of [.tmx translation memory files](http://www.ttt.org/oscarstandards/tmx/tmx14-20020710.htm). [TMX files](https://en.wikipedia.org/wiki/Translation_Memory_eXchange) are xml files.
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
@@ -30,11 +30,11 @@ TmxImporter::Tmx.new(file_path: file_path, encoding: 'utf-8').stats
|
|
30
30
|
# Extract the segments of a TMX file
|
31
31
|
# Result: [translation_units, segments]
|
32
32
|
# translation_units = [tu_id, creation_date]
|
33
|
-
# segments = [tu_id, segment_role, word_count, language, segment_text]
|
33
|
+
# segments = [tu_id, segment_role, word_count, language, segment_text, creation_date]
|
34
34
|
|
35
35
|
file_path = File.expand_path('../tmx_importer/spec/test_sample_files/test_tm(utf-8).tmx')
|
36
36
|
TmxImporter::Tmx.new(file_path: file_path, encoding: 'utf-8').import
|
37
|
-
# => [[["
|
37
|
+
# => [[["3638-1457683912-1", "2016-03-11T17:11:52+09:00"], ["7214-1457683912-3", "2016-03-11T17:11:52+09:00"], ["1539-1457683912-5", "2016-03-11T17:11:52+09:00"], ["6894-1457683912-7", "2016-03-11T17:11:52+09:00"]], [["3638-1457683912-1", "", 1, "de-DE", "überprüfen", "2016-03-11T17:11:52+09:00"], ["3638-1457683912-1", "target", 1, "en-US", "check", "2016-03-11T17:11:52+09:00"], ["7214-1457683912-3", "source", 1, "de-DE", "Rückenlehneneinstellung", "2016-03-11T17:11:52+09:00"], ["7214-1457683912-3", "target", 2, "en-US", "Backrest adjustment", "2016-03-11T17:11:52+09:00"], ["1539-1457683912-5", "source", 1, "de-DE", "Bezüglich", "2016-03-11T17:11:52+09:00"], ["1539-1457683912-5", "target", 3, "en-US", "In terms of", "2016-03-11T17:11:52+09:00"], ["6894-1457683912-7", "source", 20, "de-DE", "Der Staatsschutz prüft, ob es einen Zusammenhang mit einem Anschlag auf eine geplante Flüchtlingsunterkunft in der Nachbarschaft Ende August gibt.", "2016-03-11T17:11:52+09:00"], ["6894-1457683912-7", "target", 23, "en-US", "The state protection checks whether there is a connection with an attack on a planned refugee camp in the neighborhood of late August.", "2016-03-11T17:11:52+09:00"]]]
|
38
38
|
```
|
39
39
|
|
40
40
|
## Contributing
|
data/lib/tmx_importer/version.rb
CHANGED
data/lib/tmx_importer.rb
CHANGED
@@ -14,7 +14,7 @@ module TmxImporter
|
|
14
14
|
@encoding = encoding.upcase
|
15
15
|
@doc = {
|
16
16
|
source_language: "",
|
17
|
-
tu: { id: "", counter: 0, vals: [], lang: "" },
|
17
|
+
tu: { id: "", counter: 0, vals: [], lang: "", creation_date: "" },
|
18
18
|
seg: { lang: "", counter: 0, vals: [], role: "" },
|
19
19
|
language_pairs: []
|
20
20
|
}
|
@@ -117,15 +117,15 @@ module TmxImporter
|
|
117
117
|
|
118
118
|
def write_tu(reader)
|
119
119
|
@doc[:tu][:lang] = reader.get_attribute("srclang")
|
120
|
-
|
121
|
-
@doc[:tu][:vals] << [@doc[:tu][:id],
|
120
|
+
@doc[:tu][:creation_date] = reader.get_attribute("creationdate").nil? ? DateTime.now.to_s : DateTime.parse(reader.get_attribute("creationdate")).to_s
|
121
|
+
@doc[:tu][:vals] << [@doc[:tu][:id], @doc[:tu][:creation_date]]
|
122
122
|
end
|
123
123
|
|
124
124
|
def write_seg(reader)
|
125
125
|
return if reader.read_string.empty?
|
126
126
|
text = PrettyStrings::Cleaner.new(reader.read_string.force_encoding('UTF-8')).pretty.gsub("\\","\").gsub("'",%q(\\\'))
|
127
127
|
word_count = text.gsub("\s+", ' ').split(' ').length
|
128
|
-
@doc[:seg][:vals] << [@doc[:tu][:id], @doc[:seg][:role], word_count, @doc[:seg][:lang], text]
|
128
|
+
@doc[:seg][:vals] << [@doc[:tu][:id], @doc[:seg][:role], word_count, @doc[:seg][:lang], text, @doc[:tu][:creation_date]]
|
129
129
|
end
|
130
130
|
|
131
131
|
def generate_unique_id
|