crowdin2csv 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e621bab313be115d2ae2b08d1741473de24c69c402dbafd5b2a71d3ced898ebe
4
+ data.tar.gz: 4ebca7d20691dac527ea63dc57bedef7f297f7f084087a56645d39f3227c669c
5
+ SHA512:
6
+ metadata.gz: fff6e5fd047631211d84b6a387e07d8810ea164087b725d7b6848c494b09d292e0b283b0625c80357095b4c8aa4b1228dd89facd968b9b918048f5b5b784ba60
7
+ data.tar.gz: 8228c9767147b677ce92b8fbdb01e5994b8a0cc8d55a01f3921eb86629e1a5cf2b98397c4a445a10639b65f77b9b2c8ffdfcd4ac31c77585f66843fffa9fdda8
data/.gitignore ADDED
@@ -0,0 +1,56 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ # Used by dotenv library to load environment variables.
14
+ # .env
15
+
16
+ # Ignore Byebug command history file.
17
+ .byebug_history
18
+
19
+ ## Specific to RubyMotion:
20
+ .dat*
21
+ .repl_history
22
+ build/
23
+ *.bridgesupport
24
+ build-iPhoneOS/
25
+ build-iPhoneSimulator/
26
+
27
+ ## Specific to RubyMotion (use of CocoaPods):
28
+ #
29
+ # We recommend against adding the Pods directory to your .gitignore. However
30
+ # you should judge for yourself, the pros and cons are mentioned at:
31
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
32
+ #
33
+ # vendor/Pods/
34
+
35
+ ## Documentation cache and generated files:
36
+ /.yardoc/
37
+ /_yardoc/
38
+ /doc/
39
+ /rdoc/
40
+
41
+ ## Environment normalization:
42
+ /.bundle/
43
+ /vendor/bundle
44
+ /lib/bundler/man/
45
+
46
+ # for a library or gem, you might want to ignore these files since the code is
47
+ # intended to run in multiple environments; otherwise, check them in:
48
+ # Gemfile.lock
49
+ # .ruby-version
50
+ # .ruby-gemset
51
+
52
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
53
+ .rvmrc
54
+
55
+ # Used by RuboCop. Remote config files pulled in from inherit_from directive.
56
+ # .rubocop-https?--*
data/.rubocop.yml ADDED
@@ -0,0 +1,19 @@
1
+ # The behavior of RuboCop can be controlled via the .rubocop.yml
2
+ # configuration file. It makes it possible to enable/disable
3
+ # certain cops (checks) and to alter their behavior if they accept
4
+ # any parameters. The file can be placed either in your home
5
+ # directory or in some project directory.
6
+ #
7
+ # RuboCop will start looking for the configuration file in the directory
8
+ # where the inspected file is and continue its way up to the root directory.
9
+ #
10
+ # See https://docs.rubocop.org/rubocop/configuration
11
+
12
+ AllCops:
13
+ NewCops: enable
14
+
15
+ Style/Documentation:
16
+ Enabled: false
17
+
18
+ Gemspec/RequiredRubyVersion:
19
+ Enabled: false
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ # 0.9.0
2
+
3
+ Initial release.
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
+
7
+ # Specify your gem's dependencies in crowdin2csv.gemspec
8
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 Masayoshi Takahashi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # Crowdin2csv
2
+
3
+ `Crowdin2csv` is a CLI tool to convert a XLIFF file from [cronwdin](https://crowdin.com) into CSV file.
4
+
5
+ ## Installation
6
+
7
+ `Crowdin2csv` is a rubygems. Install with `gem` command:
8
+
9
+ ```console
10
+ $ gem install crowdin2csv
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ```console
16
+ ## to generate foo.csv
17
+ $ crowdin2csv foo.xliff
18
+
19
+ ## to generate bar.csv
20
+ $ crowdin2csv -o bar.csv foo.xliff
21
+ ```
22
+
23
+ ## Development
24
+
25
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
26
+
27
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
28
+
29
+ ## Contributing
30
+
31
+ Bug reports and pull requests are welcome on GitHub at https://github.com/takahashim/crowdin2csv.
32
+
33
+ ## License
34
+
35
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rake/testtask'
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << 'test'
8
+ t.libs << 'lib'
9
+ t.test_files = FileList['test/**/*_test.rb']
10
+ end
11
+
12
+ task default: :test
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'crowdin2csv'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'crowdin2csv/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'crowdin2csv'
9
+ spec.version = Crowdin2csv::VERSION
10
+ spec.authors = ['takahashim']
11
+ spec.email = ['takahashimm@gmail.com']
12
+
13
+ spec.summary = 'Crowdin2csv converts xliff file from crowdin.com into CSV file.'
14
+ spec.description = 'Crowdin2csv converts xliff file from crowdin.com into CSV file.'
15
+ spec.homepage = 'https://github.com/takahashim/crowdin2csv'
16
+ spec.license = 'MIT'
17
+
18
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
19
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
20
+ if spec.respond_to?(:metadata)
21
+ spec.metadata['homepage_uri'] = spec.homepage
22
+ spec.metadata['source_code_uri'] = spec.homepage
23
+ spec.metadata['changelog_uri'] = 'https://github.com/takahashim/crowdin2csv/'
24
+ else
25
+ raise 'RubyGems 2.0 or newer is required to protect against ' \
26
+ 'public gem pushes.'
27
+ end
28
+
29
+ # Specify which files should be added to the gem when it is released.
30
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
31
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
32
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
33
+ end
34
+ spec.bindir = 'exe'
35
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
36
+ spec.require_paths = ['lib']
37
+
38
+ spec.add_dependency 'nokogiri'
39
+ spec.add_development_dependency 'bundler', '>= 2.1'
40
+ spec.add_development_dependency 'minitest', '>= 5.0'
41
+ spec.add_development_dependency 'rake', '>= 13.0'
42
+ spec.add_development_dependency 'rubocop', '>= 1.9.1'
43
+ spec.add_development_dependency 'rubocop-rake'
44
+ end
data/exe/crowdin2csv ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'crowdin2csv'
5
+
6
+ Crowdin2csv::CLI.execute(ARGV)
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'crowdin2csv/version'
4
+ require 'crowdin2csv/error'
5
+ require 'crowdin2csv/cli'
6
+ require 'nokogiri'
7
+ require 'csv'
8
+
9
+ module Crowdin2csv
10
+ CSV_HEADER = %w[unit_id file_id original source target resname note].freeze
11
+
12
+ module_function
13
+
14
+ def crowdin2csv(filename, output_filename)
15
+ CSV.open(output_filename, 'w') do |csv|
16
+ csv << CSV_HEADER
17
+ doc = Nokogiri::XML(File.read(filename), nil, 'UTF-8', &:strict)
18
+
19
+ doc.css('file').each do |file|
20
+ file_id = file.attr('id')
21
+ original = file.attr('original')
22
+ _source_lang = file.attr('source-language')
23
+ _target_lang = file.attr('target-language')
24
+ _datatype = file.attr('datatype')
25
+ file.css('trans-unit').each do |trans_unit|
26
+ trans_unit_id = trans_unit.attr('id')
27
+ resname = trans_unit.attr('resname')
28
+ source = trans_unit.css('source').text
29
+ target = trans_unit.css('target').text
30
+ note = trans_unit.css('note').text
31
+
32
+ cols = [trans_unit_id, file_id, original, source, target, resname, note]
33
+ csv << cols
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'optparse'
4
+
5
+ module Crowdin2csv
6
+ class CLI
7
+ def self.execute(args)
8
+ new.execute(args)
9
+ end
10
+
11
+ def initialize
12
+ @output_filename = nil
13
+ end
14
+
15
+ def execute(args)
16
+ opts = option_parser
17
+
18
+ opts.parse!(args)
19
+
20
+ raise Crowdin2csv::Error, 'xliff file not found.' if args.size != 1
21
+
22
+ filename = args[0]
23
+ raise Crowdin2csv::Error, 'xliff file is invalid.' unless File.file?(filename)
24
+
25
+ output_filename = @output_filename || "#{File.basename(filename, '.xliff')}.csv"
26
+ Crowdin2csv.crowdin2csv(filename, output_filename)
27
+ rescue Crowdin2csv::Error => e
28
+ warn e.message, opts.help
29
+ exit 1
30
+ end
31
+
32
+ private
33
+
34
+ def option_parser
35
+ OptionParser.new do |opt|
36
+ opt.banner = 'Usage: crowdin2csv [options] <xliff filename>'
37
+ opt.program_name = 'crowdin2csv'
38
+
39
+ opt.on('-o', '--output-file FILENAME', 'output csv filename') do |filename|
40
+ @output_filename = filename
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Crowdin2csv
4
+ class Error < StandardError; end
5
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Crowdin2csv
4
+ VERSION = '0.9.0'
5
+ end
metadata ADDED
@@ -0,0 +1,146 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: crowdin2csv
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.0
5
+ platform: ruby
6
+ authors:
7
+ - takahashim
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-02-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nokogiri
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '2.1'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '2.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '13.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '13.0'
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.9.1
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 1.9.1
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop-rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Crowdin2csv converts xliff file from crowdin.com into CSV file.
98
+ email:
99
+ - takahashimm@gmail.com
100
+ executables:
101
+ - crowdin2csv
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".gitignore"
106
+ - ".rubocop.yml"
107
+ - CHANGELOG.md
108
+ - Gemfile
109
+ - LICENSE
110
+ - README.md
111
+ - Rakefile
112
+ - bin/console
113
+ - bin/setup
114
+ - crowdin2csv.gemspec
115
+ - exe/crowdin2csv
116
+ - lib/crowdin2csv.rb
117
+ - lib/crowdin2csv/cli.rb
118
+ - lib/crowdin2csv/error.rb
119
+ - lib/crowdin2csv/version.rb
120
+ homepage: https://github.com/takahashim/crowdin2csv
121
+ licenses:
122
+ - MIT
123
+ metadata:
124
+ homepage_uri: https://github.com/takahashim/crowdin2csv
125
+ source_code_uri: https://github.com/takahashim/crowdin2csv
126
+ changelog_uri: https://github.com/takahashim/crowdin2csv/
127
+ post_install_message:
128
+ rdoc_options: []
129
+ require_paths:
130
+ - lib
131
+ required_ruby_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ required_rubygems_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ requirements: []
142
+ rubygems_version: 3.1.4
143
+ signing_key:
144
+ specification_version: 4
145
+ summary: Crowdin2csv converts xliff file from crowdin.com into CSV file.
146
+ test_files: []