localedata 0.1.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 +7 -0
- data/CHANGELOG.md +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +68 -0
- data/bin/localedata +4 -0
- data/lib/localedata/cli.rb +22 -0
- data/lib/localedata/client.rb +43 -0
- data/lib/localedata/configuration.rb +92 -0
- data/lib/localedata/downloader.rb +26 -0
- data/lib/localedata/installer.rb +41 -0
- data/lib/localedata/version.rb +3 -0
- data/lib/localedata.rb +9 -0
- data/localedata.gemspec +25 -0
- metadata +85 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: aa35b67d4dd4e4b8ae793fa8d14fc4a208c5d1e9e28f60ede7951d137ed6b6a7
|
|
4
|
+
data.tar.gz: 51302c306029316297b1757676c8feacf514b5fb62663276cc53ec1e7a8c6e8c
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: ab084ae29827b18272d07599963171286eda7948ff57f96e377ebd21728c07eb5724a410af4961f506c69b12489b82df9816cc7249d98572a37bbaff401980fb
|
|
7
|
+
data.tar.gz: d2608cde89e8ca2f0e70960ee045553d2561f184ac1eb272b14a53c548d49896435b31696800875fb6bcbccd1729f2facda3e4e2e8bbdc6329e55470e0f8fe52
|
data/CHANGELOG.md
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019 LocaleData
|
|
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,68 @@
|
|
|
1
|
+
# LocaleData Client
|
|
2
|
+
|
|
3
|
+
The `localedata` gem provides a command line interface for the Ruby on Rails translation management platform LocaleData on https://www.localedata.com.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add this line to your application's Gemfile:
|
|
8
|
+
|
|
9
|
+
```ruby
|
|
10
|
+
gem "localedata", group: :development
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Execute the following command:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
$ bundle install
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Or install it yourself as:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
$ gem install localedata
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Finally, create the default configuration file:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
$ bundle exec localedata install
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Configuration
|
|
32
|
+
|
|
33
|
+
You need to configure your access token on your development machine. Add the folowing line into your `.bashrc` (or `.zshrc`) file:
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
export LOCALEDATA_ACCESS_TOKEN="YOUR-SECRET-ACCESS-TOKEN"
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
You can edit the configuration in `config/localedata.yml`:
|
|
40
|
+
|
|
41
|
+
```yaml
|
|
42
|
+
projects:
|
|
43
|
+
- id: "YOUR-PROJECT-ID"
|
|
44
|
+
locales:
|
|
45
|
+
en: "config/locales/en.yml"
|
|
46
|
+
sk: "config/locales/sk.yml"
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
You can find the project ID and your access token on your LocaleData project page.
|
|
50
|
+
|
|
51
|
+
## Usage
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
localedata pull # downloads all your locales
|
|
55
|
+
localedata pull en de # downloads only the en and de locales
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Contributing
|
|
59
|
+
|
|
60
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/localedata/localedata-client. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
|
61
|
+
|
|
62
|
+
## License
|
|
63
|
+
|
|
64
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
65
|
+
|
|
66
|
+
## Code of Conduct
|
|
67
|
+
|
|
68
|
+
Everyone interacting in the LocaleData Client project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/localedata/localedata-client/blob/master/CODE_OF_CONDUCT.md).
|
data/bin/localedata
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
require "thor"
|
|
2
|
+
|
|
3
|
+
module Localedata
|
|
4
|
+
class Cli < Thor
|
|
5
|
+
desc "install [PROJECT_ID]", "Create a default configuration file"
|
|
6
|
+
def install(project_id=nil)
|
|
7
|
+
installer = Localedata::Installer.new
|
|
8
|
+
installer.install(project_id)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
desc "pull [LOCALES]", "Download the configured locales"
|
|
12
|
+
def pull(*locales)
|
|
13
|
+
downloader = Localedata::Downloader.new
|
|
14
|
+
downloader.download(locales)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
desc "version", "Print the current version"
|
|
18
|
+
def version
|
|
19
|
+
puts "Localedata #{Localedata::VERSION}"
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
require "json"
|
|
2
|
+
require "faraday"
|
|
3
|
+
|
|
4
|
+
module Localedata
|
|
5
|
+
class Client
|
|
6
|
+
def initialize(access_token)
|
|
7
|
+
@access_token = access_token
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def pull(project_id, locale)
|
|
11
|
+
success = false
|
|
12
|
+
status_code = 0
|
|
13
|
+
yaml_data = nil
|
|
14
|
+
error_message = nil
|
|
15
|
+
|
|
16
|
+
begin
|
|
17
|
+
get_data = { access_token: @access_token, project_id: project_id, language_code: locale }
|
|
18
|
+
response = connection.get("/api/v1/exports", get_data)
|
|
19
|
+
|
|
20
|
+
success = response.success?
|
|
21
|
+
status_code = response.status
|
|
22
|
+
|
|
23
|
+
data = JSON.parse(response.body)
|
|
24
|
+
yaml_data = data["yaml"]
|
|
25
|
+
error_message = data["error"]
|
|
26
|
+
|
|
27
|
+
rescue Faraday::ConnectionFailed
|
|
28
|
+
success = false
|
|
29
|
+
error_message = "API connection failed."
|
|
30
|
+
|
|
31
|
+
rescue JSON::ParserError
|
|
32
|
+
success = false
|
|
33
|
+
error_message = "API response parsing failed."
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
{ success: success, status_code: status_code, yaml: yaml_data, error: error_message }
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def connection
|
|
40
|
+
@connection ||= Faraday.new(url: "https://app.localedata.com")
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
require "erb"
|
|
2
|
+
require "yaml"
|
|
3
|
+
|
|
4
|
+
module Localedata
|
|
5
|
+
class Configuration
|
|
6
|
+
attr_reader :access_token
|
|
7
|
+
attr_reader :projects
|
|
8
|
+
|
|
9
|
+
def initialize
|
|
10
|
+
@access_token = ENV["LOCALEDATA_ACCESS_TOKEN"]
|
|
11
|
+
@projects = []
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def load_config_file
|
|
15
|
+
validate_config_file!
|
|
16
|
+
|
|
17
|
+
file_content = File.read(config_file_path)
|
|
18
|
+
yaml_data = ERB.new(file_content).result
|
|
19
|
+
config_data = YAML.load(yaml_data)
|
|
20
|
+
|
|
21
|
+
@access_token = (config_data["access_token"] || @access_token)
|
|
22
|
+
@projects = (config_data["projects"] || @projects)
|
|
23
|
+
|
|
24
|
+
validate_configuration!
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def relative_config_file_path
|
|
28
|
+
File.join("config", "localedata.yml")
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def config_file_path
|
|
32
|
+
File.expand_path(relative_config_file_path)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
private
|
|
36
|
+
|
|
37
|
+
def validate_config_file!
|
|
38
|
+
unless File.exist?(config_file_path)
|
|
39
|
+
puts "Error: #{relative_file_path} does not exist."
|
|
40
|
+
exit 1
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
unless File.readable?(config_file_path)
|
|
44
|
+
puts "Error: #{relative_file_path} is not readable."
|
|
45
|
+
exit 1
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def validate_configuration!
|
|
50
|
+
if @access_token.to_s.strip.empty?
|
|
51
|
+
puts "Error: \"access_token\" is missing."
|
|
52
|
+
exit 1
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
unless @projects.kind_of?(Array)
|
|
56
|
+
puts "Error: \"projects\" is not an array."
|
|
57
|
+
exit 1
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
@projects.each do |project|
|
|
61
|
+
if project["id"].to_s.strip.empty?
|
|
62
|
+
puts "Error: \"id\" in \"projects\" is missing."
|
|
63
|
+
exit 1
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
unless project["locales"].kind_of?(Hash)
|
|
67
|
+
puts "Error: \"locales\" in \"projects\" is not a hash."
|
|
68
|
+
exit 1
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
project["locales"].each do |language_code, relative_file_path|
|
|
72
|
+
file_path = File.expand_path(relative_file_path)
|
|
73
|
+
|
|
74
|
+
unless File.exist?(file_path)
|
|
75
|
+
puts "Error: #{relative_file_path} does not exist."
|
|
76
|
+
exit 1
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
unless File.readable?(file_path)
|
|
80
|
+
puts "Error: #{relative_file_path} is not readable."
|
|
81
|
+
exit 1
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
unless File.writable?(file_path)
|
|
85
|
+
puts "Error: #{relative_file_path} is not writable."
|
|
86
|
+
exit 1
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
module Localedata
|
|
2
|
+
class Downloader
|
|
3
|
+
def download(locales)
|
|
4
|
+
configuration = Localedata::Configuration.new
|
|
5
|
+
configuration.load_config_file
|
|
6
|
+
|
|
7
|
+
client = Localedata::Client.new(configuration.access_token)
|
|
8
|
+
configuration.projects.each do |project|
|
|
9
|
+
project["locales"].each do |language_code, relative_file_path|
|
|
10
|
+
next if locales.any? && !locales.include?(language_code)
|
|
11
|
+
|
|
12
|
+
print "Downloading #{language_code} into #{relative_file_path}..."
|
|
13
|
+
data = client.pull(project["id"], language_code)
|
|
14
|
+
if data[:success]
|
|
15
|
+
file_path = File.expand_path(relative_file_path)
|
|
16
|
+
File.write(file_path, data[:yaml])
|
|
17
|
+
puts "Done."
|
|
18
|
+
else
|
|
19
|
+
puts "FAIL!"
|
|
20
|
+
puts "Error #{data[:status_code]}: #{data[:error]}"
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
module Localedata
|
|
2
|
+
class Installer
|
|
3
|
+
def install(project_id)
|
|
4
|
+
configuration = Localedata::Configuration.new
|
|
5
|
+
|
|
6
|
+
relative_config_file_path = configuration.relative_config_file_path
|
|
7
|
+
config_file_path = configuration.config_file_path
|
|
8
|
+
|
|
9
|
+
if File.exist?(config_file_path)
|
|
10
|
+
puts "A #{relative_config_file_path} already exists."
|
|
11
|
+
return
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
FileUtils.mkdir_p(File.dirname(config_file_path))
|
|
15
|
+
File.write(config_file_path, default_config(project_id))
|
|
16
|
+
|
|
17
|
+
puts congratulation(relative_config_file_path)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
private
|
|
21
|
+
|
|
22
|
+
def default_config(project_id)
|
|
23
|
+
<<~YAML
|
|
24
|
+
projects:
|
|
25
|
+
- id: "#{project_id || 'YOUR-PROJECT-ID'}"
|
|
26
|
+
locales:
|
|
27
|
+
en: "config/locales/en.yml"
|
|
28
|
+
YAML
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def congratulation(config_file_path)
|
|
32
|
+
<<~CONGRATS
|
|
33
|
+
Congratulations! Localedata was successfully installed.
|
|
34
|
+
We generated a config file containing some default settings:
|
|
35
|
+
|
|
36
|
+
#{config_file_path}
|
|
37
|
+
|
|
38
|
+
CONGRATS
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
data/lib/localedata.rb
ADDED
data/localedata.gemspec
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
3
|
+
require "localedata/version"
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |spec|
|
|
6
|
+
spec.name = "localedata"
|
|
7
|
+
spec.version = Localedata::VERSION
|
|
8
|
+
spec.authors = ["Juraj Kostolansky"]
|
|
9
|
+
spec.email = ["hello@localedata.com"]
|
|
10
|
+
|
|
11
|
+
spec.summary = "CLI for the Ruby on Rails translation management platform LocaleData"
|
|
12
|
+
spec.homepage = "https://github.com/localedata/localedata-client"
|
|
13
|
+
spec.license = "MIT"
|
|
14
|
+
|
|
15
|
+
spec.files = Dir["README.md", "LICENSE.txt", "CHANGELOG.md", "localedata.gemspec",
|
|
16
|
+
"lib/**/*.rb", "bin/*"]
|
|
17
|
+
|
|
18
|
+
spec.require_paths = ["lib"]
|
|
19
|
+
spec.executables = ["localedata"]
|
|
20
|
+
|
|
21
|
+
spec.required_ruby_version = ">= 2.3.0"
|
|
22
|
+
|
|
23
|
+
spec.add_dependency 'thor', '>= 0.20.0'
|
|
24
|
+
spec.add_dependency 'faraday', '>= 0.12.0'
|
|
25
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: localedata
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Juraj Kostolansky
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2019-05-02 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: thor
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ">="
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: 0.20.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.20.0
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: faraday
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - ">="
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: 0.12.0
|
|
34
|
+
type: :runtime
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - ">="
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: 0.12.0
|
|
41
|
+
description:
|
|
42
|
+
email:
|
|
43
|
+
- hello@localedata.com
|
|
44
|
+
executables:
|
|
45
|
+
- localedata
|
|
46
|
+
extensions: []
|
|
47
|
+
extra_rdoc_files: []
|
|
48
|
+
files:
|
|
49
|
+
- CHANGELOG.md
|
|
50
|
+
- LICENSE.txt
|
|
51
|
+
- README.md
|
|
52
|
+
- bin/localedata
|
|
53
|
+
- lib/localedata.rb
|
|
54
|
+
- lib/localedata/cli.rb
|
|
55
|
+
- lib/localedata/client.rb
|
|
56
|
+
- lib/localedata/configuration.rb
|
|
57
|
+
- lib/localedata/downloader.rb
|
|
58
|
+
- lib/localedata/installer.rb
|
|
59
|
+
- lib/localedata/version.rb
|
|
60
|
+
- localedata.gemspec
|
|
61
|
+
homepage: https://github.com/localedata/localedata-client
|
|
62
|
+
licenses:
|
|
63
|
+
- MIT
|
|
64
|
+
metadata: {}
|
|
65
|
+
post_install_message:
|
|
66
|
+
rdoc_options: []
|
|
67
|
+
require_paths:
|
|
68
|
+
- lib
|
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
70
|
+
requirements:
|
|
71
|
+
- - ">="
|
|
72
|
+
- !ruby/object:Gem::Version
|
|
73
|
+
version: 2.3.0
|
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
75
|
+
requirements:
|
|
76
|
+
- - ">="
|
|
77
|
+
- !ruby/object:Gem::Version
|
|
78
|
+
version: '0'
|
|
79
|
+
requirements: []
|
|
80
|
+
rubyforge_project:
|
|
81
|
+
rubygems_version: 2.7.6
|
|
82
|
+
signing_key:
|
|
83
|
+
specification_version: 4
|
|
84
|
+
summary: CLI for the Ruby on Rails translation management platform LocaleData
|
|
85
|
+
test_files: []
|