polyglot_cli 0.1.2 → 0.1.3
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 +4 -4
- data/exe/polyglot +4 -3
- data/lib/polyglot_cli/commands/push.rb +1 -1
- data/lib/polyglot_cli/commands/setup.rb +52 -7
- data/lib/polyglot_cli/helpers/general.rb +17 -3
- data/lib/polyglot_cli/helpers/terminal.rb +1 -1
- data/lib/polyglot_cli/io/locale.rb +1 -1
- data/lib/polyglot_cli/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 141a3da0e4867789a6aa6170057bfad33d7bad09
|
4
|
+
data.tar.gz: 270b6f237b47c64add31b924c0db5d0a73e363d8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3fa4d6f205c3ffd0531e6ab327a5fd05ea22da480ff91f3ee3e6e271d9ae6cc8100f0680a486de14e11ec220fb90d770bea3ff587e97e10c5a54879ba4ddc6a6
|
7
|
+
data.tar.gz: 51dfe3730446c59f57a2139f39f6bdb6db6242153d55e914d648fd83ff17ace64c17d168ddba1b49fd1babf74fbc7b566e8197e7c0795c19271c7312f9dd5245
|
data/exe/polyglot
CHANGED
@@ -19,11 +19,12 @@ command :login do |c|
|
|
19
19
|
end
|
20
20
|
|
21
21
|
command :init do |c|
|
22
|
-
c.syntax = 'polyglot init'
|
22
|
+
c.syntax = 'polyglot init [options]'
|
23
23
|
c.description = 'Sets up a Polyglot project you need for your current project.'
|
24
|
-
c.
|
24
|
+
c.option '--query STRING', String, 'Only shows projects that matches string'
|
25
|
+
c.action do |_args, options|
|
25
26
|
PolyglotCli::ErrorHandler.rescuable do
|
26
|
-
PolyglotCli::Command::Setup.init
|
27
|
+
PolyglotCli::Command::Setup.init(options)
|
27
28
|
end
|
28
29
|
end
|
29
30
|
end
|
@@ -69,7 +69,7 @@ module PolyglotCli
|
|
69
69
|
new_value = local.delete(translation.translation_key.name)
|
70
70
|
return if new_value == translation.value
|
71
71
|
|
72
|
-
prompt.ok("Updating translation #{translation.
|
72
|
+
prompt.ok("Updating translation for key: #{translation.translation_key.name}...")
|
73
73
|
translation.update(value: new_value)
|
74
74
|
end
|
75
75
|
|
@@ -1,25 +1,62 @@
|
|
1
|
+
require 'commander/blank'
|
2
|
+
require 'commander/command'
|
3
|
+
|
1
4
|
module PolyglotCli
|
2
5
|
module Command
|
3
6
|
class Setup
|
4
7
|
include Helper::Terminal
|
5
8
|
include Helper::General
|
6
9
|
|
7
|
-
def self.init
|
8
|
-
new.call
|
10
|
+
def self.init(options)
|
11
|
+
new(options).call
|
12
|
+
end
|
13
|
+
|
14
|
+
def initialize(options = Commander::Command::Options.new)
|
15
|
+
@options = options
|
9
16
|
end
|
10
17
|
|
11
18
|
def call
|
12
|
-
|
13
|
-
project_id: project_id_prompt,
|
19
|
+
@config = {
|
20
|
+
project_id: project_id_prompt(filtered_projects),
|
14
21
|
locale_path: locale_path_prompt
|
15
|
-
|
22
|
+
}
|
23
|
+
PolyglotCli::IO::Config.write(@config.merge(locale_mapping: locale_mapping))
|
16
24
|
success
|
25
|
+
rescue TTY::Prompt::ConfigurationError
|
26
|
+
prompt.error('Could not find any projects. Please try a new search.')
|
17
27
|
end
|
18
28
|
|
19
29
|
private
|
20
30
|
|
21
|
-
def
|
22
|
-
|
31
|
+
def locale_mapping
|
32
|
+
return if mapping_prompt
|
33
|
+
|
34
|
+
locale_map.each_with_object({}) do |map, hash|
|
35
|
+
key = if map[1].size > 1
|
36
|
+
locale_prompt(map[0], map[1])
|
37
|
+
else
|
38
|
+
map[1].first
|
39
|
+
end
|
40
|
+
hash[key] = map[0]
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def locale_map
|
45
|
+
languages.each_with_object(Hash.new([])) do |l, hash|
|
46
|
+
hash[l.locale[0..1]] += [l.locale]
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def mapping_prompt
|
51
|
+
prompt.yes?('Would you like to include locales?')
|
52
|
+
end
|
53
|
+
|
54
|
+
def locale_prompt(language, locales)
|
55
|
+
prompt.select("Choose a locale for #{language}: ", locales)
|
56
|
+
end
|
57
|
+
|
58
|
+
def project_id_prompt(projects)
|
59
|
+
prompt.select('Choose a project: ', projects)
|
23
60
|
end
|
24
61
|
|
25
62
|
def locale_path_prompt
|
@@ -32,6 +69,14 @@ module PolyglotCli
|
|
32
69
|
hash[r.name] = r.id
|
33
70
|
end
|
34
71
|
end
|
72
|
+
|
73
|
+
def filtered_projects
|
74
|
+
projects.select { |key, _id| key[/^(.*?(#{option_query})[^$]*)$/i] }
|
75
|
+
end
|
76
|
+
|
77
|
+
def option_query
|
78
|
+
@option_query ||= @options.__hash__.fetch(:query, '')
|
79
|
+
end
|
35
80
|
end
|
36
81
|
end
|
37
82
|
end
|
@@ -23,10 +23,24 @@ module PolyglotCli
|
|
23
23
|
Time.parse(project.updated_at).utc > Time.parse(config[:project_updated_at]).utc
|
24
24
|
end
|
25
25
|
|
26
|
-
def languages(locale)
|
26
|
+
def languages(locale = nil)
|
27
27
|
prompt.say('Getting languages...')
|
28
|
-
|
29
|
-
|
28
|
+
select_languages(
|
29
|
+
locale,
|
30
|
+
PolyglotCli::Resource::Language.token(token).depaginate(project_id: project_id)
|
31
|
+
)
|
32
|
+
end
|
33
|
+
|
34
|
+
def select_languages(locale, results)
|
35
|
+
results.select! { |l| l.locale == locale } if locale.present?
|
36
|
+
|
37
|
+
if config[:locale_mapping].present?
|
38
|
+
results.select! do |l|
|
39
|
+
l.locale = config[:locale_mapping][l.locale]
|
40
|
+
l.locale.present?
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
30
44
|
results
|
31
45
|
end
|
32
46
|
|
@@ -6,7 +6,7 @@ module PolyglotCli
|
|
6
6
|
class << self
|
7
7
|
def write(locale_path, data)
|
8
8
|
prompt.say("Writing translations to #{path(locale_path, data.keys[0])}")
|
9
|
-
File.open(path(locale_path, data.keys[0]), 'w') { |f|
|
9
|
+
File.open(path(locale_path, data.keys[0]), 'w') { |f| f.write(data.to_yaml(line_width: -1)) }
|
10
10
|
end
|
11
11
|
|
12
12
|
def read(locale_path, locale)
|
data/lib/polyglot_cli/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: polyglot_cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ivan Grgurevic
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-01-
|
11
|
+
date: 2017-01-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|