medela-bst-android-excel2xml 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +13 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +20 -0
- data/Rakefile +2 -0
- data/bin/medela-bst-android-excel2xml +12 -0
- data/lib/medela_bst_android_excel2xml.rb +12 -0
- data/lib/medela_bst_android_excel2xml/application.rb +28 -0
- data/lib/medela_bst_android_excel2xml/converter.rb +112 -0
- data/lib/medela_bst_android_excel2xml/version.rb +3 -0
- data/medela_bst_android_excel2xml.gemspec +34 -0
- metadata +127 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ad317c67f9477ee8911c40444b7dab830d91dac5
|
4
|
+
data.tar.gz: ef9196e1066ceeab1a06ecd5dbc31f3524c4b44e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e5abd4774492d52deb040efd0874e297c565f28a188ce330547f9e321a71b2bfe14ee8b53b883f2f02078ae73a614906ea3e301b0fa59e96813007819a1b528d
|
7
|
+
data.tar.gz: c4ac7375475064b038fdf1ed1a9937d315377c157b2eb4cb46a1e58a72a8bdcab5a7858e5ebe5126f6d319c2dc7672d930ccf7c580ddab625f41ae0f0056d8ba
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Daniel Kummer
|
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
|
13
|
+
all 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
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# Medela BST excel2xml converter
|
2
|
+
|
3
|
+
This litte gem supplies a command line tool to generate medela bst language files based on the medela translation excel.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
|
8
|
+
Install the gem using the following:
|
9
|
+
|
10
|
+
$ gem install medela-bst-android-excel2xml
|
11
|
+
|
12
|
+
You might need to install bundler first:
|
13
|
+
|
14
|
+
$ gem install bundler
|
15
|
+
|
16
|
+
## Usage
|
17
|
+
|
18
|
+
The script is directly accessible from the console, get more information using 'help':
|
19
|
+
|
20
|
+
$ medela-bst-android-excel2xml help generate
|
data/Rakefile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'thor'
|
2
|
+
require 'uri'
|
3
|
+
require 'roo'
|
4
|
+
require 'nokogiri'
|
5
|
+
|
6
|
+
require 'medela_bst_android_excel2xml/version'
|
7
|
+
require 'medela_bst_android_excel2xml/converter'
|
8
|
+
require 'medela_bst_android_excel2xml/application'
|
9
|
+
|
10
|
+
module MedelaBstAndroidExcel2xml
|
11
|
+
# Empty module
|
12
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module MedelaBstAndroidExcel2xml
|
2
|
+
class Application < Thor
|
3
|
+
|
4
|
+
desc 'generate XLSX_PATH', 'generate xml files from specified excel file'
|
5
|
+
long_desc <<-LONGDESC
|
6
|
+
Generate android xml language files based on an excel import file. The excel file must be in the new .xlsx format.
|
7
|
+
|
8
|
+
With --out option, an output directory can be specified, without this option the current directory is used.
|
9
|
+
|
10
|
+
With --lang option, specific languages can be generated, the default generates files for all found languages.
|
11
|
+
|
12
|
+
Example usage:
|
13
|
+
|
14
|
+
generate labels.xlsx --lang=de en fr
|
15
|
+
|
16
|
+
LONGDESC
|
17
|
+
option :out, type: :string, banner: '<output directory>'
|
18
|
+
option :lang, type: :array, banner: '<language1,language2,...>'
|
19
|
+
|
20
|
+
def generate(xlsx_path)
|
21
|
+
|
22
|
+
converter = Converter.new(xlsx_path)
|
23
|
+
converter.destination_path = options[:out] if options[:out]
|
24
|
+
converter.languages = options[:lang] if options[:lang]
|
25
|
+
converter.run
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,112 @@
|
|
1
|
+
module MedelaBstAndroidExcel2xml
|
2
|
+
|
3
|
+
class Converter
|
4
|
+
|
5
|
+
attr_accessor :destination_path, :languages
|
6
|
+
|
7
|
+
def initialize(spreadsheet_path)
|
8
|
+
@file = Roo::Spreadsheet.open(spreadsheet_path)
|
9
|
+
@destination_path ||= Dir.pwd
|
10
|
+
@languages ||= []
|
11
|
+
end
|
12
|
+
|
13
|
+
def run
|
14
|
+
translations = parse_sheet
|
15
|
+
translations.select!(@languages) unless @languages.empty?
|
16
|
+
translations.each do |language, translation_hash|
|
17
|
+
xml = generate_xml(translation_hash)
|
18
|
+
save_xml(xml, language)
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
protected
|
24
|
+
|
25
|
+
##
|
26
|
+
# Parse the entire sheet into a hash where the key represents the language and the entry is an array of name value
|
27
|
+
# hashes
|
28
|
+
#
|
29
|
+
def parse_sheet
|
30
|
+
translation_sheet = @file.sheet(0)
|
31
|
+
all_headers = translation_sheet.row(2)
|
32
|
+
|
33
|
+
row_hashes = []
|
34
|
+
# parse header
|
35
|
+
translation_sheet.parse(header_search: all_headers, clean: true).each do |row_hash|
|
36
|
+
row_hashes << row_hash.delete_if { |key, value| key.to_s.match(/(notes|-chars)/) || value.nil? }
|
37
|
+
end
|
38
|
+
|
39
|
+
#remove header row from sheet hashes
|
40
|
+
row_hashes.shift
|
41
|
+
|
42
|
+
# cleanup array - delete hashes with empty tech keys
|
43
|
+
row_hashes.delete_if { |entry| entry['tech. key'].nil? }
|
44
|
+
|
45
|
+
i18n_hash = {}
|
46
|
+
|
47
|
+
# transform to hash containing name value pairs grouped by language
|
48
|
+
row_hashes.each do |hash|
|
49
|
+
translation_hash = hash.reject { |k, v| k == 'tech. key' }
|
50
|
+
translation_hash.each do |language, text|
|
51
|
+
i18n_hash[language] ||= {}
|
52
|
+
i18n_hash[language][hash['tech. key']] = text
|
53
|
+
end
|
54
|
+
end
|
55
|
+
i18n_hash
|
56
|
+
end
|
57
|
+
|
58
|
+
def generate_xml(translations)
|
59
|
+
Nokogiri::XML::Builder.new(encoding: 'UTF-8') do |xml|
|
60
|
+
xml.resources {
|
61
|
+
translations.sort.each do |name, value|
|
62
|
+
|
63
|
+
# Normalize attr names
|
64
|
+
name_attr = name.downcase
|
65
|
+
name_attr = name_attr.upcase if name_attr.include?('_b2c')
|
66
|
+
name_attr = 'new_' if name_attr == 'new'
|
67
|
+
|
68
|
+
#escape single quotes
|
69
|
+
value.gsub!("'", %q(\\\'))
|
70
|
+
|
71
|
+
#leading 0 replacement for dates
|
72
|
+
if name_attr == 'sectionstatsfrequencyperiodtypeweeklyweekof'
|
73
|
+
str_replace_index = 0
|
74
|
+
value.gsub!(/(%@)/) do
|
75
|
+
str_replace_index += 1
|
76
|
+
"%#{str_replace_index}$02d"
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
# Replace all %@ with numbered java placeholders, eg. %1$s %2$s etc
|
81
|
+
str_replace_index = 0
|
82
|
+
value.gsub!(/(%@)/) do
|
83
|
+
str_replace_index += 1
|
84
|
+
"%#{str_replace_index}$s"
|
85
|
+
end
|
86
|
+
|
87
|
+
int_replace_index = 0
|
88
|
+
value.gsub!(/(%X%)/) do
|
89
|
+
int_replace_index += 1
|
90
|
+
"%#{int_replace_index}$d"
|
91
|
+
end
|
92
|
+
value.gsub!(/(%Y%)/, '%2$s')
|
93
|
+
|
94
|
+
value.gsub!(/(%DAY%)/, '%1$s')
|
95
|
+
|
96
|
+
# put html inside cdata
|
97
|
+
if value.include?('html')
|
98
|
+
xml.string(name: name_attr) { xml.cdata(CGI.unescapeHTML(value)) }
|
99
|
+
else
|
100
|
+
xml.string(value, name: name_attr)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
}
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def save_xml(xml, language)
|
108
|
+
File.open(File.join(@destination_path, 'strings_' + language + '.xml'), 'w') { |f| f.write(xml.to_xml) }
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'medela_bst_android_excel2xml/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'medela-bst-android-excel2xml'
|
8
|
+
spec.version = MedelaBstAndroidExcel2xml::VERSION
|
9
|
+
spec.authors = ['Daniel Kummer']
|
10
|
+
spec.email = ['daniel.kummer@namics.com']
|
11
|
+
spec.required_ruby_version = '>=2'
|
12
|
+
|
13
|
+
#if spec.respond_to?(:metadata)
|
14
|
+
# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com' to prevent pushes to rubygems.org, or delete to allow pushes to any server."
|
15
|
+
#end
|
16
|
+
|
17
|
+
spec.summary = %q{Generate android language files based on the translation excel worksheet.}
|
18
|
+
spec.homepage = 'http://www.namics.com'
|
19
|
+
spec.license = 'MIT'
|
20
|
+
|
21
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
22
|
+
#spec.bindir = 'exe'
|
23
|
+
#spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
|
+
spec.executables = ['medela-bst-android-excel2xml']
|
25
|
+
spec.default_executable = 'medela-bst-android-excel2xml'
|
26
|
+
spec.require_paths = ['lib']
|
27
|
+
|
28
|
+
spec.add_dependency 'roo', '~> 2.0.0'
|
29
|
+
spec.add_dependency 'nokogiri', '~> 1.6.6'
|
30
|
+
spec.add_dependency 'thor', '~> 0.19'
|
31
|
+
|
32
|
+
spec.add_development_dependency 'bundler', '~> 1.8'
|
33
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
34
|
+
end
|
metadata
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: medela-bst-android-excel2xml
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Daniel Kummer
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-06-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: roo
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.0.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.0.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: nokogiri
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.6.6
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.6.6
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: thor
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.19'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.19'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.8'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.8'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '10.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '10.0'
|
83
|
+
description:
|
84
|
+
email:
|
85
|
+
- daniel.kummer@namics.com
|
86
|
+
executables:
|
87
|
+
- medela-bst-android-excel2xml
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- ".gitignore"
|
92
|
+
- Gemfile
|
93
|
+
- Gemfile.lock
|
94
|
+
- LICENSE.txt
|
95
|
+
- README.md
|
96
|
+
- Rakefile
|
97
|
+
- bin/medela-bst-android-excel2xml
|
98
|
+
- lib/medela_bst_android_excel2xml.rb
|
99
|
+
- lib/medela_bst_android_excel2xml/application.rb
|
100
|
+
- lib/medela_bst_android_excel2xml/converter.rb
|
101
|
+
- lib/medela_bst_android_excel2xml/version.rb
|
102
|
+
- medela_bst_android_excel2xml.gemspec
|
103
|
+
homepage: http://www.namics.com
|
104
|
+
licenses:
|
105
|
+
- MIT
|
106
|
+
metadata: {}
|
107
|
+
post_install_message:
|
108
|
+
rdoc_options: []
|
109
|
+
require_paths:
|
110
|
+
- lib
|
111
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '2'
|
116
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
requirements: []
|
122
|
+
rubyforge_project:
|
123
|
+
rubygems_version: 2.4.6
|
124
|
+
signing_key:
|
125
|
+
specification_version: 4
|
126
|
+
summary: Generate android language files based on the translation excel worksheet.
|
127
|
+
test_files: []
|