international 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +4 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +99 -0
- data/Rakefile +6 -0
- data/bin/international +5 -0
- data/international.gemspec +39 -0
- data/lib/android_manager.rb +50 -0
- data/lib/international.rb +116 -0
- data/lib/international/version.rb +3 -0
- data/lib/templates/android.erb +4 -0
- data/lib/templates/ios.erb +2 -0
- metadata +164 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 92a3de542246b4ca4d95886749d6cb8cddd565cf
|
4
|
+
data.tar.gz: c5467a8d283df45d8b264769c2d94ab1c543b148
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3fd9abc59711d7f841a1b3c85cd39b7e3aeab3c5c898f3a759154ec9a6c343b4f416c23797229ed94fa11728714af7be23d887d2370d512b93772a0b0e6e8c4d
|
7
|
+
data.tar.gz: 320cee7573d83d49ca014de2d2ee6e70c4a1960a9beb1624596a76907bef148576412ef33fd260236257d68c6c6a29937139863415b2f3626720580eeaa0f9df
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 cesarferreira
|
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,99 @@
|
|
1
|
+
# International [![Gem Version](https://badge.fury.io/rb/international.svg)](https://badge.fury.io/rb/international)
|
2
|
+
|
3
|
+
> Convert CSV to localization strings, for both ANDROID and iOS
|
4
|
+
|
5
|
+
<!-- <p align="center">
|
6
|
+
<img src="extras/terminal.gif" />
|
7
|
+
</p>
|
8
|
+
|
9
|
+
-->
|
10
|
+
## Usage
|
11
|
+
|
12
|
+
This will create the localization for you, based on a `.csv` file
|
13
|
+
|
14
|
+
```bash
|
15
|
+
international --csv ~/import.csv
|
16
|
+
```
|
17
|
+
### Will have this output:
|
18
|
+
English, `/values-en/translation.xml`:
|
19
|
+
|
20
|
+
```xml
|
21
|
+
<?xml version="1.0" ?>
|
22
|
+
<resources>
|
23
|
+
<string name="welcome_message">hello</string>
|
24
|
+
<string name="thank_you_message">thank you</string>
|
25
|
+
<string name="goodbye_message">goodbye</string>
|
26
|
+
</resources>
|
27
|
+
```
|
28
|
+
Portuguese, `/values-pt/translation.xml`:
|
29
|
+
```xml
|
30
|
+
<?xml version="1.0" ?>
|
31
|
+
<resources>
|
32
|
+
<string name="welcome_message">Bem vindo</string>
|
33
|
+
<string name="thank_you_message">Obrigado</string>
|
34
|
+
<string name="goodbye_message">Adeus</string>
|
35
|
+
</resources>
|
36
|
+
```
|
37
|
+
|
38
|
+
Given this `~/import.csv`
|
39
|
+
```csv
|
40
|
+
keys,pt,en,es
|
41
|
+
welcome_message,Bem vindo,welcome,bienvenido
|
42
|
+
goodbye,adeus,goodbye,adios
|
43
|
+
```
|
44
|
+
|
45
|
+
|
46
|
+
<b>You can also send it straight to some folder:</b>
|
47
|
+
|
48
|
+
```bash
|
49
|
+
international --csv ~/import.csv --output app/src/main/res/
|
50
|
+
```
|
51
|
+
|
52
|
+
|
53
|
+
<!--
|
54
|
+
.Strings - iOS
|
55
|
+
en.strings
|
56
|
+
```
|
57
|
+
/* */
|
58
|
+
"welcome_message" = "hello";
|
59
|
+
|
60
|
+
/* */
|
61
|
+
"thank_you_message" = "thank you";
|
62
|
+
|
63
|
+
/* */
|
64
|
+
"goodbye_message" = "goodbye";
|
65
|
+
ru.strings
|
66
|
+
|
67
|
+
/* */
|
68
|
+
"welcome_message" = "здравствуйте";
|
69
|
+
|
70
|
+
/* */
|
71
|
+
"thank_you_message" = "спасибо";
|
72
|
+
|
73
|
+
/* */
|
74
|
+
"goodbye_message" = "До свидания";
|
75
|
+
```
|
76
|
+
-->
|
77
|
+
|
78
|
+
|
79
|
+
## Full usage
|
80
|
+
```bash
|
81
|
+
|
82
|
+
Usage: international [OPTIONS]
|
83
|
+
|
84
|
+
Options
|
85
|
+
-c, --csv PATH_TO_CSV # Path to the .csv file
|
86
|
+
-o, --output PATH_TO_OUTPUT # Path to the desired output folder
|
87
|
+
-d, --dryrun # Only simulates the output and don't write files
|
88
|
+
-h, --help # Displays help
|
89
|
+
-v, --version # Displays version
|
90
|
+
|
91
|
+
```
|
92
|
+
|
93
|
+
## Installation
|
94
|
+
|
95
|
+
$ gem install international
|
96
|
+
|
97
|
+
## License
|
98
|
+
|
99
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/international
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'international/version'
|
5
|
+
|
6
|
+
#rake build # Build international-0.0.1.gem into the pkg directory
|
7
|
+
#rake install # Build and install international-0.0.1.gem into system gems
|
8
|
+
#rake release # Create tag v0.0.1 and build and push international-0.0.1.gem t...
|
9
|
+
#rake spec # Run RSpec code examples
|
10
|
+
|
11
|
+
Gem::Specification.new do |spec|
|
12
|
+
spec.name = "international"
|
13
|
+
spec.version = International::VERSION
|
14
|
+
spec.authors = ["cesarferreira"]
|
15
|
+
spec.email = ["cesar.manuel.ferreira@gmail.com"]
|
16
|
+
|
17
|
+
spec.summary = %q{Convert CSV to localization strings}
|
18
|
+
spec.description = %q{Convert CSV to localization strings}
|
19
|
+
spec.homepage = "https://github.com/cesarferreira/international"
|
20
|
+
spec.license = "MIT"
|
21
|
+
|
22
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
23
|
+
spec.bindir = "bin"
|
24
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
25
|
+
spec.require_paths = ["lib"]
|
26
|
+
|
27
|
+
spec.required_ruby_version = '>= 2.0.0'
|
28
|
+
|
29
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
30
|
+
spec.add_development_dependency 'pry-byebug', '~> 3.2'
|
31
|
+
spec.add_development_dependency 'rspec'
|
32
|
+
|
33
|
+
spec.add_dependency 'bundler', '~> 1.7'
|
34
|
+
spec.add_dependency 'colorize', '~> 0.7'
|
35
|
+
|
36
|
+
spec.add_dependency 'erubis', '~> 2.7'
|
37
|
+
spec.add_dependency 'fastercsv', '~> 1.5', '>= 1.5.5'
|
38
|
+
|
39
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'erb'
|
2
|
+
require 'erubis'
|
3
|
+
require 'fileutils'
|
4
|
+
require 'colorize'
|
5
|
+
require 'pry'
|
6
|
+
|
7
|
+
class AndroidManager
|
8
|
+
def initialize language, items, output_folder, dryrun=false
|
9
|
+
@language = language
|
10
|
+
@dryrun = dryrun
|
11
|
+
@items = items
|
12
|
+
@path = output_folder
|
13
|
+
@template = File.read(get_template_path)
|
14
|
+
end
|
15
|
+
|
16
|
+
def get_template_path
|
17
|
+
File.join(File.dirname(__FILE__), 'templates/android.erb') # add proper number of ..
|
18
|
+
end
|
19
|
+
|
20
|
+
def get_file_name
|
21
|
+
"values-#{@language}/translation.xml"
|
22
|
+
end
|
23
|
+
|
24
|
+
def create_file
|
25
|
+
file_name = get_file_name
|
26
|
+
destination_file_path = "#{@path}#{file_name}"
|
27
|
+
|
28
|
+
pretty_print destination_file_path
|
29
|
+
|
30
|
+
unless @dryrun
|
31
|
+
|
32
|
+
dirname = File.dirname(destination_file_path)
|
33
|
+
unless File.directory?(dirname)
|
34
|
+
FileUtils.mkdir_p(dirname)
|
35
|
+
end
|
36
|
+
File.open(destination_file_path, 'w') { |f| f.write(render) }
|
37
|
+
else
|
38
|
+
puts render.yellow
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def pretty_print(path_to_file)
|
43
|
+
subtracted = path_to_file.gsub("#{Dir.pwd}/",'')
|
44
|
+
puts "created #{subtracted.green} successfully"
|
45
|
+
end
|
46
|
+
|
47
|
+
def render
|
48
|
+
ERB.new(@template).result(binding)
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,116 @@
|
|
1
|
+
require 'colorize'
|
2
|
+
require 'international/version'
|
3
|
+
require 'csv'
|
4
|
+
require 'android_manager'
|
5
|
+
|
6
|
+
module International
|
7
|
+
|
8
|
+
class MainApp
|
9
|
+
|
10
|
+
def initialize(arguments)
|
11
|
+
|
12
|
+
# defaults
|
13
|
+
@path_to_output = 'output/'
|
14
|
+
@path_to_csv = nil
|
15
|
+
@dryrun = false
|
16
|
+
|
17
|
+
# Parse Options
|
18
|
+
arguments.push "-h" if arguments.length == 0
|
19
|
+
create_options_parser(arguments)
|
20
|
+
|
21
|
+
manage_opts
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
def call
|
26
|
+
end
|
27
|
+
|
28
|
+
### Options parser
|
29
|
+
def create_options_parser(args)
|
30
|
+
|
31
|
+
args.options do |opts|
|
32
|
+
opts.banner = "Usage: international [OPTIONS]"
|
33
|
+
opts.separator ''
|
34
|
+
opts.separator "Options"
|
35
|
+
|
36
|
+
opts.on('-c PATH_TO_CSV', '--csv PATH_TO_CSV', 'Path to the .csv file') do |csv_path|
|
37
|
+
@path_to_csv = csv_path
|
38
|
+
end
|
39
|
+
|
40
|
+
opts.on('-o PATH_TO_OUTPUT', '--output PATH_TO_OUTPUT', 'Path to the desired output folder') do |path_to_output|
|
41
|
+
unless path_to_output[0,1] == '/'
|
42
|
+
path_to_output = "#{path_to_output}/"
|
43
|
+
end
|
44
|
+
|
45
|
+
@path_to_output = path_to_output
|
46
|
+
end
|
47
|
+
|
48
|
+
opts.on('-d', '--dryrun', 'Only simulates the output and don\'t write files') do |aa|
|
49
|
+
@dryrun = true
|
50
|
+
end
|
51
|
+
|
52
|
+
opts.on('-h', '--help', 'Displays help') do
|
53
|
+
@require_analyses = false
|
54
|
+
puts opts.help
|
55
|
+
exit
|
56
|
+
end
|
57
|
+
opts.on('-v', '--version', 'Displays version') do
|
58
|
+
@require_analyses = false
|
59
|
+
puts International::VERSION
|
60
|
+
exit
|
61
|
+
end
|
62
|
+
opts.parse!
|
63
|
+
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
### Manage options
|
68
|
+
def manage_opts
|
69
|
+
|
70
|
+
unless @path_to_csv
|
71
|
+
puts "Please give me a path to a CSV".yellow
|
72
|
+
exit 1
|
73
|
+
end
|
74
|
+
|
75
|
+
hash = csv_to_hash(@path_to_csv)
|
76
|
+
separate_languages hash
|
77
|
+
end
|
78
|
+
|
79
|
+
### CSV TO HASH
|
80
|
+
def csv_to_hash(path_to_csv)
|
81
|
+
file = File.open(path_to_csv, "rb")
|
82
|
+
body = file.read
|
83
|
+
|
84
|
+
body = "key#{body}" if body[0,1] == ','
|
85
|
+
|
86
|
+
CSV::Converters[:blank_to_nil] = lambda do |field|
|
87
|
+
field && field.empty? ? nil : field
|
88
|
+
end
|
89
|
+
|
90
|
+
csv = CSV.new(body, :headers => true, :header_converters => :symbol, :converters => [:all, :blank_to_nil])
|
91
|
+
|
92
|
+
csv.to_a.map {|row| row.to_hash }
|
93
|
+
end
|
94
|
+
|
95
|
+
def separate_languages(all)
|
96
|
+
languages = all.first.keys.drop(1)
|
97
|
+
separated = Hash.new
|
98
|
+
|
99
|
+
languages.each do |lang|
|
100
|
+
items = Array.new
|
101
|
+
all.each do |row|
|
102
|
+
item = {
|
103
|
+
:key => row.first.last, # dem hacks
|
104
|
+
:translation => row[lang]
|
105
|
+
}
|
106
|
+
|
107
|
+
items.push item
|
108
|
+
end
|
109
|
+
|
110
|
+
manager = AndroidManager.new lang, items, @path_to_output, @dryrun
|
111
|
+
manager.create_file
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
116
|
+
end
|
metadata
ADDED
@@ -0,0 +1,164 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: international
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- cesarferreira
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-01-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '10.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '10.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: pry-byebug
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.2'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.2'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
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.7'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.7'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: colorize
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.7'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.7'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: erubis
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '2.7'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '2.7'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: fastercsv
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '1.5'
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: 1.5.5
|
107
|
+
type: :runtime
|
108
|
+
prerelease: false
|
109
|
+
version_requirements: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - "~>"
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '1.5'
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: 1.5.5
|
117
|
+
description: Convert CSV to localization strings
|
118
|
+
email:
|
119
|
+
- cesar.manuel.ferreira@gmail.com
|
120
|
+
executables:
|
121
|
+
- international
|
122
|
+
extensions: []
|
123
|
+
extra_rdoc_files: []
|
124
|
+
files:
|
125
|
+
- ".gitignore"
|
126
|
+
- ".rspec"
|
127
|
+
- ".travis.yml"
|
128
|
+
- Gemfile
|
129
|
+
- LICENSE.txt
|
130
|
+
- README.md
|
131
|
+
- Rakefile
|
132
|
+
- bin/international
|
133
|
+
- international.gemspec
|
134
|
+
- lib/android_manager.rb
|
135
|
+
- lib/international.rb
|
136
|
+
- lib/international/version.rb
|
137
|
+
- lib/templates/android.erb
|
138
|
+
- lib/templates/ios.erb
|
139
|
+
homepage: https://github.com/cesarferreira/international
|
140
|
+
licenses:
|
141
|
+
- MIT
|
142
|
+
metadata: {}
|
143
|
+
post_install_message:
|
144
|
+
rdoc_options: []
|
145
|
+
require_paths:
|
146
|
+
- lib
|
147
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - ">="
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: 2.0.0
|
152
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
153
|
+
requirements:
|
154
|
+
- - ">="
|
155
|
+
- !ruby/object:Gem::Version
|
156
|
+
version: '0'
|
157
|
+
requirements: []
|
158
|
+
rubyforge_project:
|
159
|
+
rubygems_version: 2.4.8
|
160
|
+
signing_key:
|
161
|
+
specification_version: 4
|
162
|
+
summary: Convert CSV to localization strings
|
163
|
+
test_files: []
|
164
|
+
has_rdoc:
|